コード例 #1
0
def test_shopping_list_add_smartphones(smartphones):
    shopping_list = ShoppingList()
    size = 0
    for smartphone in smartphones:
        shopping_list.add_smartphone(smartphone)
        size += 1
        assert shopping_list.items() == size
        assert shopping_list.item(size - 1) == smartphone
コード例 #2
0
def test_shopping_list_add_computers(computers):
    shopping_list = ShoppingList()
    size = 0
    for computer in computers:
        shopping_list.add_computer(computer)
        size += 1
        assert shopping_list.items() == size
        assert shopping_list.item(size - 1) == computer
コード例 #3
0
def test_shopping_list_no_smartphone_duplicates():
    shopping_list = ShoppingList()
    shopping_list.add_smartphone(
        Smartphone(Name('Velvet'), Manufacturer('LG'), Price.create(100),
                   Quantity(1), Description("")))
    with pytest.raises(ValueError):
        shopping_list.add_smartphone(
            Smartphone(Name('Velvet'), Manufacturer('LG'), Price.create(100),
                       Quantity(4), Description("")))
コード例 #4
0
def test_shopping_list_no_computer_duplicates():
    shopping_list = ShoppingList()
    shopping_list.add_computer(
        Computer(Name('Haorus'), Manufacturer('Gigabyte'), Price.create(100),
                 Quantity(1), Description("")))
    with pytest.raises(ValueError):
        shopping_list.add_computer(
            Computer(Name('Haorus'), Manufacturer('Gigabyte'),
                     Price.create(100), Quantity(4), Description("")))
コード例 #5
0
def test_shopping_list_max_cardinality(computers, smartphones):
    shopping_list = ShoppingList()
    for computer in computers:
        shopping_list.add_computer(computer)
    for smartphone in smartphones:
        shopping_list.add_smartphone(smartphone)
    with pytest.raises(ValidationError):
        shopping_list.add_computer(
            Computer(Name('Omen'), Manufacturer('HP'), Price.create(100),
                     Quantity(1), Description("")))
コード例 #6
0
def test_shopping_list_change_quantity(smartphones):
    shopping = ShoppingList()
    shopping.add_smartphone(smartphones[0])
    shopping.change_quantity(0, Quantity(1))

    with pytest.raises(ValidationError):
        shopping.change_quantity(-1, Quantity(1))
    with pytest.raises(ValidationError):
        shopping.change_quantity(shopping.items(), Quantity(1))

    assert shopping.item(0).quantity.value == 1
コード例 #7
0
def test_shopping_list_remove_item(smartphones, computers):
    shopping = ShoppingList()
    for computer in computers:
        shopping.add_computer(computer)
    for smartphone in smartphones:
        shopping.add_smartphone(smartphone)

    shopping.remove_item(0)
    assert shopping.item(0) == computers[1]

    with pytest.raises(ValidationError):
        shopping.remove_item(-1)
    with pytest.raises(ValidationError):
        shopping.remove_item(shopping.items())

    while shopping.items():
        shopping.remove_item(0)
    assert shopping.items() == 0
コード例 #8
0
 def __init__(self):
     self.__first_menu = self.init_first_menu()
     self.__menu = self.__init_shopping_list_menu()
     self.__shoppinglist = ShoppingList()
コード例 #9
0
def test_shopping_list_sort_by_price(smartphones, computers):
    shopping = ShoppingList()
    shopping.add_computer(computers[0])
    shopping.add_smartphone(smartphones[0])
    shopping.sort_by_price()
    assert shopping.item(0) == smartphones[0]