Ejemplo n.º 1
0
    def test_login(self):
        """Tests the login view.
        """
        from lfs.checkout.views import login
        from lfs.checkout.settings import CHECKOUT_TYPE_ANON

        from lfs.tests.utils import create_request
        request = create_request()

        # Anonymous
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser()

        result = login(request)
        self.assertEqual(result.status_code, 200)

        # Set checkout_type
        shop = get_default_shop()
        shop.checkout_type = CHECKOUT_TYPE_ANON
        shop.save()

        # Fake a new reuqest
        request.shop = shop

        result = login(request)
        self.assertEqual(result.status_code, 302)

        # Authenticated
        request.user = self.user
        result = login(request)

        self.assertEqual(result.status_code, 302)
Ejemplo n.º 2
0
    def test_shipping_price_4(self):
        """Tests an additional shipping method price with a criterion and customer price
        """
        # create country dependent tax
        self.us = Country.objects.create(code="us", name="USA")
        self.ch = Country.objects.create(code="ch", name="Switzerland")

        self.request = create_request()
        self.request.user = AnonymousUser()
        self.customer = get_or_create_customer(self.request)

        self.ct1 = CustomerTax.objects.create(rate=10.0)
        cc = CountryCriterion.objects.create(content=self.ct1,
                                             operator=Criterion.IS_SELECTED)
        cc.value.add(self.us)

        self.sm1.price = 10
        self.sm1.price_calculator = settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[
            1][0]
        self.sm1.save()

        costs = utils.get_shipping_costs(self.request, self.sm1)
        self.assertEqual(costs["price_gross"], 10)
        self.assertEqual(costs["price_net"], 10)
        self.assertEqual(costs["tax"], 0)

        self.customer.selected_shipping_address.country = self.us
        self.customer.selected_shipping_address.save()

        costs = utils.get_shipping_costs(self.request, self.sm1)
        self.assertEqual(costs["price_gross"], 11)
        self.assertEqual(costs["price_net"], 10)
        self.assertEqual(costs["tax"], 1)
Ejemplo n.º 3
0
    def test_login(self):
        """Tests the login view.
        """
        from lfs.checkout.views import login
        from lfs.checkout.settings import CHECKOUT_TYPE_ANON

        from lfs.tests.utils import create_request
        request = create_request()

        # Anonymous
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser()

        result = login(request)
        self.assertEqual(result.status_code, 200)

        # Set checkout_type
        shop = get_default_shop()
        shop.checkout_type = CHECKOUT_TYPE_ANON
        shop.save()

        # Fake a new reuqest
        request.shop = shop

        result = login(request)
        self.assertEqual(result.status_code, 302)

        # Authenticated
        request.user = self.user
        result = login(request)

        self.assertEqual(result.status_code, 302)
Ejemplo n.º 4
0
    def test_shipping_price_4(self):
        """Tests an additional shipping method price with a criterion and customer price
        """
        # create country dependent tax
        self.us = Country.objects.create(code="us", name="USA")
        self.ch = Country.objects.create(code="ch", name="Switzerland")

        self.request = create_request()
        self.request.user = AnonymousUser()
        self.customer = get_or_create_customer(self.request)

        self.ct1 = CustomerTax.objects.create(rate=10.0)
        cc = CountryCriterion.objects.create(content=self.ct1, operator=Criterion.IS_SELECTED)
        cc.value.add(self.us)

        self.sm1.price = 10
        self.sm1.price_calculator = settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[1][0]
        self.sm1.save()

        costs = utils.get_shipping_costs(self.request, self.sm1)
        self.assertEqual(costs["price_gross"], 10)
        self.assertEqual(costs["price_net"], 10)
        self.assertEqual(costs["tax"], 0)

        self.customer.selected_shipping_address.country = self.us
        self.customer.selected_shipping_address.save()

        costs = utils.get_shipping_costs(self.request, self.sm1)
        self.assertEqual(costs["price_gross"], 11)
        self.assertEqual(costs["price_net"], 10)
        self.assertEqual(costs["tax"], 1)
