def test_too_many_requests(self):
     connection = MockPortalConnection()
     error_message = \
         'Not enough API calls for new requests (requested {!r})'.format(
             _STUB_URL_PATH,
             )
     with assert_raises_substring(AssertionError, error_message):
         connection.send_get_request(_STUB_URL_PATH)
Ejemplo n.º 2
0
 def test_too_many_requests(self):
     connection = MockPortalConnection()
     error_message = \
         'Not enough API calls for new requests (requested {!r})'.format(
             _STUB_URL_PATH,
             )
     with assert_raises_substring(AssertionError, error_message):
         connection.send_get_request(_STUB_URL_PATH)
    def test_multiple_api_calls(self):
        connection = MockPortalConnection(
            _ConstantCallable([_STUB_API_CALL_1, _STUB_API_CALL_2]),
            )

        assert_false(connection.api_calls)

        connection.send_get_request(_STUB_URL_PATH)
        eq_([_STUB_API_CALL_1], connection.api_calls)

        connection.send_post_request(_STUB_URL_PATH, None)
        eq_([_STUB_API_CALL_1, _STUB_API_CALL_2], connection.api_calls)
Ejemplo n.º 4
0
 def test_unsuccessful_creation(self):
     error_message = 'Whoops!'
     exception = HubspotClientError(error_message, get_uuid4_str())
     simulator = UnsuccessfulCreateProperty(STUB_NUMBER_PROPERTY, exception)
     with assert_raises_regexp(HubspotClientError, error_message):
         with MockPortalConnection(simulator) as connection:
             create_property(STUB_NUMBER_PROPERTY, connection)
Ejemplo n.º 5
0
    def test_unexpected_response(self):
        connection = MockPortalConnection(
            _simulate_create_static_contact_list_with_unsupported_response, )

        with assert_raises(Invalid):
            with connection:
                create_static_contact_list(_STUB_CONTACT_LIST.name, connection)
Ejemplo n.º 6
0
 def test_unsuccessful_creation(self):
     property_group = PropertyGroup(self._PROPERTY_GROUP_NAME)
     exception = HubspotClientError('Whoops!', get_uuid4_str())
     simulator = UnsuccessfulCreatePropertyGroup(property_group, exception)
     with assert_raises_regexp(HubspotClientError, str(exception)):
         with MockPortalConnection(simulator) as connection:
             create_property_group(property_group, connection)
Ejemplo n.º 7
0
    def test_unexpected_response(self):
        connection = MockPortalConnection(
            _simulate_get_all_contact_lists_with_unsupported_response, )

        with assert_raises(Invalid):
            with connection:
                list(get_all_contact_lists(connection))
Ejemplo n.º 8
0
 def _make_connection_for_contact_with_exception(contact,
                                                 exception,
                                                 available_property=None):
     available_property = available_property or STUB_STRING_PROPERTY
     simulator = UnsuccessfulCreateContact(contact, exception,
                                           [available_property])
     connection = MockPortalConnection(simulator)
     return connection
Ejemplo n.º 9
0
 def _make_connection_for_contacts(cls, contacts):
     simulator = UnsuccessfulSaveContacts(
         contacts,
         cls._STUB_EXCEPTION,
         [STUB_STRING_PROPERTY],
         )
     connection = MockPortalConnection(simulator)
     return connection
Ejemplo n.º 10
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,
         )
Ejemplo n.º 11
0
 def _make_connection(self, contacts_to_update, updated_contacts):
     simulator = self._SIMULATOR_CLASS(
         _STUB_CONTACT_LIST,
         contacts_to_update,
         updated_contacts,
     )
     connection = MockPortalConnection(simulator)
     return connection
Ejemplo n.º 12
0
    def test_name_doesnt_exist(self):
        simulator = CreateStaticContactList(_STUB_CONTACT_LIST.name)
        with MockPortalConnection(simulator) as connection:
            contact_list = create_static_contact_list(
                _STUB_CONTACT_LIST.name,
                connection,
            )

        eq_(_STUB_CONTACT_LIST, contact_list)
Ejemplo n.º 13
0
    def test_name_already_exists(self):
        exception = HubspotClientError('Whoops!', 1)
        simulator = UnsuccessfulCreateStaticContactList(
            _STUB_CONTACT_LIST.name,
            exception,
        )

        with assert_raises_regexp(HubspotClientError, str(exception)):
            with MockPortalConnection(simulator) as connection:
                create_static_contact_list(_STUB_CONTACT_LIST.name, connection)
