Exemplo n.º 1
0
    def test_amount_1(self):
        """Don't manage stock amount.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Refresh item amount
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2
            })
        request.session = self.session
        request.user = self.user

        refresh_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 2.0)
Exemplo n.º 2
0
    def test_amount_2(self):
        """Manage stock amount; refresh to 2 only 1 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # prepare shipping/payment methods
        from lfs.payment.models import PaymentMethod
        from lfs.shipping.models import ShippingMethod
        pm = PaymentMethod.objects.create(name='pm')
        sm = ShippingMethod.objects.create(name='sm')

        # Try to increase item to two, but there is only one in stock
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2,
                "shipping_method": sm.pk,
                "payment_method": pm.pk
            })
        request.session = self.session
        request.user = self.user

        # This results into a message to the customer
        result = json.loads(refresh_cart(request).content)
        self.assertEqual(
            result.get("message"),
            "Sorry, but \'Product 1\' is only one time available.")

        # And the amount of the item is still 1.0
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = json.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = json.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)
Exemplo n.º 3
0
    def test_amount_1(self):
        """Don't manage stock amount.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # prepare shipping/payment methods
        from lfs.payment.models import PaymentMethod
        from lfs.shipping.models import ShippingMethod
        pm = PaymentMethod.objects.create(name='pm')
        sm = ShippingMethod.objects.create(name='sm')

        # Refresh item amount
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2,
                "shipping_method": sm.pk,
                "payment_method": pm.pk
            })
        request.session = self.session
        request.user = self.user
        refresh_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 2.0)
Exemplo n.º 4
0
    def test_amount_1(self):
        """Don't manage stock amount.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # prepare shipping/payment methods
        from lfs.payment.models import PaymentMethod
        from lfs.shipping.models import ShippingMethod
        pm = PaymentMethod.objects.create(name='pm')
        sm = ShippingMethod.objects.create(name='sm')

        # Refresh item amount
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2,
                                "shipping_method": sm.pk, "payment_method": pm.pk})
        request.session = self.session
        request.user = self.user
        refresh_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 2.0)
Exemplo n.º 5
0
    def test_amount_3(self):
        """Manage stock amount; refresh to 3 only 2 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 2
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Increase items to two
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Try to increase item to 3, but there are only 2 in stock
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 3})
        request.session = self.session
        request.user = self.user

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "Sorry, but \'Product 1\' is only 2.0 times available.")

        # And the amount of the item is still 2.0
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 3.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 3.0)
Exemplo n.º 6
0
    def test_amount_2(self):
        """Manage stock amount; refresh to 2 only 1 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # prepare shipping/payment methods
        from lfs.payment.models import PaymentMethod
        from lfs.shipping.models import ShippingMethod
        pm = PaymentMethod.objects.create(name='pm')
        sm = ShippingMethod.objects.create(name='sm')

        # Try to increase item to two, but there is only one in stock
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2,
                                "shipping_method": sm.pk, "payment_method": pm.pk})
        request.session = self.session
        request.user = self.user

        # This results into a message to the customer
        result = json.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "Sorry, but \'Product 1\' is only one time available.")

        # And the amount of the item is still 1.0
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = json.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = json.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)
Exemplo n.º 7
0
    def test_amount_4(self):
        """Manage stock amount; refresh to 2 but no product is there anymore.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        self.p1.stock_amount = 0
        self.p1.save()

        # Try to increase item to two, but there is no product in stock anymore
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2
            })
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is not possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"),
                         "Sorry, but 'Product 1' is not available anymore.")
        self.assertEqual(cart.get_amount_of_items(), 0.0)
Exemplo n.º 8
0
    def test_amount_4(self):
        """Manage stock amount; refresh to 2 but no product is there anymore.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        self.p1.stock_amount = 0
        self.p1.save()

        # Try to increase item to two, but there is no product in stock anymore
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is not possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "Sorry, but 'Product 1' is not available anymore.")
        self.assertEqual(cart.get_amount_of_items(), 0.0)
Exemplo n.º 9
0
    def test_amount_1(self):
        """Don't manage stock amount.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Refresh item amount
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        refresh_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 2.0)
Exemplo n.º 10
0
    def test_amount_4(self):
        """Manage stock amount; refresh to 2 but no product is there anymore.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        item_id = cart.get_items()[0].id

        self.p1.stock_amount = 0
        self.p1.save()

        self.assertEqual(0, len(cart.get_items()))

        # prepare shipping/payment methods
        from lfs.payment.models import PaymentMethod
        from lfs.shipping.models import ShippingMethod

        pm = PaymentMethod.objects.create(name="pm")
        sm = ShippingMethod.objects.create(name="sm")

        # Try to increase item to two, but there is no product in stock anymore
        request = rf.post(
            "/",
            {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % item_id: 2,
                "shipping_method": sm.pk,
                "payment_method": pm.pk,
            },
        )
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is not possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(cart.get_amount_of_items(), 0.0)
        self.assertTrue("Your Cart is empty" in result.get("html"))
Exemplo n.º 11
0
    def test_amount_4(self):
        """Manage stock amount; refresh to 2 but no product is there anymore.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        item_id = cart.get_items()[0].id

        self.p1.stock_amount = 0
        self.p1.save()

        self.assertEqual(0, len(cart.get_items()))

        # prepare shipping/payment methods
        from lfs.payment.models import PaymentMethod
        from lfs.shipping.models import ShippingMethod
        pm = PaymentMethod.objects.create(name='pm')
        sm = ShippingMethod.objects.create(name='sm')

        # Try to increase item to two, but there is no product in stock anymore
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % item_id: 2,
                "shipping_method": sm.pk,
                "payment_method": pm.pk
            })
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is not possible
        result = json.loads(refresh_cart(request).content)
        self.assertEqual(cart.get_amount_of_items(), 0.0)
        self.assertTrue('Your Cart is empty' in result.get("html"))