def test_multiple_pages_with_cutoff_on_subsequent_page(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT + 2) page_2_contact_2 = contacts[BATCH_RETRIEVAL_SIZE_LIMIT + 1] self._check_retrieved_contacts_are_newer_than_contact( page_2_contact_2, contacts, )
def test_contacts_as_a_generator(self): contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT) connection = self._make_connection_for_contacts(contacts) contacts_generator = iter(contacts) with connection: save_contacts(contacts_generator, connection)
def test_multiple_pages_with_cutoff_on_first_page(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT + 1) page_1_last_contact = contacts[BATCH_RETRIEVAL_SIZE_LIMIT - 1] self._check_retrieved_contacts_are_newer_than_contact( page_1_last_contact, contacts, )
def test_cutoff_newer_than_most_recently_updated_contact(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT - 1) page_1_contact_1 = contacts[0] self._check_retrieved_contacts_are_newer_than_contact( page_1_contact_1, contacts, )
def test_all_contacts_in_list_exceeding_batch_size_limit(self): contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) self._test_membership_update( expected_updated_contacts=contacts, contacts_to_update=contacts, contacts_in_list=contacts, )
def test_cutoff_newer_than_most_recently_updated_contact(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT - 1) page_1_contact_1 = contacts[0] self._check_retrieved_contacts_are_newer_than_contact( page_1_contact_1, contacts, )
def test_all_contacts_in_list_exceeding_batch_size_limit(self): contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) self._test_membership_update( expected_updated_contacts=contacts, contacts_to_update=contacts, contacts_in_list=contacts, )
def test_multiple_pages_with_cutoff_on_subsequent_page(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT + 2) page_2_contact_2 = contacts[BATCH_RETRIEVAL_SIZE_LIMIT + 1] self._check_retrieved_contacts_are_newer_than_contact( page_2_contact_2, contacts, )
def test_some_contacts(self): saved_contacts = make_contacts(1) with self._make_connection_for_contacts(saved_contacts) as connection: with assert_raises(HubspotServerError) as context_manager: save_contacts(saved_contacts, connection) eq_(self._STUB_EXCEPTION, context_manager.exception)
def test_contacts_not_in_list_without_exceeding_batch_size_limit(self): contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT) self._test_membership_update( expected_updated_contacts=[], contacts_to_update=contacts, contacts_in_list=[], )
def test_single_page_with_cutoff(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT - 1) page_1_contact_2 = contacts[1] self._check_retrieved_contacts_are_newer_than_contact( page_1_contact_2, contacts, )
def test_contacts_not_in_list_without_exceeding_batch_size_limit(self): contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT) self._test_membership_update( expected_updated_contacts=[], contacts_to_update=contacts, contacts_in_list=[], )
def test_single_page_with_cutoff(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT - 1) page_1_contact_2 = contacts[1] self._check_retrieved_contacts_are_newer_than_contact( page_1_contact_2, contacts, )
def test_multiple_pages_with_cutoff_on_first_page(self): contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT + 1) page_1_last_contact = contacts[BATCH_RETRIEVAL_SIZE_LIMIT - 1] self._check_retrieved_contacts_are_newer_than_contact( page_1_last_contact, contacts, )
def test_getting_non_existing_properties(self): """Requesting non-existing properties fails silently in HubSpot""" contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT) self._check_contacts_from_simulated_retrieval_equal( contacts, contacts, property_names=['undefined'], )
def test_unexpected_response(self): connection = MockPortalConnection(self._make_unsupported_api_call()) with connection, assert_raises(Invalid): self._MEMBERSHIP_UPDATER( _STUB_CONTACT_LIST, make_contacts(1), connection, )
def test_unexpected_response(self): connection = MockPortalConnection(self._make_unsupported_api_call()) with connection, assert_raises(Invalid): self._MEMBERSHIP_UPDATER( _STUB_CONTACT_LIST, make_contacts(1), connection, )
def test_getting_non_existing_properties(self): """Requesting non-existing properties fails silently in HubSpot""" contacts = make_contacts(BATCH_RETRIEVAL_SIZE_LIMIT) self._check_contacts_from_simulated_retrieval_equal( contacts, contacts, property_names=['undefined'], )
def test_duplicated_contacts(self): contact1, contact2 = make_contacts(2) expected_contacts = [contact1, contact2] simulator_contacts = [contact1, contact2, contact1] self._check_contacts_from_simulated_retrieval_equal( simulator_contacts, expected_contacts, )
def test_duplicated_contacts(self): contact1, contact2 = make_contacts(2) expected_contacts = [contact1, contact2] simulator_contacts = [contact1, contact2, contact1] self._check_contacts_from_simulated_retrieval_equal( simulator_contacts, expected_contacts, )
def test_updated_contacts_in_first_batch_of_list(self): contacts_to_update = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) contacts_in_first_batch = contacts_to_update[BATCH_SAVING_SIZE_LIMIT:] self._test_membership_update( expected_updated_contacts=contacts_in_first_batch, contacts_to_update=contacts_to_update, contacts_in_list=contacts_in_first_batch, )
def test_updated_contacts_in_first_batch_of_list(self): contacts_to_update = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) contacts_in_first_batch = contacts_to_update[BATCH_SAVING_SIZE_LIMIT:] self._test_membership_update( expected_updated_contacts=contacts_in_first_batch, contacts_to_update=contacts_to_update, contacts_in_list=contacts_in_first_batch, )
def test_updated_contacts_in_subsequent_batch_of_list(self): contacts_to_update = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) contacts_in_first_batch, other_contacts = \ _split_list(contacts_to_update, BATCH_SAVING_SIZE_LIMIT) self._test_membership_update( expected_updated_contacts=contacts_in_first_batch, contacts_to_update=contacts_to_update, contacts_in_list=other_contacts, )
def test_updated_contacts_in_subsequent_batch_of_list(self): contacts_to_update = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) contacts_in_first_batch, other_contacts = \ _split_list(contacts_to_update, BATCH_SAVING_SIZE_LIMIT) self._test_membership_update( expected_updated_contacts=contacts_in_first_batch, contacts_to_update=contacts_to_update, contacts_in_list=other_contacts, )
def test_contacts_as_a_generator(self): contacts = make_contacts(1) with self._make_connection(contacts, contacts) as connection: updated_contact_vids = self._MEMBERSHIP_UPDATER( _STUB_CONTACT_LIST, iter(contacts), connection, ) expected_updated_contact_vids = _get_contact_vids(contacts) assert_equal(expected_updated_contact_vids, updated_contact_vids)
def test_contacts_as_a_generator(self): contacts = make_contacts(1) with self._make_connection(contacts, contacts) as connection: updated_contact_vids = self._MEMBERSHIP_UPDATER( _STUB_CONTACT_LIST, iter(contacts), connection, ) expected_updated_contact_vids = _get_contact_vids(contacts) assert_items_equal(expected_updated_contact_vids, updated_contact_vids)
def _make_unsupported_api_call(cls): api_calls_simulator = cls._SIMULATOR_CLASS( _STUB_CONTACT_LIST, make_contacts(1), [], ) api_calls = api_calls_simulator() for api_call in api_calls: # Corrupt the response del api_call.response_body_deserialization['updated'] return lambda: api_calls
def _make_unsupported_api_call(cls): api_calls_simulator = cls._SIMULATOR_CLASS( _STUB_CONTACT_LIST, make_contacts(1), [], ) api_calls = api_calls_simulator() for api_call in api_calls: # Corrupt the response del api_call.response_body_deserialization['updated'] return lambda: api_calls
def test_some_successfully_retrieved_contacts(self): contacts = make_contacts(1) connection = self._make_connection(contacts) with connection: retrieved_contacts = self._RETRIEVER(connection) successufully_retrieved_contacts = \ islice(retrieved_contacts, len(contacts)) _assert_retrieved_contacts_equal( contacts, list(successufully_retrieved_contacts), ) with assert_raises(HubspotServerError): next(retrieved_contacts)
def _test_invalid_property_value( self, property_, property_value, exc_message_template, ): saved_contacts = make_contacts(1) connection = \ self._make_connection_for_contacts(saved_contacts, property_) contact_with_invalid_property_value = \ make_contact(1, {property_.name: property_value}) exc_message = exc_message_template.format(repr(property_value)) with assert_raises_regexp(HubspotPropertyValueError, exc_message): with connection: save_contacts([contact_with_invalid_property_value], connection)
def test_some_successfully_retrieved_contacts(self): contacts = make_contacts(1) connection = self._make_connection(contacts) with connection: retrieved_contacts = self._RETRIEVER(connection) successufully_retrieved_contacts = \ islice(retrieved_contacts, len(contacts)) _assert_retrieved_contacts_equal( contacts, list(successufully_retrieved_contacts), ) with assert_raises(HubspotServerError): next(retrieved_contacts)
def test_exceeding_pagination_size(self): contacts_count = BATCH_RETRIEVAL_SIZE_LIMIT + 1 contacts = make_contacts(contacts_count) self._check_contacts_from_simulated_retrieval_equal(contacts, contacts)
def test_exceeding_batch_size_limit(self): contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT + 1) self._check_saved_contacts_match(contacts)
def test_no_contacts(self): contacts_in_list = make_contacts(5) self._test_membership_update([], [], contacts_in_list)
def test_non_existing_contact(self): self._test_membership_update( expected_updated_contacts=[], contacts_to_update=make_contacts(1), contacts_in_hubspot=[], )
def test_exceeding_pagination_size(self): contacts_count = BATCH_RETRIEVAL_SIZE_LIMIT + 1 contacts = make_contacts(contacts_count) self._check_contacts_from_simulated_retrieval_equal(contacts, contacts)
def test_no_contacts(self): contacts_in_list = make_contacts(5) self._test_membership_update([], [], contacts_in_list)
def test_non_existing_contact(self): self._test_membership_update( expected_updated_contacts=[], contacts_to_update=make_contacts(1), contacts_in_hubspot=[], )