def _retrieve_contact_with_specified_property( self, property_definition, property_value, **kwargs ): property_names = [property_definition.name] if self._CONTACT_LIST: kwargs['contact_list'] = self._CONTACT_LIST simulator_contact = \ make_contact(1, {property_definition.name: property_value}) connection = self._make_connection_for_contacts( contacts=[simulator_contact], available_property=property_definition, property_names=property_names, **kwargs ) with connection: # Trigger API calls by consuming iterator retrieved_contacts = list( self._RETRIEVER( connection=connection, property_names=property_names, **kwargs ), ) retrieved_contact = retrieved_contacts[0] return retrieved_contact
def test_getting_existing_properties(self): simulator_contacts = [ make_contact(1, properties={STUB_PROPERTY.name: 'foo'}), make_contact( 2, properties={STUB_PROPERTY.name: 'baz', 'p2': 'bar'}, ), ] expected_contacts = _get_contacts_with_stub_property(simulator_contacts) self._check_contacts_from_simulated_retrieval_equal( simulator_contacts, expected_contacts, property_names=[STUB_PROPERTY.name], )
def test_property_type_casting_for_unknown_property(self): simulator_contact = make_contact(1, {'p1': 'yes'}) expected_contact = simulator_contact.copy() expected_contact.properties = {} self._check_contacts_from_simulated_retrieval_equal( [simulator_contact], [expected_contact], )
def test_conflicting_email_address_property(self): contact = make_contact(1, {_EMAIL_PROPERTY.name: '*****@*****.**'}) with assert_raises(AssertionError): self._make_connection_for_contacts( [contact], available_property=_EMAIL_PROPERTY, **self._get_kwargs_for_email_property() )
def test_invalid_property_raises_hubspot_client_error(self): contact = make_contact(None, properties={'is_polite': 'notavalidinput'}) with assert_raises(HubspotClientError) as context: with self._make_connection_for_contact_with_exception( contact, HubspotClientError("Property notavalidinput is invalid", "request-id")) as connection: create_contact(contact, connection) eq_(context.exception.message, "Property notavalidinput is invalid")
def test_getting_email_address_as_property(self): contact_with_email = make_contact(1) contact_with_no_email = make_contact(2) contact_with_no_email.email_address = None simulator_contacts = [contact_with_email, contact_with_no_email] expected_contacts = \ _get_contacts_with_email_property(simulator_contacts) kwargs = self._get_kwargs_for_email_property() connection = self._make_connection_for_contacts( simulator_contacts, available_property=_EMAIL_PROPERTY, **kwargs ) with connection: # Trigger API calls by consuming iterator retrieved_contacts = \ list(self._RETRIEVER(connection=connection, **kwargs)) _assert_retrieved_contacts_equal(expected_contacts, 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 _assert_property_value_cast_equals( self, property_definition, original_value, expected_cast_value, ): contact = make_contact(1, {property_definition.name: original_value}) contacts = [contact] connection = \ self._make_connection_for_contacts(contacts, property_definition) with connection: save_contacts(contacts, connection) api_call = connection.api_calls[-1] contact_data = api_call.request_body_deserialization[0] contact_properties_data = contact_data['properties'] contact_property_data = contact_properties_data[0] eq_(expected_cast_value, contact_property_data['value'])
def test_contacts_with_related_contact_vids(self): contacts = [make_contact(1, related_contact_vids=[2, 3])] self._check_contacts_from_simulated_retrieval_equal(contacts, contacts)
def test_update_single_contact(self): contact = make_contact(1) with self._make_connection_for_contact(contact) as connection: update_contact(contact, connection)
def test_create_single_contact(self): contact = make_contact(None) with self._make_connection_for_contact(1, contact) as connection: vid = create_contact(contact, connection) eq_(1, vid)
def test_property_values_in_request(self): property_value = 'true' contact = make_contact(1, {STUB_STRING_PROPERTY.name: property_value}) self._check_saved_contacts_match([contact])