Skip to content

Commit

Permalink
Merge branch 'master' into TDL-24718/python-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
leslievandemark authored Jan 24, 2024
2 parents f900460 + da38d56 commit 2c83363
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 2.14.0
* Updates to run on python 3.11.7 [#249](https://github.com/singer-io/tap-hubspot/pull/249mag)

## 2.13.2
* Fix out-of-index error [#253](https://github.com/singer-io/tap-hubspot/pull/253)

## 2.13.1
* Optimise contacts_by_company implementation [#250](https://github.com/singer-io/tap-hubspot/pull/250)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
install_requires=[
'attrs==16.3.0',
'singer-python==6.0.0',
'requests==2.20.0',
'requests==2.31.0',
'backoff==2.2.1',
'requests_mock==1.3.0',
],
Expand Down
5 changes: 5 additions & 0 deletions tap_hubspot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,15 @@ def use_recent_companies_endpoint(response):

# NB> to do: support stream aliasing and field selection
def _sync_contacts_by_company_batch_read(STATE, ctx, company_ids):
# Return state as it is if company ids list is empty
if len(company_ids) == 0:
return STATE

schema = load_schema(CONTACTS_BY_COMPANY)
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
url = get_url("contacts_by_company_v3")

with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
with metrics.record_counter(CONTACTS_BY_COMPANY) as counter:
body = {'inputs': [{'id': company_id} for company_id in company_ids]}
Expand Down
43 changes: 39 additions & 4 deletions tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import requests
from base import HubspotBaseTest
from tap_tester import LOGGER
import time

DEBUG = False
BASE_URL = "https://api.hubapi.com"
Expand Down Expand Up @@ -802,6 +803,13 @@ def create(self, stream, company_ids=[], subscriptions=[], times=1):
return self.create_companies()
elif stream == 'contact_lists':
return self.create_contact_lists()
elif stream == 'static_contact_lists':
staticlist = self.create_contact_lists(dynamic=False)
listId = staticlist[0].get('listId')
records = self.create('contacts')
contact_email = records[0].get('properties').get('email').get('value')
self.add_contact_to_contact_list(listId, contact_email)
return staticlist
elif stream == 'contacts_by_company':
return self.create_contacts_by_company(company_ids, times=times)
elif stream == 'engagements':
Expand All @@ -813,8 +821,9 @@ def create(self, stream, company_ids=[], subscriptions=[], times=1):
elif stream == 'workflows':
return self.create_workflows()
elif stream == 'contacts':
LOGGER.info("self.record_create_times is %s", self.record_create_times)
if stream not in self.record_create_times.keys():
self.record_create_times[stream]=[]
self.record_create_times['contacts']=[]
records = self.create_contacts()
return records
elif stream == 'deal_pipelines':
Expand Down Expand Up @@ -939,7 +948,7 @@ def create_companies(self):
records = [response]
return records

def create_contact_lists(self):
def create_contact_lists(self, dynamic=True):
"""
HubSpot API https://legacydocs.hubspot.com/docs/methods/lists/create_list
Expand All @@ -948,15 +957,16 @@ def create_contact_lists(self):
using different filters would result in any new fields.
"""
record_uuid = str(uuid.uuid4()).replace('-', '')
value = f"@hubspot{record_uuid}"

url = f"{BASE_URL}/contacts/v1/lists/"
data = {
"name": f"tweeters{record_uuid}",
"dynamic": True,
"dynamic": dynamic,
"filters": [
[{
"operator": "EQ",
"value": f"@hubspot{record_uuid}",
"value": value,
"property": "twitterhandle",
"type": "string"
}]
Expand All @@ -965,6 +975,31 @@ def create_contact_lists(self):
# generate a record
response = self.post(url, data)
records = [response]
LOGGER.info("dynamic contact list is %s", records)
return records

def add_contact_to_contact_list(self, list_id, contact_email):
"""
HubSpot API https://legacydocs.hubspot.com/docs/methods/lists/create_list
NB: This generates a list based on a 'twitterhandle' filter. There are many
different filters, but at the time of implementation it did not seem that
using different filters would result in any new fields.
"""
record_uuid = str(uuid.uuid4()).replace('-', '')
value = f"@hubspot{record_uuid}"

url = f"{BASE_URL}/contacts/v1/lists/{list_id}/add"
data = {
"emails": [
contact_email
]
}
# generate a record
LOGGER.info("Post URL is %s", url)
response = self.post(url, data)
records = [response]
LOGGER.info("updated contact_list is %s", records)
return records

def create_contacts_by_company(self, company_ids=[], contact_records=[], times=1):
Expand Down
1 change: 1 addition & 0 deletions tests/test_hubspot_all_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def get_matching_actual_record_by_pk(expected_primary_key_dict, actual_records):
'property_hs_num_associated_deal_splits',
'property_hs_is_active_shared_deal', #https://jira.talendforge.org/browse/TDL-24758
'property_hs_is_deal_split',
'property_hs_is_active_shared_deal',
'stateChanges',
'property_hs_num_associated_active_deal_registrations',
'property_hs_num_associated_deal_registrations',
Expand Down
14 changes: 10 additions & 4 deletions tests/test_hubspot_bookmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from time import sleep
import time


import tap_tester.connections as connections
Expand Down Expand Up @@ -34,7 +34,7 @@ def streams_to_test(self):

return expected_streams.difference({
'subscription_changes', # BUG_TDL-14938 https://jira.talendforge.org/browse/TDL-14938
})
})

def get_properties(self):
return {
Expand All @@ -57,17 +57,23 @@ def create_test_data(self, expected_streams):
for stream in expected_streams - {'contacts_by_company'}:
if stream == 'contacts':
self.times=10
elif stream == 'contact_lists':
self.times=2
else:
self.times =3

if stream in 'email_events':
if stream == 'email_events':
email_records = self.test_client.create(stream, self.times)
self.expected_records['email_events'] += email_records
else:
# create records, one will be updated between syncs
# create one static list and the rest dynamic list
for _ in range(self.times):
record = self.test_client.create(stream)
self.expected_records[stream] += record
if stream == 'contact_lists':
static_list = self.test_client.create('static_contact_lists')
self.expected_records[stream] += static_list

if 'contacts_by_company' in expected_streams: # do last
company_ids = [record['companyId'] for record in self.expected_records['companies']]
Expand Down Expand Up @@ -108,6 +114,7 @@ def test_run(self):
for stream in expected_streams - {'contacts_by_company'}:
record = self.test_client.create(stream)
self.expected_records[stream] += record

if 'contacts_by_company' in expected_streams:
company_ids = [record['companyId'] for record in self.expected_records['companies'][:-1]]
contact_records = self.expected_records['contacts'][-1:]
Expand All @@ -116,7 +123,6 @@ def test_run(self):
)
self.expected_records['contacts_by_company'] += record


# Update 1 record from the test seutp for each stream that has an update endpoint
for stream in expected_streams - STREAMS_WITHOUT_UPDATES:
primary_key = list(self.expected_primary_keys()[stream])[0]
Expand Down

0 comments on commit 2c83363

Please sign in to comment.