forked from HubSpot/hapipy
-
Notifications
You must be signed in to change notification settings - Fork 2
Tests for contacts & contact lists, added some methods to the API tha… #1
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import unittest2 | ||
| import random | ||
|
|
||
| from nose.plugins.attrib import attr | ||
|
|
||
| import helper | ||
| from hapi.contact_lists import ContactListsClient | ||
| from hapi.contacts import ContactsClient | ||
| from test_contacts import ContactsClientTestCase | ||
|
|
||
|
|
||
| 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_a_contact_lists(self): | ||
| """ Test that the get contact lists endpoint is valid. """ | ||
| response = self.client.get_a_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']) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import unittest2 | ||
|
|
||
| from faker import Faker | ||
| from nose.plugins.attrib import attr | ||
|
|
||
| import helper | ||
| from hapi.contacts import ContactsClient | ||
|
|
||
| fake = Faker() | ||
|
|
||
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| nose==1.1.2 | ||
| unittest2==0.5.1 | ||
| simplejson==2.2.1 | ||
| fake-factory==0.5.2 | ||
|
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. do we need helper here?
Author
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. helper is a file specific to this repo hapi/test/helper.py |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What do we get from helper.get_options() ? I tried pip install helper, but no get_options() method found.
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.
check source :) it basically has a base set of demo credentials , allowing you to modify it for testing if you want to use different creds.
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.
I thought it was a third-party package named helper....and I did find it, so I installed it........