Ejemplo n.º 5
0
    def test_get_product_delivery_time_2(self):
        """Tests the product delivery time for the *cart view*.
        """
        request = create_request()
        request.user = AnonymousUser()

        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()

        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        dt = utils.get_product_delivery_time(request, self.p2, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        customer.selected_shipping_method = self.sm2
        customer.save()

        # As the customer has now selected sm2 explicitely the delivery method
        # for the products is dt2 although the default shipping method is
        # sm1.
        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid, hence we should get dt1
        dt = utils.get_product_delivery_time(request, self.p2, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # Create a weigth criterion and add it to the shipping method 1. That
        # means sm1 is not valid anymore for p1.
        WeightCriterion.objects.create(content=self.sm1,
                                       value=10.0,
                                       operator=GREATER_THAN)

        # And even if the customer select sm1 explicitely ...
        customer.selected_shipping_method = self.sm1
        customer.save()

        # ... the shipping method for p1 is sm2 and hence the delivery time is
        # dt2
        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)
Ejemplo n.º 6
0
    def test_get_product_delivery_time_2(self):
        """Tests the product delivery time for the *cart view*.
        """
        request = create_request()
        request.user = AnonymousUser()

        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()

        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        dt = utils.get_product_delivery_time(request, self.p2, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        customer.selected_shipping_method = self.sm2
        customer.save()

        # As the customer has now selected sm2 explicitely the delivery method
        # for the products is dt2 although the default shipping method is
        # sm1.
        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid, hence we should get dt1
        dt = utils.get_product_delivery_time(request, self.p2, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # Create a weigth criterion and add it to the shipping method 1. That
        # means sm1 is not valid anymore for p1.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # And even if the customer select sm1 explicitely ...
        customer.selected_shipping_method = self.sm1
        customer.save()

        # ... the shipping method for p1 is sm2 and hence the delivery time is
        # dt1
        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)
Ejemplo n.º 7
0
    def test_get_product_delivery_time_1(self):
        """Tests the product delivery time for the *product view*.
        """
        request = create_request()
        request.user = AnonymousUser()

        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()

        # We select a explicitely shipping method for the customer. For the
        # product view this shouldn't make a difference. It should always the
        # first valid shipping method be taken to display the delivery time.
        customer.selected_shipping_method = self.sm2
        customer.save()

        # Create a weigth criterion and add it to the shipping method 1.
        WeightCriterion.objects.create(content=self.sm1,
                                       value=10.0,
                                       operator=GREATER_THAN)

        # Create a weigth criterion and add it to the shipping method 2.
        WeightCriterion.objects.create(content=self.sm2,
                                       value=10.0,
                                       operator=LESS_THAN)

        # Now we ask for the delivery time for product 1. As sm1 is not valid
        # (p1 has an weight of 6.0) we should get the delivery time from sm2,
        # which is dt2
        dt = utils.get_product_delivery_time(request, self.p1)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid (p2 has an weight of 11.0), hence we should
        # get dt1.
        dt = utils.get_product_delivery_time(request, self.p2)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        # Now we switch to manual delivery time
        self.p1.manual_delivery_time = True
        self.p1.delivery_time = self.dt3
        self.p1.save()

        dt = utils.get_product_delivery_time(request, self.p1)
        self.assertEqual(dt.min, self.dt3.min)
        self.assertEqual(dt.max, self.dt3.max)
        self.assertEqual(dt.unit, self.dt3.unit)
Ejemplo n.º 8
0
    def test_get_product_delivery_time_1(self):
        """Tests the product delivery time for the *product view*.
        """
        request = create_request()
        request.user = AnonymousUser()

        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()

        # We select a explicitely shipping method for the customer. For the
        # product view this shouldn't make a difference. It should always the
        # first valid shipping method be taken to display the delivery time.
        customer.selected_shipping_method = self.sm2
        customer.save()

        # Create a weigth criterion and add it to the shipping method 1.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # Create a weigth criterion and add it to the shipping method 2.
        c = WeightCriterion.objects.create(weight=10.0, operator=LESS_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm2)
        co.save()

        # Now we ask for the delivery time for product 1. As sm1 is not valid
        # (p1 has an weight of 6.0) we should get the delivery time from sm2,
        # which is dt2
        dt = utils.get_product_delivery_time(request, self.p1)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid (p2 has an weight of 11.0), hence we should
        # get dt1.
        dt = utils.get_product_delivery_time(request, self.p2)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        # Now we switch to manual delivery time
        self.p1.manual_delivery_time = True
        self.p1.delivery_time = self.dt3
        self.p1.save()

        dt = utils.get_product_delivery_time(request, self.p1)
        self.assertEqual(dt.min, self.dt3.min)
        self.assertEqual(dt.max, self.dt3.max)
        self.assertEqual(dt.unit, self.dt3.unit)
Ejemplo n.º 9
0
    def setUp(self):
        self.us = Country.objects.create(code="us", name="USA")
        self.ch = Country.objects.create(code="ch", name="Switzerland")
        self.de = Country.objects.create(code="de", name="Germany")
        self.ie = Country.objects.create(code="ie", name="Ireland")

        self.product = Product.objects.create(name="P1", slug="p1", price=100.0)

        self.request = create_request()
        self.request.user = AnonymousUser()
        self.customer = get_or_create_customer(self.request)

        self.ct1 = CustomerTax.objects.create(rate = 20.0)
        self.ct1.countries.add(self.ch)
        self.ct1.countries.add(self.us)

        self.ct2 = CustomerTax.objects.create(rate = 10.0)
        self.ct2.countries.add(self.ie)
Ejemplo n.º 10
0
    def setUp(self):
        self.us = Country.objects.create(code="us", name="USA")
        self.ch = Country.objects.create(code="ch", name="Switzerland")
        self.de = Country.objects.create(code="de", name="Germany")
        self.ie = Country.objects.create(code="ie", name="Ireland")

        self.product = Product.objects.create(name="P1",
                                              slug="p1",
                                              price=100.0)

        self.request = create_request()
        self.request.user = AnonymousUser()
        self.customer = get_or_create_customer(self.request)

        self.ct1 = CustomerTax.objects.create(rate=20.0)
        self.ct1.countries.add(self.ch)
        self.ct1.countries.add(self.us)

        self.ct2 = CustomerTax.objects.create(rate=10.0)
        self.ct2.countries.add(self.ie)
Ejemplo n.º 11
0
    def setUp(self):
        self.us = Country.objects.create(code="us", name="USA")
        self.ch = Country.objects.create(code="ch", name="Switzerland")
        self.de = Country.objects.create(code="de", name="Germany")
        self.ie = Country.objects.create(code="ie", name="Ireland")

        self.product = Product.objects.create(name="P1", slug="p1", price=100.0)

        self.request = create_request()
        self.request.user = AnonymousUser()
        self.customer = get_or_create_customer(self.request)

        self.ct1 = CustomerTax.objects.create(rate=20.0)
        cc = CountryCriterion.objects.create(content=self.ct1, operator=Criterion.IS_SELECTED)
        cc.value.add(self.ch)
        cc.value.add(self.us)

        self.ct2 = CustomerTax.objects.create(rate=10.0)
        cc = CountryCriterion.objects.create(content=self.ct2, operator=Criterion.IS_SELECTED)
        cc.value.add(self.ie)
Ejemplo n.º 12
0
    def setUp(self):
        self.us = Country.objects.create(code="us", name="USA")
        self.ch = Country.objects.create(code="ch", name="Switzerland")
        self.de = Country.objects.create(code="de", name="Germany")
        self.ie = Country.objects.create(code="ie", name="Ireland")

        self.product = Product.objects.create(name="P1",
                                              slug="p1",
                                              price=100.0)

        self.request = create_request()
        self.request.user = AnonymousUser()
        self.customer = get_or_create_customer(self.request)

        self.ct1 = CustomerTax.objects.create(rate=20.0)
        cc = CountryCriterion.objects.create(content=self.ct1,
                                             operator=Criterion.IS_SELECTED)
        cc.value.add(self.ch)
        cc.value.add(self.us)

        self.ct2 = CustomerTax.objects.create(rate=10.0)
        cc = CountryCriterion.objects.create(content=self.ct2,
                                             operator=Criterion.IS_SELECTED)
        cc.value.add(self.ie)