class ConstactListsClientTestCase(unittest2.TestCase): """ Unit tests for the HubSpot Contact Lists API Python client. This file contains some unittest tests for the Contact Lists API. Questions, comments: http://developers.hubspot.com/docs/methods/lists/create_list """ test_portal_id = 62515 def setUp(self): 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] @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) @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) 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) 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) response = self.client.delete_a_contact_list(contact_list['listId'])
from hapi.contacts import ContactsClient api_key = 'Your API Key' contact_client = ContactsClient(api_key=api_key) data = {} data['properties'] = [] data['properties'].append({ 'property': 'email', 'value': '*****@*****.**' }) data['properties'].append({'property': 'firstname', 'value': 'testing user'}) data['properties'].append({'property': 'phone', 'value': '09876543210'}) contact_client.create_a_contact(data=data)
def setUp(self): self.client = ContactsClient(**helper.get_options()) self.contacts = []
class ContactsClientTestCase(unittest2.TestCase): """ Unit tests for the HubSpot Contacts API Python client. This file contains some unittest tests for the Contacts API. Questions, comments: http://developers.hubspot.com/docs/methods/contacts/contacts-overview """ test_contact_json = { "properties": [ { "property": "email", "value": fake.email() }, { "property": "firstname", "value": fake.first_name() }, { "property": "lastname", "value": fake.last_name() }, { "property": "website", "value": fake.url() }, { "property": "company", "value": fake.company() }, { "property": "phone", "value": fake.phone_number() }, { "property": "address", "value": fake.street_address() }, { "property": "city", "value": fake.city() }, { "property": "state", "value": fake.state() }, { "property": "zip", "value": fake.zipcode() } ] } def setUp(self): self.client = ContactsClient(**helper.get_options()) self.contacts = [] def tearDown(self): """ Cleans up the created objects. """ if self.contacts: [self.client.delete_a_contact(contact) for contact in self.contacts] @attr('api') def test_create_or_update_a_contact(self): """ Test the create or update a contact endpoint is valid. """ email = self.test_contact_json['properties'][0]['value'] response = self.client.create_or_update_a_contact(email, data=self.test_contact_json) self.assertTrue(len(response) > 0) self.contacts.append(response['vid']) @attr('api') def test_get_contact_by_email(self): """ Test that the get contact by email address endoint is valid. """ email = self.test_contact_json['properties'][0]['value'] contact = self.client.create_or_update_a_contact(email, data=self.test_contact_json)['vid'] response = self.client.get_contact_by_email(email) self.assertTrue(len(response) > 0) self.contacts.append(contact) @attr('api') def test_update_a_contact(self): """ Test that the update contact endpoint is valid and that changes persist. """ email = self.test_contact_json['properties'][0]['value'] contact = self.client.create_or_update_a_contact(email, data=self.test_contact_json)['vid'] new_contact_json = self.test_contact_json.copy() new_contact_json['properties'][4]['value'] = new_contact_json['properties'][4]['value'] + ' UPDATED' response = self.client.update_a_contact(contact, data=self.test_contact_json) contact_response = self.client.get_contact_by_email(email) self.assertEqual(contact_response['properties']['company']['value'], new_contact_json['properties'][4]['value']) self.contacts.append(contact) @attr('api') def test_delete_a_contact(self): """ Test that the delete contact endpoint is valid. """ email = self.test_contact_json['properties'][0]['value'] contact = self.client.create_or_update_a_contact(email, data=self.test_contact_json)['vid'] response = self.client.delete_a_contact(contact) self.assertTrue(len(response) > 0)
class ContactsClientTestCase(unittest2.TestCase): """ Unit tests for the HubSpot Contacts API Python client. This file contains some unittest tests for the Contacts API. Questions, comments: http://developers.hubspot.com/docs/methods/contacts/contacts-overview """ test_contact_json = { "properties": [{ "property": "email", "value": fake.email() }, { "property": "firstname", "value": fake.first_name() }, { "property": "lastname", "value": fake.last_name() }, { "property": "website", "value": fake.url() }, { "property": "company", "value": fake.company() }, { "property": "phone", "value": fake.phone_number() }, { "property": "address", "value": fake.street_address() }, { "property": "city", "value": fake.city() }, { "property": "state", "value": fake.state() }, { "property": "zip", "value": fake.zipcode() }] } def setUp(self): self.client = ContactsClient(**helper.get_options()) self.contacts = [] def tearDown(self): """ Cleans up the created objects. """ if self.contacts: [ self.client.delete_a_contact(contact) for contact in self.contacts ] @attr('api') def test_create_or_update_a_contact(self): """ Test the create or update a contact endpoint is valid. """ email = self.test_contact_json['properties'][0]['value'] response = self.client.create_or_update_a_contact( email, data=self.test_contact_json) self.assertTrue(len(response) > 0) self.contacts.append(response['vid']) @attr('api') def test_get_contact_by_email(self): """ Test that the get contact by email address endoint is valid. """ email = self.test_contact_json['properties'][0]['value'] contact = self.client.create_or_update_a_contact( email, data=self.test_contact_json)['vid'] response = self.client.get_contact_by_email(email) self.assertTrue(len(response) > 0) self.contacts.append(contact) @attr('api') def test_update_a_contact(self): """ Test that the update contact endpoint is valid and that changes persist. """ email = self.test_contact_json['properties'][0]['value'] contact = self.client.create_or_update_a_contact( email, data=self.test_contact_json)['vid'] new_contact_json = self.test_contact_json.copy() new_contact_json['properties'][4][ 'value'] = new_contact_json['properties'][4]['value'] + ' UPDATED' response = self.client.update_a_contact(contact, data=self.test_contact_json) contact_response = self.client.get_contact_by_email(email) self.assertEqual(contact_response['properties']['company']['value'], new_contact_json['properties'][4]['value']) self.contacts.append(contact) @attr('api') def test_delete_a_contact(self): """ Test that the delete contact endpoint is valid. """ email = self.test_contact_json['properties'][0]['value'] contact = self.client.create_or_update_a_contact( email, data=self.test_contact_json)['vid'] response = self.client.delete_a_contact(contact) self.assertTrue(len(response) > 0)
class ConstactListsClientTestCase(unittest2.TestCase): """ Unit tests for the HubSpot Contact Lists API Python client. This file contains some unittest tests for the Contact Lists API. Questions, comments: http://developers.hubspot.com/docs/methods/lists/create_list """ test_portal_id = 62515 def setUp(self): 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] @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) @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) 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) 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) response = self.client.delete_a_contact_list(contact_list['listId'])