コード例 #1
0
 def test_init_shop(self):
     s = Shop(ITEM_LIST)
     assert len(s) == 3
     assert s[0] == Item({
         'title': "Ballpoint pens, 100 pack",
         'price': Decimal('12.99'),
         'inventory_count': 2
     })
     assert s[1] == Item(DUMMY_ITEM)
     assert s[2] == Item({
         'title': "Fork",
         'price': Decimal('2.49'),
         'inventory_count': 10
     })
コード例 #2
0
 def test_get_item_by_name(self):
     s = Shop(ITEM_LIST)
     assert s.get('Fork') == Item({
         'title': "Fork",
         'price': Decimal('2.49'),
         'inventory_count': 10
     })
     with pytest.raises(KeyError):
         s.get('Antimatter')
コード例 #3
0
    def test_remove(self):
        c = Cart()
        i = Item(DUMMY_ITEM)
        c.add(i)
        c.add(i)
        assert c.total == Decimal('2')
        assert c.names == ['Cup']
        assert c.items == [{'product': i.dict(), 'quantity': 2}]

        c.remove('Cup')
        assert c.total == Decimal('1')
        assert c.names == ['Cup']
        assert c.items == [{'product': i.dict(), 'quantity': 1}]

        c.remove('Cup')
        assert c.total == Decimal('0')
        assert c.names == []
        assert c.items == []
コード例 #4
0
 def test_add_out_of_stock(self):
     c = Cart()
     with pytest.raises(ValueError):
         c.add(
             Item({
                 'title': "Arid Mesa",
                 'price': Decimal('50.00'),
                 'inventory_count': 0
             }))
コード例 #5
0
 def test_add_item_over_limit(self):
     c = Cart()
     i = Item(DUMMY_ITEM)
     c.add(i)
     assert c.items == [{'product': i, 'quantity': 1}]
     c.add(i)
     c.add(i)
     assert c.total == Decimal('3')
     c.add(i)
     with pytest.raises(ValueError):
         c.add(i)
コード例 #6
0
 def test_add_multiple_items_over_limit(self):
     c = Cart()
     i1 = Item(DUMMY_ITEM)
     i2 = Item({
         'title': "Arid Mesa",
         'price': Decimal('50.00'),
         'inventory_count': 1
     })
     c.add(i2)
     c.add(i1)
     c.add(i1)
     assert c.items == [{
         'product': i2,
         'quantity': 1
     }, {
         'product': i1,
         'quantity': 2
     }]
     assert c.total == Decimal('52')
     with pytest.raises(ValueError):
         c.add(i2)
コード例 #7
0
    def test_checkout_over_stock_cart(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            # let's exploit how Carts are implemented!
            cart.my_cart.add(Item({
                'title': "Chachalaca",
                'price': Decimal('3.50'),
                'inventory_count': 999  # fake inventory_count fools the quantity check
            }))

            with pytest.raises(NotAcceptable):
                cart.checkout_cart()
コード例 #8
0
 def test_view(self):
     c = Cart()
     i1 = Item(DUMMY_ITEM)
     i2 = Item({
         'title': "Fork",
         'price': Decimal('2.49'),
         'inventory_count': 10
     })
     c.add(i1)
     c.add(i1)
     c.add(i2)
     cartstruct = c.view()
     assert cartstruct['total'] == Decimal('4.49')
     assert cartstruct['items'] == [{
         'product': i1.dict(),
         'quantity': 2
     }, {
         'product': i2.dict(),
         'quantity': 1
     }]
コード例 #9
0
 def test_item_equality(self):
     cup = Item(DUMMY_ITEM)
     assert cup == Item(DUMMY_ITEM)
コード例 #10
0
 def test_negative_stock(self):
     cup = Item(DUMMY_ITEM)
     cup.inventory_count -= 1
     assert cup.inventory_count == 3
     with pytest.raises(ValueError):
         cup.inventory_count -= 99
コード例 #11
0
 def test_init_item(self):
     cup = Item(DUMMY_ITEM)
     assert cup is not None
     assert cup.title == "Cup"
     assert cup.price == Decimal('1.00')
     assert cup.inventory_count == 4