def setUp(self):
     self.non_discount_methods = [
         methods.Free(),
         methods.FixedPrice(D('10.00'), D('10.00')),
         OrderAndItemCharges(price_per_order=D('5.00'),
                             price_per_item=D('1.00'))
     ]
 def test_simple_payment_url_is_as_expected(self):
     url = self.build_payment_url(None, self.order.number,
                                  self.order.user, self.basket,
                                  shipping_methods.Free(), self.address,
                                  None)
     self.assertNotIn('testMode', url)
     self.assertEqual(
         'https://secure.worldpay.com/wcc/purchase?instId=12345&cartId=10001&currency=GBP&amount=10.58&desc=&M_basket=1&M_billing_address=None&M_shipping_address=1&M_shipping_method=free-shipping&M_user=1&M_authenticator=77cfb68a1b094c753709ec5ab0be6b37133aaa998d31f40139c1229f21f6468f&address1=75+Smith+Road&address2=&address3=&country=GB&email=test%40example.com&fixContact=True&hideContact=False&name=Barrington&postcode=N4+8TY&region=&tel=01225+442244&town=&signature=ffbf1d6b60214aa1799e4015d5376562',
         url)
Beispiel #3
0
class Repository(OcarRepository):
    """
    Repository class responsible for returning ShippingMethod
    objects for a given user, basket etc
    """

    # We default to just free shipping. Customise this class and override this
    # property to add your own shipping methods. This should be a list of
    # instantiated shipping methods.
    methods = (shipping_methods.Free(), CountDown())
    def test_redirects_customers_when_only_one_shipping_method_is_available(
            self, mock_repo):
        self.add_product_to_basket()
        self.enter_guest_details()
        self.enter_shipping_address()

        # Ensure one shipping method available
        instance = mock_repo.return_value
        instance.get_shipping_methods.return_value = [methods.Free()]

        response = self.get(reverse('checkout:shipping-method'))
        self.assertRedirectsTo(response, 'checkout:payment-method')
 def test_check_user_can_submit_only_valid_shipping_method(self, mock_repo):
     self.add_product_to_basket()
     self.enter_guest_details()
     self.enter_shipping_address()
     method = mock.MagicMock()
     method.code = 'm'
     instance = mock_repo.return_value
     instance.get_shipping_methods.return_value = [methods.Free(), method]
     form_page = self.get(reverse('checkout:shipping-method'))
     # a malicious attempt?
     form_page.forms[0]['method_code'].value = 'super-free-shipping'
     response = form_page.forms[0].submit()
     self.assertRedirectsTo(response, 'checkout:shipping-method')
Beispiel #6
0
    def test_skip_if_single_shipping_method_is_available(self, mock_repo):
        # This skip condition is not a "normal" one, but is implemented in the
        # view's "get" method
        self.add_product_to_basket()
        if self.is_anonymous:
            self.enter_guest_details()
        self.enter_shipping_address()

        # Ensure one shipping method available
        instance = mock_repo.return_value
        instance.get_shipping_methods.return_value = [methods.Free()]

        response = self.get(reverse('checkout:shipping-method'))
        self.assertRedirectsTo(response, 'checkout:payment-method')
    def test_shows_form_when_multiple_shipping_methods_available(
            self, mock_repo):
        self.add_product_to_basket()
        self.enter_guest_details()
        self.enter_shipping_address()

        # Ensure multiple shipping methods available
        method = mock.MagicMock()
        method.code = 'm'
        instance = mock_repo.return_value
        instance.get_shipping_methods.return_value = [methods.Free(), method]
        form_page = self.get(reverse('checkout:shipping-method'))
        self.assertIsOk(form_page)

        response = form_page.forms[0].submit()
        self.assertRedirectsTo(response, 'checkout:payment-method')
