本文整理汇总了Python中shop.views.cart.CartDetails.post方法的典型用法代码示例。如果您正苦于以下问题:Python CartDetails.post方法的具体用法?Python CartDetails.post怎么用?Python CartDetails.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shop.views.cart.CartDetails
的用法示例。
在下文中一共展示了CartDetails.post方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_calling_ajax_post_returns_content
# 需要导入模块: from shop.views.cart import CartDetails [as 别名]
# 或者: from shop.views.cart.CartDetails import post [as 别名]
def test_calling_ajax_post_returns_content(self):
self.cart.user = self.user
self.cart.save()
request = Mock()
setattr(request, "is_ajax", lambda: True)
setattr(request, "user", self.user)
setattr(request, "session", {})
post = {"add_item_id": self.product.pk, "add_item_quantity": 1}
setattr(request, "POST", post)
view = CartDetails(request=request)
ret = view.post()
self.assertTrue(isinstance(ret, HttpResponse))
ret = view.get_context_data()
self.assertNotEqual(ret, None)
self.assertEqual(len(ret["cart_items"]), 1)
self.assertEqual(ret["cart_items"][0], self.item)
self.assertEqual(ret["cart_items"][0].quantity, 2)
示例2: test_calling_ajax_post_returns_content
# 需要导入模块: from shop.views.cart import CartDetails [as 别名]
# 或者: from shop.views.cart.CartDetails import post [as 别名]
def test_calling_ajax_post_returns_content(self):
self.cart.user = self.user
self.cart.save()
request = Mock()
setattr(request, 'is_ajax', lambda :True)
setattr(request, 'user', self.user)
post={
'add_item_id':self.product.id,
'add_item_quantity':1,
}
setattr(request, 'POST', post)
view = CartDetails(request=request)
ret = view.post()
self.assertTrue(isinstance(ret,HttpResponse))
ret = view.get_context_data()
self.assertNotEqual(ret,None)
self.assertEqual(len(ret['cart_items']),1)
self.assertEqual(ret['cart_items'][0], self.item)
self.assertEqual(ret['cart_items'][0].quantity, 2)