当前位置: 首页>>代码示例>>Python>>正文


Python RequestFactory.post方法代码示例

本文整理汇总了Python中lfs.tests.utils.RequestFactory.post方法的典型用法代码示例。如果您正苦于以下问题:Python RequestFactory.post方法的具体用法?Python RequestFactory.post怎么用?Python RequestFactory.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lfs.tests.utils.RequestFactory的用法示例。


在下文中一共展示了RequestFactory.post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_amount_4

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    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)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:32,代码来源:tests.py

示例2: test_amount_1

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    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)
开发者ID:ethirajit,项目名称:onlinepos,代码行数:29,代码来源:tests.py

示例3: test_standard_product

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_standard_product(self):
        session = SessionStore()
        rf = RequestFactory()

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

        cart = get_cart(request)
        self.assertEqual(cart, None)

        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        # 1l login admin
        request = rf.get("/")
        request.session = session
        request.user = self.admin

        cart = get_cart(request)
        self.assertEqual(cart, None)

        update_cart_after_login(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        # logout
        session = SessionStore()
        request = rf.post("/", {"product_id": self.p0.id, "quantity": 2})
        request.session = session
        request.user = AnonymousUser()

        cart = get_cart(request)
        self.assertEqual(cart, None)

        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 2)

        # 2. login admin
        request = rf.get("/")
        request.session = session
        request.user = self.admin

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        update_cart_after_login(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 3)
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:57,代码来源:tests.py

示例4: test_amount_3

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    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)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:57,代码来源:tests.py

示例5: test_amount_2

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    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)
开发者ID:ethirajit,项目名称:onlinepos,代码行数:55,代码来源:tests.py

示例6: test_amount_4

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    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"))
开发者ID:naro,项目名称:django-lfs,代码行数:51,代码来源:tests.py

示例7: test_add_to_cart_stock_2

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_add_to_cart_stock_2(self):
        """Try to add product three times to cart if only two is in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        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": 3})
        request.session = self.session
        request.user = self.user

        # This need to result in a message to the customer
        result = add_to_cart(request)
        self.failIf(result.cookies.get("message").__str__().find("Sorry%2C%20but%20%27Product%201%27%20is%20only%202.0%20times%20available.") == -1)

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:34,代码来源:tests.py

示例8: test_add_to_cart_not_in_stock

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_add_to_cart_not_in_stock(self):
        """Try to add product to the cart which is not in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 0
        self.p1.save()

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

        self.assertRaises(Http404, add_to_cart, request)

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:32,代码来源:tests.py

示例9: test_add_to_cart_non_active

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_add_to_cart_non_active(self):
        """Try to add product to the cart which is not active.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        self.assertRaises(Http404, add_to_cart, request, self.p1.id)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:11,代码来源:tests.py

示例10: test_amount_1

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    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)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:23,代码来源:tests.py

示例11: test_add_to_cart_not_deliverable

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_add_to_cart_not_deliverable(self):
        """Try to add product to the cart which is not deliverable.
        """
        self.p1.active = True
        self.p1.deliverable = False
        self.p1.save()

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

        # Not deliverable
        self.assertRaises(Http404, add_to_cart, request, self.p1.id)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:16,代码来源:tests.py

示例12: test_totals_2

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_totals_2(self):
        """Add a product with explicit quantity to cart
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, "en_US.UTF-8")

        # Added product_1 two times to cart
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)

        # Added product_1 two times to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $40.00") == -1)
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:21,代码来源:tests.py

示例13: test_totals_1

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_totals_1(self):
        """Add a product without quantity to cart (implicit 1)
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, "en_US.UTF-8")

        # Added product_1 to cart
        add_to_cart(request)
        response = added_to_cart_items(request)

        # need to test for two versions of currency output (Mac and Ubuntu differ)
        self.failIf(response.find(u"Total: $10.00") == -1)

        # Added product_1 to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:23,代码来源:tests.py

示例14: test_totals_2

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_totals_2(self):
        """Add a product with explicit quantity to cart
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        # Check we are using german locale
        shop = lfs_get_object_or_404(Shop, pk=1)
        self.assertEqual(shop.default_locale, 'en_US.UTF-8')

        # Added product_1 two times to cart
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)

        # Added product_1 two times to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $40.00") == -1)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:23,代码来源:tests.py

示例15: test_totals_1

# 需要导入模块: from lfs.tests.utils import RequestFactory [as 别名]
# 或者: from lfs.tests.utils.RequestFactory import post [as 别名]
    def test_totals_1(self):
        """Add a product without quantity to cart (implicit 1)
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id})
        request.session = self.session
        request.user = self.user

        # Added product_1 to cart
        add_to_cart(request)
        response = added_to_cart_items(request)

        # Check we are using german locale
        shop = lfs_get_object_or_404(Shop, pk=1)
        self.assertEqual(shop.default_locale, 'en_US.UTF-8')

        # need to test for two versions of currency output (Mac and Ubuntu differ)
        self.failIf(response.find(u"Total: $10.00") == -1)

        # Added product_1 to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)
开发者ID:cloudappsetup,项目名称:django-lfs,代码行数:25,代码来源:tests.py


注:本文中的lfs.tests.utils.RequestFactory.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。