Skip to content

Commit

Permalink
Create custom contact properties and verify replication of those prop…
Browse files Browse the repository at this point in the history
…erties (#244)

* Create custom contact properties, added a few to the contact and verified the replication of the same

* Raise exception if not 409

* Adding one more bad key prefix

* Moved create_custom_contact_properties to setup

* Changed the exception name and added comments

* Changed the exception handling

* Resolved conflicts

* Resolved conflicts

* Resolved merge conflicts
  • Loading branch information
bhuvana-talend authored Jan 25, 2024
1 parent 14a2271 commit 685a827
Showing 1 changed file with 115 additions and 1 deletion.
116 changes: 115 additions & 1 deletion tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import requests
from base import HubspotBaseTest
from tap_tester import LOGGER
import time
import time
from copy import deepcopy

DEBUG = False
BASE_URL = "https://api.hubapi.com"
Expand Down Expand Up @@ -38,6 +39,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)
Expand Down Expand Up @@ -842,6 +844,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 requests.exceptions.HTTPError as err:
LOGGER.info("Data already exists for %s", current_data)
if '409' in str(err):
pass
else:
response.raise_for_status()


def create_contacts(self):
"""
Generate a single contacts record.
Expand All @@ -852,6 +955,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
},
{
"property": "email",
"value": f"{record_uuid}@stitchdata.com"
Expand Down Expand Up @@ -1865,6 +1976,9 @@ def __init__(self, start_date=''):
self.cleanup(stream, records, delete_count)
LOGGER.info(f"TEST CLIENT | {delete_count} records deleted from {stream}")

# Create custom properties for contacts
self.create_custom_contact_properties()

def print_histogram_data(self):
for stream, recorded_times in self.record_create_times.items():
LOGGER.info("Time taken for stream {} is total: {}, avg: {}, minimum: {}, maximum: {}".
Expand Down

0 comments on commit 685a827

Please sign in to comment.