Esempio n. 1
0
 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)
Esempio n. 3
0
 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,
         )
Esempio n. 4
0
 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,
         )
Esempio n. 5
0
 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,
         )
Esempio n. 6
0
 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,
     )
Esempio n. 7
0
 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,
     )
Esempio n. 8
0
 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)
Esempio n. 10
0
 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=[],
     )
Esempio n. 11
0
 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,
         )
Esempio n. 12
0
 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=[],
         )
Esempio n. 13
0
 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,
     )
Esempio n. 14
0
 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,
     )
Esempio n. 15
0
 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'],
     )
Esempio n. 16
0
 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,
         )
Esempio n. 17
0
 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,
             )
Esempio n. 18
0
 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'],
         )
Esempio n. 19
0
    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,
            )
Esempio n. 20
0
    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,
        )
Esempio n. 21
0
    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,
        )
Esempio n. 22
0
    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,
            )
Esempio n. 23
0
    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,
            )
Esempio n. 24
0
    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,
        )
Esempio n. 25
0
    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)
Esempio n. 26
0
    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)
Esempio n. 27
0
    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
Esempio n. 28
0
    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
Esempio n. 29
0
    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)
Esempio n. 31
0
    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)
Esempio n. 32
0
 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)
Esempio n. 34
0
 def test_no_contacts(self):
     contacts_in_list = make_contacts(5)
     self._test_membership_update([], [], contacts_in_list)
Esempio n. 35
0
 def test_non_existing_contact(self):
     self._test_membership_update(
         expected_updated_contacts=[],
         contacts_to_update=make_contacts(1),
         contacts_in_hubspot=[],
     )
Esempio n. 36
0
 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)
Esempio n. 37
0
 def test_no_contacts(self):
     contacts_in_list = make_contacts(5)
     self._test_membership_update([], [], contacts_in_list)
Esempio n. 38
0
 def test_non_existing_contact(self):
     self._test_membership_update(
         expected_updated_contacts=[],
         contacts_to_update=make_contacts(1),
         contacts_in_hubspot=[],
         )