コード例 #1
0
ファイル: test_Stock.py プロジェクト: sumsar01/Store
def test_update_stock():
    stock1 = shop.Stock()
    stock2 = shop.Stock()
    mælk = shop.StockUnit("mælk", 2.50, "liter")
    kaffe = shop.StockUnit("kaffe", 15.00, "kg")
    stock1.add_item("123", mælk, 7.50, 100)
    stock2.add_item("255", kaffe, 59.95, 20)

    stock1.update_stock("123", 10)
    stock2.update_stock("255", 5)

    assert stock1.stock["123"][2] == 110
    assert stock2.stock["255"][2] == 25

    with pytest.raises(ValueError):
        stock1.update_stock("133", 10)
    with pytest.raises(ValueError):
        stock2.update_stock("275", 5) 

    with pytest.raises(TypeError):
        stock1.update_stock("123", "hej")
    with pytest.raises(TypeError):
        stock2.update_stock("255", [])   

    del stock1
    del stock2  
コード例 #2
0
ファイル: test_Stock.py プロジェクト: sumsar01/Store
def test_stock_information():
    stock1 = shop.Stock()
    stock2 = shop.Stock()
    mælk = shop.StockUnit("mælk", 2.50, "liter")
    kaffe = shop.StockUnit("kaffe", 15.00, "kg")
    stock1.add_item("123", mælk, 7.50, 100)
    stock2.add_item("255", kaffe, 59.95, 20)

    stock1.stock_information()
    stock2.stock_information()

    del stock1
    del stock2
コード例 #3
0
ファイル: test_Stock.py プロジェクト: sumsar01/Store
def test_get_item():
    stock1 = shop.Stock()
    stock2 = shop.Stock()
    mælk = shop.StockUnit("mælk", 2.50, "liter")
    kaffe = shop.StockUnit("kaffe", 15.00, "kg")
    stock1.add_item("123", mælk, 7.50, 100)
    stock2.add_item("255", kaffe, 59.95, 20)

    assert stock1.get_item("123") == mælk
    assert stock2.get_item("255") == kaffe

    with pytest.raises(ValueError):
        stock1.get_cost("133")
    with pytest.raises(ValueError):
        stock2.get_cost("275")

    del stock1
    del stock2
コード例 #4
0
ファイル: test_Stock.py プロジェクト: sumsar01/Store
def test_add_item():
    stock1 = shop.Stock()
    stock2 = shop.Stock()
    mælk = shop.StockUnit("mælk", 2.50, "liter")
    kaffe = shop.StockUnit("kaffe", 15.00, "kg")
    stock1.add_item("123", mælk, 7.50, 100)
    stock2.add_item("255", kaffe, 59.95, 20)

    assert stock1.stock == {"123" : [mælk, 7.50, 100]}
    assert stock2.stock == {"255" : [kaffe, 59.95, 20]}
    
    with pytest.raises(ValueError):
        stock1.add_item("123", mælk, 7.50, 100)
    with pytest.raises(ValueError):
        stock2.add_item("255", kaffe, 59.95, 20)
    
    del stock1
    del stock2
コード例 #5
0
ファイル: test_Reciept.py プロジェクト: sumsar01/Store
 def setUp(self):
     eggs = shop.StockUnit("Eggs", 18, "stk", "Expensive eggs")
     potatoes = shop.StockUnit("Potatoes", 10, "kg", "Danish potatoes")
     self.test_stock = shop.Stock()
     self.test_stock.add_item(1, eggs, 25, 50)
     self.test_stock.add_item(2, potatoes, 15, 30)
     id_q_list = [(1, 2), (2, 2)]
     self.test_receipt = shop.Receipt(id_q_list,
                                      self.test_stock,
                                      purchase_sale="s")
