def test_with_already_populated_billing_address(self, billing_address): """ Test that if the order has some billing address fields already populated, none of the address fields get overridden. """ company = CompanyFactory.build( address_1='1', address_2='Hello st.', address_town='Muckamore', address_county='Antrim', address_postcode='BT41 4QE', address_country_id=Country.ireland.value.id, ) order = OrderFactory.build( company=company, **billing_address, ) populate_billing_data(order) # check that the fields didn't get overridden actual_billing_address = { field_name: getattr(order, field_name) for field_name in billing_address } assert actual_billing_address == billing_address
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_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_order_get_absolute_url(): """Test that Order.get_absolute_url() returns the correct URL.""" order = OrderFactory.build() assert order.get_absolute_url() == ( f'{settings.DATAHUB_FRONTEND_URL_PREFIXES["order"]}/{order.pk}')