本文整理汇总了Python中models.Product.reserve方法的典型用法代码示例。如果您正苦于以下问题:Python Product.reserve方法的具体用法?Python Product.reserve怎么用?Python Product.reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.reserve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reserved
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import reserve [as 别名]
def test_reserved(self):
qty = random.randint(1,10)
print ' To reserve: ',qty,
if Product.reserve(self.name,qty):
p = Product.get_by_key_name(self.name)
print ' AVAILABLE: ',p.available
self.assertEqual(p.available, p.stock - qty, 'Not reserving correctly')
else:
p = Product.get_by_key_name(self.name)
print ' Not enough stock', p.available
self.assertGreater(qty, p.available, 'Not reserving correctly')
示例2: test_stocked
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import reserve [as 别名]
def test_stocked(self):
qty = random.randint(1,10)
print ' To buy: ',qty,
if Product.reserve(self.name,qty):
p = Product.get_by_key_name(self.name)
before = p.reserved
Product.remove_stock(self.name,qty)
p = Product.get_by_key_name(self.name)
print ' AVAILABLE: ',p.available
self.assertEqual(p.available, p.stock, 'Not lowering stock correctly ')
self.assertEqual(before - qty,p.reserved, 'Not lowering reserves correctly')
else:
p = Product.get_by_key_name(self.name)
print ' Not enough stock', p.available
self.assertGreater(qty, p.available, 'Not reserving correctly')
示例3: test_reserved_stock
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import reserve [as 别名]
def test_reserved_stock(self):
#3 random products in cart
value = 0.0
result = 0
items_no = 0
for i in range(3):
qty = random.randint(1,10)
print 'product: ', self.products[i], ' to reserve: ',qty,
if Product.reserve(self.products[i],qty):
p = Product.get_by_key_name(self.products[i])
#print p.stock, p.reserved
self.cart.add_item(CartItem(p),qty)
result += qty
items_no +=1
#p = Product.get_by_key_name(self.products[i])
print self.cart.total_different_items, items_no
self.assertEqual(self.cart.total_different_items, items_no, 'Error in total different items')
self.assertEqual(self.cart.total_items, result, 'Error in total_items')