コード例 #6
0
def test_Sale():
    stock1 = shop.Stock()
    stock2 = shop.Stock()
    mælk = shop.StockUnit("mælk", 2.50, "liter")
    kaffe = shop.StockUnit("kaffe", 15.00, "kg")
    stock1.add_item("123", mælk, 7.50, 100)
    stock1.add_item("255", kaffe, 59.95, 20)
    stock2.add_item("255", kaffe, 59.95, 20)
    stock2.add_item("123", mælk, 7.50, 100)
    book1 = shop.Book("testBook1")
    account1 = shop.Account(2000)
    book2 = shop.Book("testBook2")
    account2 = shop.Account(2000)


    shop.Sale("123", 50, stock1, book1, account1)
    shop.Sale("255", 5, stock2, book2, account2)

    assert account1.get() == (2000 + 50*7.50)
    assert account2.get() == (2000 + 5*59.95)

    assert stock1.stock["123"][2] == 50
    assert stock2.stock["255"][2] == 15

    shop.Sale(["123", "255"] , [5, 2], stock1, book1, account1)
    assert account1.get() == (2000 + 50*7.50 + 5*7.50 + 2*59.95)
    assert stock1.stock["123"][2] == 45
    assert stock1.stock["255"][2] == 18

    shop.Sale(["255", "255"] , [5, 5], stock1, book1, account1)
    assert account1.get() == (2000 + 50*7.50 + 5*7.50 + 2*59.95 + 10*59.95)
    assert stock1.stock["255"][2] == 18-10

    shop.Sale(["255", "123"] , [10, 30], stock2, book2, account2)
    assert account2.get() == (2000 + 5*59.95 + 10*59.95 + 30*7.50)
    assert stock2.stock["123"][2] == 70
    assert stock2.stock["255"][2] == 5

    os.remove("testBook1_balance_history.csv")
    os.remove("testBook1_receipts.csv")
    os.remove("testBook2_balance_history.csv")
    os.remove("testBook2_receipts.csv")
コード例 #7
0
ファイル: test_Purchase.py プロジェクト: sumsar01/Store
def test_Purchase():
    stock1 = shop.Stock()
    stock2 = shop.Stock()
    mælk = shop.StockUnit("mælk", 2.50, "liter")
    kaffe = shop.StockUnit("kaffe", 15.00, "kg")
    stock1.add_item("123", mælk, 7.50, 100)
    stock1.add_item("255", kaffe, 59.95, 20)
    stock2.add_item("255", kaffe, 59.95, 20)
    stock2.add_item("123", mælk, 7.50, 100)
    book1 = shop.Book("testBook1")
    account1 = shop.Account(2000)
    book2 = shop.Book("testBook2")
    account2 = shop.Account(2000)

    shop.Purchase("123", 50, stock1, book1, account1)
    shop.Purchase("255", 5, stock2, book2, account2)

    assert account1.get() == (2000 - 50 * 2.50)
    assert account2.get() == (2000 - 5 * 15.00)

    assert stock1.stock["123"][2] == 150
    assert stock2.stock["255"][2] == 25

    shop.Purchase(["123", "255"], [5, 2], stock1, book1, account1)
    assert account1.get() == (2000 - 50 * 2.50 - 5 * 2.50 - 2 * 15.00)
    assert stock1.stock["123"][2] == 155
    assert stock1.stock["255"][2] == 22

    shop.Purchase(["255", "255"], [5, 5], stock1, book1, account1)
    assert account1.get() == (2000 - 50 * 2.50 - 5 * 2.50 - 2 * 15.00 -
                              10 * 15.00)
    assert stock1.stock["255"][2] == 22 + 10

    shop.Purchase(["255", "123"], [10, 30], stock2, book2, account2)
    assert account2.get() == (2000 - 5 * 15.00 - 10 * 15.00 - 30 * 2.50)
    assert stock2.stock["123"][2] == 130
    assert stock2.stock["255"][2] == 35

    os.remove("testBook1_balance_history.csv")
    os.remove("testBook1_receipts.csv")
    os.remove("testBook2_balance_history.csv")
    os.remove("testBook2_receipts.csv")
コード例 #8
0
ファイル: test_Book.py プロジェクト: sumsar01/Store
    def setUp(self):
        potatos = shop.StockUnit("potatos", 9, "kg", "Something...")
        eggs = shop.StockUnit("eggs", 10, "pieces", "something...")
        milk = shop.StockUnit("milk", 5, "l", "something...")
        self.test_stock = shop.Stock()
        self.test_stock.add_item(1, potatos, 12, 100)
        self.test_stock.add_item(2, eggs, 25, 100)
        self.test_stock.add_item(3, milk, 10, 100)

        self.test_book = shop.Book("testBook")
        self.test_receipt_sale1 = shop.Receipt([(1, 2), (2, 2), (3, 3)], self.test_stock)
        self.test_receipt_sale2 = shop.Receipt([(1, 4), (2, 3), (3, 2)], self.test_stock)
        self.test_receipt_purc1 = shop.Receipt([(1, 30), (2, 30), (3, 40)], self.test_stock, purchase_sale="p")
        self.test_receipt_purc2 = shop.Receipt([(1, 10), (2, 10), (3, 20)], self.test_stock, purchase_sale="p")

        self.test_book.add_receipt(self.test_receipt_sale1)
        self.test_book.add_receipt(self.test_receipt_sale2)
        self.test_book.add_receipt(self.test_receipt_purc1)
        self.test_book.add_receipt(self.test_receipt_purc2)

        self.test_book.print_todays_receipts()
コード例 #9
0
ファイル: test_Stock.py プロジェクト: sumsar01/Store
def empty_stock():
    return shop.Stock()