-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create custom contact properties and verify replication of those properties #244
Changes from 7 commits
acf4212
092bc3a
f925a65
53ad094
1880ea4
5b9656d
e37fd59
68c46ab
520643b
7f42c8e
6103dee
1cb5bdb
100a505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import requests | ||
from base import HubspotBaseTest | ||
from tap_tester import LOGGER | ||
from copy import deepcopy | ||
|
||
DEBUG = False | ||
BASE_URL = "https://api.hubapi.com" | ||
|
@@ -37,6 +38,7 @@ def giveup(exc): | |
jitter=None, | ||
giveup=giveup, | ||
interval=10) | ||
|
||
def get(self, url, params=dict()): | ||
"""Perform a GET using the standard requests method and logs the action""" | ||
response = requests.get(url, params=params, headers=self.HEADERS) | ||
|
@@ -833,6 +835,107 @@ def create(self, stream, company_ids=[], subscriptions=[], times=1): | |
else: | ||
raise NotImplementedError(f"There is no create_{stream} method in this dipatch!") | ||
|
||
def create_custom_contact_properties(self): | ||
"""Create custom contact properties of all the types""" | ||
|
||
url = f"{BASE_URL}/properties/v1/contacts/properties" | ||
data = [] | ||
property = { | ||
"name": "custom_string", | ||
"label": "A New String Custom Property", | ||
"description": "A new string property for you", | ||
"groupName": "contactinformation", | ||
"type": "string", | ||
"fieldType": "text", | ||
"formField": True, | ||
"displayOrder": 6, | ||
"options": [ | ||
] | ||
} | ||
data.append(deepcopy(property)) | ||
|
||
property = { | ||
"name": "custom_number", | ||
"label": "A New Number Custom Property", | ||
"description": "A new number property for you", | ||
"groupName": "contactinformation", | ||
"type": "number", | ||
"fieldType": "text", | ||
"formField": True, | ||
"displayOrder": 7, | ||
"options": [ | ||
] | ||
} | ||
data.append(deepcopy(property)) | ||
|
||
property = { | ||
"name": "custom_date", | ||
"label": "A New Date Custom Property", | ||
"description": "A new date property for you", | ||
"groupName": "contactinformation", | ||
"type": "date", | ||
"fieldType": "text", | ||
"formField": True, | ||
"displayOrder": 9, | ||
"options": [ | ||
] | ||
} | ||
data.append(deepcopy(property)) | ||
|
||
property = { | ||
"name": "custom_datetime", | ||
"label": "A New Datetime Custom Property", | ||
"description": "A new datetime property for you", | ||
"groupName": "contactinformation", | ||
"type": "datetime", | ||
"fieldType": "text", | ||
"formField": True, | ||
"displayOrder": 10, | ||
"options": [ | ||
] | ||
} | ||
data.append(deepcopy(property)) | ||
|
||
property = { | ||
"name": "multi_pick", | ||
"label": "multi pick", | ||
"description": "multi select picklist test", | ||
"groupName": "contactinformation", | ||
"type": "enumeration", | ||
"fieldType": "checkbox", | ||
"hidden": False, | ||
"options": [ | ||
{ | ||
"label": "Option A", | ||
"value": "option_a" | ||
}, | ||
{ | ||
"label": "Option B", | ||
"value": "option_b" | ||
}, | ||
{ | ||
"label": "Option C", | ||
"value": "option_c" | ||
} | ||
], | ||
"formField": True | ||
} | ||
data.append(deepcopy(property)) | ||
# generate a contacts record | ||
|
||
for current_data in data: | ||
try: | ||
response = self.post(url, current_data) | ||
LOGGER.info("response is %s", response) | ||
# Setting up the property is a one time task, If exception occurs because, it already exists, ignore | ||
except Exception as DataAlreadyExistsExcp: | ||
LOGGER.info("Data already exists for %s", current_data) | ||
if '409' in str(DataAlreadyExistsExcp): | ||
pass | ||
else: | ||
response.raise_for_status() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I"m communicating well enough. doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry Harrison - I think I got it right now :) Now handling it as requests.exceptions.HTTPError |
||
|
||
|
||
def create_contacts(self): | ||
""" | ||
Generate a single contacts record. | ||
|
@@ -843,6 +946,14 @@ def create_contacts(self): | |
url = f"{BASE_URL}/contacts/v1/contact" | ||
data = { | ||
"properties": [ | ||
{ | ||
"property": "custom_string", | ||
"value": "custom_string_value" | ||
}, | ||
{ | ||
"property": "custom_number", | ||
"value": 1567 | ||
}, | ||
Comment on lines
+958
to
+965
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are setting custom properties for every call of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, creating the custom contact property is a one time task. After my first successful run of the test, it never creates and gives a 409, that's why I am skipping it. Probably doing it in init is a good idea. Will try that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you moved it to setup. I meant the init of the client so anyone using the client makes sure it is in good shape, vs just for your test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, moved it to init |
||
{ | ||
"property": "email", | ||
"value": f"{record_uuid}@stitchdata.com" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is great that you are creating a variety of data types in the custom fields. Since you went through the pain of creating them we should also use them all when creating a contact - instead of just the first two - to make sure that we support all of the types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) was expecting this comment.. The other types seems complicated, I'll need more time to figure out how to do. Can I write a separate card for that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.