Пример #1
0
    def test_multi_site(self):
        basket = factories.create_basket(empty=True)
        site1 = factories.SiteFactory()
        site2 = factories.SiteFactory()
        request = HttpRequest()
        request.META['SERVER_PORT'] = 80
        request.META['SERVER_NAME'] = site1.domain
        user = factories.UserFactory()
        add_product(basket, D('12.00'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {'user': user,
                                 'order_number': '12345',
                                 'basket': basket,
                                 'shipping_method': shipping_method,
                                 'shipping_charge': shipping_charge,
                                 'order_total': order_total,
                                 'billing_address': billing_address,
                                 'shipping_address': shipping_address,
                                 'request': request}
        OrderPlacementMixin().place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.site, site1)

        add_product(basket, D('12.00'))
        request.META['SERVER_NAME'] = site2.domain
        order_submission_data['order_number'] = '12346'
        order_submission_data['request'] = request
        OrderPlacementMixin().place_order(**order_submission_data)
        order2 = Order.objects.get(number='12346')
        self.assertEqual(order2.site, site2)
Пример #2
0
    def test_multiple_payment_events(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('100.00'))
        order_placement = OrderPlacementMixin()
        order_placement.add_payment_event('Gift Card Payment', D('10'))
        order_placement.add_payment_event('Credit Card Payment', D('90'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {
            'user': user,
            'order_number': '12345',
            'basket': basket,
            'shipping_method': shipping_method,
            'shipping_charge': shipping_charge,
            'order_total': order_total,
            'billing_address': billing_address,
            'shipping_address': shipping_address
        }
        order_placement.place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.payment_events.count(), 2)
        event1 = order1.payment_events.all()[0]
        event2 = order1.payment_events.all()[1]
        self.assertEqual(event1.event_type.name, 'Credit Card Payment')
        self.assertEqual(event1.amount, D('90'))
        self.assertEqual(event1.lines.count(), 1)
        self.assertEqual(event2.event_type.name, 'Gift Card Payment')
        self.assertEqual(event2.amount, D('10'))
        self.assertEqual(event2.lines.count(), 1)
Пример #3
0
    def test_multiple_payment_events(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('100.00'))
        order_placement = OrderPlacementMixin()
        order_placement.add_payment_event('Gift Card Payment', D('10'))
        order_placement.add_payment_event('Credit Card Payment', D('90'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {'user': user,
                                 'order_number': '12345',
                                 'basket': basket,
                                 'shipping_method': shipping_method,
                                 'shipping_charge': shipping_charge,
                                 'order_total': order_total,
                                 'billing_address': billing_address,
                                 'shipping_address': shipping_address}
        order_placement.place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.payment_events.count(), 2)
        event1 = order1.payment_events.all()[0]
        event2 = order1.payment_events.all()[1]
        self.assertEqual(event1.event_type.name, 'Credit Card Payment')
        self.assertEqual(event1.amount, D('90'))
        self.assertEqual(event1.lines.count(), 1)
        self.assertEqual(event2.event_type.name, 'Gift Card Payment')
        self.assertEqual(event2.amount, D('10'))
        self.assertEqual(event2.lines.count(), 1)
Пример #4
0
 def test_can_create_shipping_address_for_empty_address(self):
     address = OrderPlacementMixin().create_shipping_address(
         user=mock.Mock(), shipping_address=None)
     self.assertEqual(address, None)
Пример #5
0
    def test_update_address_book(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('12.00'))
        shipping_method = FixedPrice(D('5.00'), D('5.00'))

        billing_address = factories.BillingAddressFactory(
            line1='1 Boardwalk Place',
            line2='Trafalgar Way',
            line3='Tower Hamlets',
            line4='London')
        shipping_address = factories.ShippingAddressFactory(
            line1='Knightsbridge', line2='159', line4='London')
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        order_submission_data = {
            'user': user,
            'order_number': '12345',
            'basket': basket,
            'shipping_address': shipping_address,
            'shipping_method': shipping_method,
            'shipping_charge': shipping_charge,
            'billing_address': billing_address,
            'order_total': order_total
        }
        OrderPlacementMixin().place_order(**order_submission_data)

        self.assertEqual(
            user.addresses.filter(
                hash=billing_address.generate_hash()).count(), 1)
        self.assertEqual(
            user.addresses.filter(
                hash=shipping_address.generate_hash()).count(), 1)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 1)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         1)

        order_submission_data['order_number'] = '12346'

        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 2)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         2)

        order_submission_data.pop('billing_address', None)
        order_submission_data['order_number'] = '123457'
        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 2)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         3)

        shipping_address.line2 = '160'
        order_submission_data['billing_address'] = billing_address
        order_submission_data['order_number'] = '123458'
        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 3)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         1)
Пример #6
0
 def test_returns_none_when_no_shipping_address_passed_to_creation_method(
         self):
     address = OrderPlacementMixin().create_shipping_address(
         user=mock.Mock(), shipping_address=None)
     self.assertEqual(address, None)