本文整理匯總了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)