def test_checkout_shipping_address_setter(): address = Address(first_name='Jan', last_name='Kowalski') checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code') checkout.shipping_address = address assert checkout.storage['shipping_address'] == { 'city': u'', 'city_area': u'', 'company_name': u'', 'country': '', 'phone': u'', 'country_area': u'', 'first_name': 'Jan', 'id': None, 'last_name': 'Kowalski', 'postal_code': u'', 'street_address_1': u'', 'street_address_2': u''}
def save(self, commit=True): instance = super(ChurchForm, self).save(commit=False) if commit: data = self.cleaned_data address = instance.address or Address() for field in address_fields: setattr(address, field, data[field]) address.save() instance.address = address instance.save() return instance
def test_total_setter(billing_address: Address, tax_rates_countries: dict): price = Price(net=10, gross=20, currency='USD') order = models.Order() order.total = price assert order.total_net.net == 10 assert order.total_tax.net == 10 # testing the tax applying from the billing address order.billing_address = billing_address price = Price(net=10, currency='EUR') assert order.total_net.net == 10 for country, tax_rate in tax_rates_countries.items(): billing_address.country = Country(country) order.total = price expected_tax = Decimal(10 * tax_rate) assert order.total_net.net == 10 assert_decimal(order.total_tax.net, expected_tax) assert order.tax_rate == int(tax_rate * 100)