diff --git a/oscar/apps/checkout/mixins.py b/oscar/apps/checkout/mixins.py index 0eea5ab62f6..8456a0ef988 100644 --- a/oscar/apps/checkout/mixins.py +++ b/oscar/apps/checkout/mixins.py @@ -145,6 +145,10 @@ def create_shipping_address(self, user, shipping_address): Compared to self.get_shipping_address(), ShippingAddress is saved and makes sure that appropriate UserAddress exists. """ + # For an order that only contains items that don't require shipping we + # won't have a shipping address, so we have to check for it. + if not shipping_address: + return None shipping_address.save() if user.is_authenticated(): self.update_address_book(user, shipping_address) diff --git a/tests/unit/checkout/mixins_tests.py b/tests/unit/checkout/mixins_tests.py new file mode 100644 index 00000000000..562858b28ad --- /dev/null +++ b/tests/unit/checkout/mixins_tests.py @@ -0,0 +1,13 @@ +import mock + +from django.test import TestCase + +from oscar.apps.checkout.mixins import OrderPlacementMixin + + +class TestOrderPlacementMixin(TestCase): + + def test_can_create_shipping_address_for_empty_address(self): + address = OrderPlacementMixin().create_shipping_address( + user=mock.Mock(), shipping_address=None) + self.assertEquals(address, None)