Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions hapi/contact_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def get_contact_lists(self, **options):
""" Returns all of the contact lists """
return self._call('lists', method='GET', **options)

def get_contacts_by_list_id(self, list_id, query='', **options):
""" Get all contacts in the specified list """
return self._call(
'lists/{list_id}/contacts/all'.format(list_id=list_id),
method='GET',
query=query,
**options
)

def add_contact_to_a_list(self, list_id, vids, data=None, **options):
""" Adds a list of contact vids to the specified list. """
data = data or {}
Expand Down
82 changes: 50 additions & 32 deletions hapi/test/test_contact_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from test_contacts import ContactsClientTestCase


class ConstactListsClientTestCase(unittest2.TestCase):
class ContactsListsClientTestCase(unittest2.TestCase):

""" Unit tests for the HubSpot Contact Lists API Python client.

Expand All @@ -21,52 +21,70 @@ class ConstactListsClientTestCase(unittest2.TestCase):
test_portal_id = 62515

def setUp(self):
self.client = ContactListsClient(**helper.get_options())
self.contacts_client = ContactsClient(**helper.get_options())
self.lists = []
self.contacts =[]
self.client = ContactListsClient(**helper.get_options())
self.contacts_client = ContactsClient(**helper.get_options())
self.lists = []
self.contacts =[]

def tearDown(self):
""" Clean up all the created objects. """
if self.contacts:
[self.contacts_client.delete_a_contact(contact) for contact in self.contacts]
if self.lists:
[self.client.delete_a_contact_list(list) for list in self.lists]
""" Clean up all the created objects. """
if self.contacts:
[self.contacts_client.delete_a_contact(contact) for contact in self.contacts]
if self.lists:
[self.client.delete_a_contact_list(list) for list in self.lists]

@attr('api')
def test_get_contact_lists(self):
""" Test that the get contact lists endpoint is valid. """
response = self.client.get_contact_lists()
self.assertTrue(len(response) > 0)

def test_get_contacts_by_list_id(self):
""" Test that get contacts in a list is returning the right contacts """
email = ContactsClientTestCase.test_contact_json['properties'][0]['value']
contact = self.contacts_client.create_or_update_a_contact(
email,
data=ContactsClientTestCase.test_contact_json
)['vid']
self.contacts.append(contact)
contact_list = self.client.create_a_contact_list(
list_name='test_add_contact_to_a_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)
self.lists.append(contact_list['listId'])
self.client.add_contact_to_a_list(contact_list['listId'], [contact])
response = self.client.get_contacts_by_list_id(contact_list['listId'])
self.assertEqual(len(response['contacts']), 1)
self.assertEqual(response['contacts'][0]['vid'], contact)

@attr('api')
def test_add_contact_to_a_list(self):
""" Test that the add contact to a list endpoint is valid. """
email = ContactsClientTestCase.test_contact_json['properties'][0]['value']
contact = self.contacts_client.create_or_update_a_contact(email, data=ContactsClientTestCase.test_contact_json)['vid']
self.contacts.append(contact)
contact_list = self.client.create_a_contact_list(list_name='test_add_contact_to_a_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)
self.lists.append(contact_list['listId'])

response = self.client.add_contact_to_a_list(contact_list['listId'], [contact])
self.assertTrue(len(response) > 0)
""" Test that the add contact to a list endpoint is valid. """
email = ContactsClientTestCase.test_contact_json['properties'][0]['value']
contact = self.contacts_client.create_or_update_a_contact(email, data=ContactsClientTestCase.test_contact_json)['vid']
self.contacts.append(contact)
contact_list = self.client.create_a_contact_list(list_name='test_add_contact_to_a_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)
self.lists.append(contact_list['listId'])

response = self.client.add_contact_to_a_list(contact_list['listId'], [contact])
self.assertTrue(len(response) > 0)

def test_create_a_contact_list(self):
""" Test that the create contact list endpoint is valid. """
response = self.client.create_a_contact_list(list_name='test_create_a_contact_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)
self.assertTrue(len(response) > 0)
""" Test that the create contact list endpoint is valid. """
response = self.client.create_a_contact_list(list_name='test_create_a_contact_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)
self.assertTrue(len(response) > 0)

self.lists.append(response['listId'])
self.lists.append(response['listId'])

def test_delete_a_contact_list(self):
""" Test that the delete contact list endpoint is valid. """
contact_list = self.client.create_a_contact_list(list_name='test_delete_a_contact_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)
""" Test that the delete contact list endpoint is valid. """
contact_list = self.client.create_a_contact_list(list_name='test_delete_a_contact_list' + str(random.randint(1000, 50000)),
portal_id=self.test_portal_id,
dynamic=False)

response = self.client.delete_a_contact_list(contact_list['listId'])
response = self.client.delete_a_contact_list(contact_list['listId'])

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='hapipy',
version='2.10.5.3',
version='2.10.5.4',
description="A python wrapper around HubSpot's APIs",
long_description=open('README.md').read(),
author='HubSpot Dev Team',
Expand Down