예제 #1
0
    def test_checkout_empty_cart(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            cart.checkout_cart()
            assert cart.my_cart is None
예제 #2
0
 def test_close_cart(self):
     with f.app_context():
         cart.my_cart = None
         cart.create()
         cart.add_to_cart('French hen')
         cart.close_cart()
         assert cart.my_cart is None
예제 #3
0
    def test_remove_unknown_item(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            with pytest.raises(NotFound):
                cart.remove_from_cart('Noisy crow')
예제 #4
0
 def test_close_unopened_cart(self):
     with f.app_context():
         cart.my_cart = None
         with pytest.raises(NotAcceptable):
             cart.close_cart()
         cart.create()
         assert cart.my_cart is not None
예제 #5
0
    def test_create_cart_for_user(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()
            assert cart.my_cart is not None

            with pytest.raises(NotAcceptable):
                cart.create()
예제 #6
0
    def test_checkout_cart(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            cart.add_to_cart('Turtle dove')
            cart.add_to_cart('French hen')
            cart.checkout_cart()
            assert cart.my_cart is None
예제 #7
0
    def test_remove_item_not_in_cart(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            cart.add_to_cart('Turtle dove')
            cart.remove_from_cart('Turtle dove')
            with pytest.raises(NotAcceptable):
                cart.remove_from_cart('Turtle dove')
            with pytest.raises(NotAcceptable):
                cart.remove_from_cart('Chachalaca')
예제 #8
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()
예제 #9
0
    def test_add(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()
            cart.add_to_cart('French hen')
            cart.add_to_cart('French hen')
            cart.add_to_cart('Turtle dove')
            assert cart.my_cart.items == [
                {'product': HEN, 'quantity': 2},
                {'product': DOVE, 'quantity': 1}
            ]

            cart.add_to_cart('French hen')
            with pytest.raises(NotAcceptable):
                cart.add_to_cart('French hen')
예제 #10
0
 def test_view_cart(self):
     with f.app_context():
         cart.my_cart = None
         cart.create()
         assert cart.view_cart() == {
             'total': Decimal('0'),
             'items': []
         }
         cart.add_to_cart('Turtle dove')
         cart.add_to_cart('Turtle dove')
         cart.add_to_cart('French hen')
         assert cart.view_cart() == {
             'total': Decimal('34.67'),
             'items': [
                 {'product': DOVE, 'quantity': 2},
                 {'product': HEN, 'quantity': 1}
             ]
         }
예제 #11
0
    def test_remove_items(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            cart.add_to_cart('Turtle dove')
            cart.add_to_cart('Turtle dove')
            cart.add_to_cart('French hen')
            cart.remove_from_cart('Turtle dove')
            cartstruct = cart.view_cart()
            assert cartstruct['total'] == Decimal('22.42')
            assert cartstruct['items'] == [
                {'product': DOVE, 'quantity': 1},
                {'product': HEN, 'quantity': 1}
            ]

            cart.remove_from_cart('Turtle dove')
            cart.remove_from_cart('French hen')
            cartstruct = cart.view_cart()
            assert cartstruct['total'] == Decimal('0')
            assert cartstruct['items'] == []