~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/services/shop/cart/models/test_cart_item_creation.py -rw-r--r-- 698 bytes
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools.such import helper

from byceps.services.shop.cart.models import CartItem

from testfixtures.shop_article import create_article


def test_init_with_positive_quantity():
    quantity = 1

    item = create_item(quantity)

    assert item.quantity == quantity


def test_init_with_zero_quantity():
    with helper.assertRaises(ValueError):
        create_item(0)


def test_init_with_negative_quantity():
    with helper.assertRaises(ValueError):
        create_item(-1)


# helpers

def create_item(quantity):
    article = create_article()
    return CartItem(article, quantity)