Ejemplo n.º 14
0
    def test_valid_contact_list_id(self):
        """
        It must be possible to cast the ID of the contact list to an integer,
        since these are the only valid types of ID.

        """
        valid_contact_list_id = '123'
        simulator = DeleteContactList(valid_contact_list_id)
        with MockPortalConnection(simulator) as connection:
            delete_contact_list(valid_contact_list_id, connection)
Ejemplo n.º 15
0
    def test_invalid_contact_list_id(self):
        """
        When the contact list ID cannot be cast to an integer, the error
        is allowed to propagate.

        """
        with MockPortalConnection() as connection:
            with assert_raises(ValueError):
                invalid_contact_list_id = 'not an integer'
                delete_contact_list(invalid_contact_list_id, connection)
Ejemplo n.º 16
0
 def _make_connection_for_contacts(cls,
                                   contacts,
                                   available_property=None,
                                   **simulator_kwargs):
     available_property = available_property or STUB_STRING_PROPERTY
     simulator = cls._SIMULATOR_CLASS(
         contacts=contacts,
         available_properties=[available_property],
         **simulator_kwargs)
     connection = MockPortalConnection(simulator)
     return connection
Ejemplo n.º 17
0
    def test_multiple_api_calls(self):
        connection = MockPortalConnection(
            _ConstantCallable([_STUB_API_CALL_1, _STUB_API_CALL_2]), )

        assert_false(connection.api_calls)

        connection.send_get_request(_STUB_URL_PATH)
        eq_([_STUB_API_CALL_1], connection.api_calls)

        connection.send_post_request(_STUB_URL_PATH, None)
        eq_([_STUB_API_CALL_1, _STUB_API_CALL_2], connection.api_calls)
Ejemplo n.º 18
0
 def _make_connection(cls, contacts):
     simulator = cls._make_simulator(contacts)
     connection = MockPortalConnection(simulator)
     return connection
Ejemplo n.º 19
0
    def _test_retrieved_property_group_equal(self, property_groups):
        simulator = GetAllPropertyGroups(property_groups)
        with MockPortalConnection(simulator) as connection:
            retrieved_property_groups = get_all_property_groups(connection)

        eq_(property_groups, retrieved_property_groups)
Ejemplo n.º 20
0
 def _make_connection_for_expected_api_call(expected_api_call):
     expected_api_calls_simulator = _ConstantCallable([expected_api_call])
     connection = MockPortalConnection(expected_api_calls_simulator)
     return connection
Ejemplo n.º 21
0
 def _create_property_group(property_group):
     simulator = CreatePropertyGroup(property_group)
     with MockPortalConnection(simulator) as connection:
         created_property_group = \
             create_property_group(property_group, connection)
     return created_property_group
Ejemplo n.º 22
0
def test_property_group_deletion():
    property_group_name = 'property_group_name'
    simulator = DeletePropertyGroup(property_group_name)
    with MockPortalConnection(simulator) as connection:
        assert_is_none(delete_property_group(property_group_name, connection))
Ejemplo n.º 23
0
 def test_successful_deletion(self):
     simulator = DeleteContactList(_STUB_CONTACT_LIST.id)
     with MockPortalConnection(simulator) as connection:
         delete_contact_list(_STUB_CONTACT_LIST.id, connection)
Ejemplo n.º 24
0
    def _check_properties_retrieval(self, properties):
        api_calls_simulator = GetAllProperties(properties)
        with MockPortalConnection(api_calls_simulator) as connection:
            retrieved_properties = get_all_properties(connection)

        eq_(list(properties), list(retrieved_properties))
Ejemplo n.º 25
0
 def test_unsupported_type(self):
     api_calls_simulator = _simulate_get_all_properties_with_unsupported_type
     with assert_raises(MultipleInvalid):
         with MockPortalConnection(api_calls_simulator) as connection:
             get_all_properties(connection)
Ejemplo n.º 26
0
    def _check_create_property(cls, property_, expected_property):
        simulator = CreateProperty(property_)
        with MockPortalConnection(simulator) as connection:
            created_property = create_property(property_, connection)

        eq_(expected_property, created_property)
Ejemplo n.º 27
0
def test_successful_property_deletion():
    property_name = 'test'
    simulator = DeleteProperty(property_name)
    with MockPortalConnection(simulator) as connection:
        delete_property(property_name, connection)
Ejemplo n.º 28
0
 def _make_connection_with_contact_lists(self, contact_lists):
     simulator = GetAllContactLists(contact_lists)
     connection = MockPortalConnection(simulator)
     return connection
Ejemplo n.º 29
0
 def _make_connection_for_contact(contact, available_property=None):
     available_property = available_property or STUB_STRING_PROPERTY
     simulator = UpdateContact(contact, [available_property])
     connection = MockPortalConnection(simulator)
     return connection