def test_with_empty_order(self, initial_model_values, expected_billing_address_fields): """ Test that an order without any of the billing fields filled in is populated with the company/contact details. """ company = CompanyFactory.build(**initial_model_values) order = OrderFactory.build( billing_company_name='', billing_contact_name='', billing_email='', billing_phone='', billing_address_1='', billing_address_2='', billing_address_town='', billing_address_county='', billing_address_postcode='', billing_address_country=None, company=company, contact=ContactFactory.build(), ) populate_billing_data(order) assert not order.billing_contact_name assert not order.billing_email assert not order.billing_phone assert order.billing_company_name == company.name actual_billing_address = { field_name: getattr(order, field_name) for field_name in expected_billing_address_fields } assert actual_billing_address == expected_billing_address_fields
def test_str(self, first_name, last_name, company_factory, expected_output): """Test the human-friendly string representation of a Contact object.""" contact = ContactFactory.build( first_name=first_name, last_name=last_name, company=company_factory(), ) assert str(contact) == expected_output
def test_with_already_populated_billing_company_name(self): """ Test that if the billing company name for an order is already set, it does not get overridden. """ billing_company_name = 'My Corp' order = OrderFactory.build( contact=ContactFactory.build(), billing_company_name=billing_company_name, ) populate_billing_data(order) assert order.billing_company_name == billing_company_name
def test_get_absolute_url(self): """Test that Contact.get_absolute_url() returns the correct URL.""" contact = ContactFactory.build() assert contact.get_absolute_url() == ( f'{settings.DATAHUB_FRONTEND_URL_PREFIXES["contact"]}/{contact.pk}' )