Beispiel #8
0
 def test_check_user_can_submit_only_valid_shipping_method(
     self,
     mock_repo,
     mock_skip_unless_basket_requires_shipping,
     mock_skip_unless_payment_is_required,
 ):
     self.add_product_to_basket()
     if self.is_anonymous:
         self.enter_guest_details()
     self.enter_shipping_address()
     method = mock.MagicMock()
     method.code = 'm'
     instance = mock_repo.return_value
     instance.get_shipping_methods.return_value = [methods.Free(), method]
     form_page = self.get(reverse('checkout:shipping-method'))
     # a malicious attempt?
     form_page.forms[0]['method_code'].value = 'super-free-shipping'
     response = form_page.forms[0].submit()
     self.assertIsNotRedirect(response)
     response.mustcontain('Your submitted shipping method is not permitted')
Beispiel #9
0
class Repository(object):
    """
    Repository class responsible for returning ShippingMethod
    objects for a given user, basket etc
    """

    # We default to just free shipping. Customise this class and override this
    # property to add your own shipping methods. This should be a list of
    # instantiated shipping methods.
    methods = (shipping_methods.Free(), )

    # API

    def get_shipping_methods(self, basket, shipping_addr=None, **kwargs):
        """
        Return a list of all applicable shipping method instances for a given
        basket, address etc.
        """
        if not basket.is_shipping_required():
            # Special case! Baskets that don't require shipping get a special
            # shipping method.
            return [shipping_methods.NoShippingRequired()]

        methods = self.get_available_shipping_methods(
            basket=basket, shipping_addr=shipping_addr, **kwargs)
        if basket.has_shipping_discounts:
            methods = self.apply_shipping_offers(basket, methods)
        return methods

    def get_default_shipping_method(self,
                                    basket,
                                    shipping_addr=None,
                                    **kwargs):
        """
        Return a 'default' shipping method to show on the basket page to give
        the customer an indication of what their order will cost.
        """
        shipping_methods = self.get_shipping_methods(
            basket, shipping_addr=shipping_addr, **kwargs)
        if len(shipping_methods) == 0:
            raise ImproperlyConfigured(
                _("You need to define some shipping methods"))

        # Assume first returned method is default
        return shipping_methods[0]

    # Helpers

    def get_available_shipping_methods(self,
                                       basket,
                                       shipping_addr=None,
                                       **kwargs):
        """
        Return a list of all applicable shipping method instances for a given
        basket, address etc. This method is intended to be overridden.
        """
        return self.methods

    def apply_shipping_offers(self, basket, methods):
        """
        Apply shipping offers to the passed set of methods
        """
        # We default to only applying the first shipping discount.
        offer = basket.shipping_discounts[0]['offer']
        return [
            self.apply_shipping_offer(basket, method, offer)
            for method in methods
        ]

    def apply_shipping_offer(self, basket, method, offer):
        """
        Wrap a shipping method with an offer discount wrapper (as long as the
        shipping charge is non-zero).
        """
        # If the basket has qualified for shipping discount, wrap the shipping
        # method with a decorating class that applies the offer discount to the
        # shipping charge.
        charge = method.calculate(basket)
        if charge.excl_tax == D('0.00'):
            # No need to wrap zero shipping charges
            return method

        if charge.is_tax_known:
            return shipping_methods.TaxInclusiveOfferDiscount(method, offer)
        else:
            # When returning a tax exclusive discount, it is assumed
            # that this will be used to calculate taxes which will then
            # be assigned directly to the method instance.
            return shipping_methods.TaxExclusiveOfferDiscount(method, offer)
Beispiel #10
0
 def setUp(self):
     self.method = methods.Free()
     self.basket = mock.Mock()
     self.basket.num_items = 1
     self.charge = self.method.calculate(self.basket)
Beispiel #11
0
 def setUp(self):
     self.method = methods.Free()
     self.basket = Basket()
     self.charge = self.method.calculate(self.basket)
Beispiel #12
0
 def setUp(self):
     self.method = methods.Free()
Beispiel #13
0
class Repository(_Repository):

    methods = (shipping_methods.Free(), )  #, Standard() )