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)
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)
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)
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)
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))
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
def _make_connection_for_contacts(cls, contacts): simulator = UnsuccessfulSaveContacts( contacts, cls._STUB_EXCEPTION, [STUB_STRING_PROPERTY], ) connection = MockPortalConnection(simulator) return 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 _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
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)
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)
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)
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)
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
def _make_connection(cls, contacts): simulator = cls._make_simulator(contacts) connection = MockPortalConnection(simulator) return connection
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)
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
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
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))
def test_successful_deletion(self): simulator = DeleteContactList(_STUB_CONTACT_LIST.id) with MockPortalConnection(simulator) as connection: delete_contact_list(_STUB_CONTACT_LIST.id, connection)
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))
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)
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)
def test_successful_property_deletion(): property_name = 'test' simulator = DeleteProperty(property_name) with MockPortalConnection(simulator) as connection: delete_property(property_name, connection)
def _make_connection_with_contact_lists(self, contact_lists): simulator = GetAllContactLists(contact_lists) connection = MockPortalConnection(simulator) return connection
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