Exemplo n.º 1
0
def test_add_item():
    cart = ShoppingCart()
    cart.add_item('apple', 1)

    receipt = cart.print_receipt()

    assert receipt[0] == 'apple - 1 - €1.00'
Exemplo n.º 2
0
def test_add_item_with_multiple_quantity():
    cart = ShoppingCart()
    cart.add_item('apple', 2)

    receipt = cart.print_receipt()

    assert receipt[0] == 'apple - 2 - €2.00'
Exemplo n.º 3
0
    def test_get_price_in_currency_exception(self):
        cart = ShoppingCart(prices_json_path)
        result = cart.get_price_in_currency(2.00, "US")
        self.assertEqual(result,0)

#if __name__ == '__main__':
#    unittest.main()
Exemplo n.º 4
0
def test_add_item_with_multiple_quantity():
    cart = ShoppingCart()
    cart.add_item("apple", 2)
    receipt = cart.print_receipt()
    assert receipt[0]['item'] == "apple"
    assert receipt[0]['quantity'] == "2"
    assert receipt[0]['cost'] == "€2.20"
Exemplo n.º 5
0
def test_add_item():
    cart = ShoppingCart()
    cart.add_item("apple", 1)
    receipt = cart.print_receipt()
    assert receipt[0]['item'] == "apple"
    assert receipt[0]['quantity'] == "1"
    assert receipt[0]['cost'] == "€1.10"
Exemplo n.º 6
0
def test_cart_in_dollars():
    cart = ShoppingCart(PriceStoreCode(), FXDict(FX_RATES, FX_SYMBOLS), 'usd')
    cart.add_item("banana", 1)

    receipt = cart.print_receipt()
    assert receipt[0] == "banana - 1 - $1.33"
    assert receipt[1] == "Total - $1.33"
Exemplo n.º 7
0
    def add_item_with_multiple_quantity(self, reader: PriceReader):
        cart = ShoppingCart(reader)
        cart.add_item("a", 2)

        receipt = cart.print_receipt()

        self.assertEqual(receipt[0],"a - 2 - €2.00 - $%.2f - £%.2f" % (convert_wrapup(2.00, USDcurrency), convert_wrapup(2.00, GBPcurrency)))
        self.assertEqual(receipt[1],"Total: €2.00 - $%.2f - £%.2f" % (convert_wrapup(2.00, USDcurrency), convert_wrapup(2.00, GBPcurrency)))
Exemplo n.º 8
0
def test_currency():
    cart = ShoppingCart()
    r_dict=cart.display_product_list_in_currency('GBP')
    with open("products/products.json") as f:
        p_dict = json.load(f)
    ans1 = r_dict['apple']
    ans2 = get_amount_in_currency(p_dict['apple'], 'GBP')
    assert ans1 == ans2
Exemplo n.º 9
0
    def add_item(self, reader: PriceReader):
        
        cart = ShoppingCart(reader)
        cart.add_item("a", 1)

        receipt = cart.print_receipt()

        self.assertEqual(receipt[0],"a - 1 - €1.00 - $%.2f - £%.2f" % (convert_wrapup(1.00, USDcurrency), convert_wrapup(1.00, GBPcurrency)), "Erro in test_add_item()")
        self.assertEqual(receipt[1],"Total: €1.00 - $%.2f - £%.2f" % (convert_wrapup(1.00, USDcurrency), convert_wrapup(1.00, GBPcurrency)))
Exemplo n.º 10
0
    def add_same_item_multiple_times(self, reader: PriceReader):
        cart = ShoppingCart(reader)
        cart.add_item("a", 1)
        cart.add_item("a", 1) # add same item two times

        receipt = cart.print_receipt()

        self.assertEqual(receipt[0],"a - 2 - €2.00 - $%.2f - £%.2f" % (convert_wrapup(2.00, USDcurrency), convert_wrapup(2.00, GBPcurrency)))
        self.assertEqual(receipt[1],"Total: €2.00 - $%.2f - £%.2f" % (convert_wrapup(2.00, USDcurrency), convert_wrapup(2.00, GBPcurrency)))
Exemplo n.º 11
0
def test_set_product_source_to_database():
    os.environ["data_source"] = "DATABASE"
    reload(config)

    cart = ShoppingCart()
    cart.add_item("apple", 1)

    receipt = cart.print_receipt()

    assert receipt[0] == "apple - 1 - €1.00"
Exemplo n.º 12
0
    def test_add_incorrect_quantity_code(self):
        cart = ShoppingCart(prices_json_path)
        cart.add_item("pineapple", -3)
        cart.add_item("kiwi", 1)
        receipt = cart.print_receipt()

        self.assertEqual(receipt[0],"kiwi - 1 - €3.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(3.00, "USD"), cart.get_price_in_currency(3.00, "GBP")))
        self.assertEqual(receipt[1],"Total = €3.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(3.00, "USD"), cart.get_price_in_currency(3.00, "GBP")))
Exemplo n.º 13
0
def test_order():
    cart = ShoppingCart()
    cart.add_item("banana", 1)
    cart.add_item("kiwi", 1)
    cart.add_item("apple", 1)
    receipt = cart.print_receipt()
    assert receipt[0]['item'] == "banana"
    assert receipt[1]['item'] == "kiwi"
    assert receipt[2]['item'] == "apple"
Exemplo n.º 14
0
def test_print_receipt(capsys):
    cart = ShoppingCart()
    
    cart.add_item("banana", 1)

    receipt = cart.print_receipt()
    out, err = capsys.readouterr()
    sys.stdout.write(out)
    sys.stderr.write(err)
    assert out.split('\n')[0] == "-"*39
    assert out.split('\n')[1] == "|ITEM        | Quantity       | Price |"
    assert out.split('\n')[2] == "|banana      | 1              | €1.60 |"
    assert out.split('\n')[3] == "-"*39
    assert out.split('\n')[4] == "|Total Price:                    €1.60|"
    assert out.split('\n')[5] == "-"*39
Exemplo n.º 15
0
def test_total_price_with_multiple_currencies():
    cart = ShoppingCart()
    cart.add_item("apple", 1)
    cart.add_item("apple", 1)
    cart.add_item("banana", 2)
    receipt = cart.print_receipt_with_currencies()
    assert receipt[-1] == "Total Price = €4.20 / $4.58 / £3.86 / INR327.60"
Exemplo n.º 16
0
def test_check_total():
    cart = ShoppingCart()
    cart.add_item("banana", 1)
    cart.add_item("kiwi", 1)

    receipt = cart.print_receipt()

    assert receipt[-1] == "Total - €4.10"
Exemplo n.º 17
0
def test_set_cart_currency_to_gbp():
    cart = ShoppingCart()
    cart.add_item("apple", 1)

    receipt = cart.print_receipt()

    assert receipt[0] == "apple - 1 - €1.00"

    cart.modify_currency('GBP')
    receipt = cart.print_receipt()

    assert receipt[0] == "apple - 1 - £0.86"
Exemplo n.º 18
0
    def add_different_items(self, reader: PriceReader):
        cart = ShoppingCart(reader)
        cart.add_item("a", 1)
        cart.add_item("b", 2)
        cart.add_item("c", 1)
        cart.add_item("d", 5)
        cart.add_item("e", 3)

        receipt = cart.print_receipt()

        self.assertEqual(receipt[0],"a - 1 - €1.00 - $%.2f - £%.2f" % (convert_wrapup(1.00, USDcurrency), convert_wrapup(1.00, GBPcurrency)))
        self.assertEqual(receipt[1],"b - 2 - €2.20 - $%.2f - £%.2f" % (convert_wrapup(2.20, USDcurrency), convert_wrapup(2.20, GBPcurrency)))
        self.assertEqual(receipt[2],"c - 1 - €1.17 - $%.2f - £%.2f" % (convert_wrapup(1.17, USDcurrency), convert_wrapup(1.17, GBPcurrency)))
        self.assertEqual(receipt[3],"d - 5 - €11.15 - $%.2f - £%.2f" % (convert_wrapup(11.15, USDcurrency), convert_wrapup(11.15, GBPcurrency)))
        self.assertEqual(receipt[4],"e - 3 - €9.00 - $%.2f - £%.2f" % (convert_wrapup(9.00, USDcurrency), convert_wrapup(9.00, GBPcurrency)))
        self.assertEqual(receipt[5],"Total: €24.52 - $%.2f - £%.2f" % (convert_wrapup(24.52, USDcurrency), convert_wrapup(24.52, GBPcurrency)))
Exemplo n.º 19
0
    def test_add_same_item_twice_code(self):
        cart = ShoppingCart(prices_json_path)
        cart.add_item("pineapple", 1)
        cart.add_item("pineapple", 1)
        receipt = cart.print_receipt()
        #print(receipt)

        self.assertEqual(receipt[0],"pineapple - 2 - €2.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(2.00, "USD"), cart.get_price_in_currency(2.00, "GBP")))
        self.assertEqual(receipt[1],"Total = €2.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(2.00, "USD"), cart.get_price_in_currency(2.00, "GBP")))
Exemplo n.º 20
0
def test_add_multiple_items():
    cart = ShoppingCart()
    cart.add_item("apple", 2)
    cart.add_item("banana", 2)

    receipt = cart.print_receipt()

    assert receipt[0] == "apple - 2 - €2.00"
    assert receipt[1] == "banana - 2 - €2.20"
Exemplo n.º 21
0
def test_add_different_items():
    cart = ShoppingCart()
    cart.add_item("banana", 1)
    cart.add_item("kiwi", 1)

    receipt = cart.print_receipt()

    assert receipt[0] == "banana - 1 - €1.10"
    assert receipt[1] == "kiwi - 1 - €3.00"
Exemplo n.º 22
0
def test_add_different_items_Currency(curr):
    cart = ShoppingCart()
    cart.add_item('apple', 1)
    cart.add_item('kiwi', 1)

    receipt = cart.print_receipt(curr)

    print(receipt)
    """ assert receipt[0].startswith('apple -1 - %s' curr)
Exemplo n.º 23
0
def test_unknown_symbol():
    cart = ShoppingCart(PriceStoreCode(), FXDict(FX_RATES_CHF, FX_SYMBOLS),
                        'chf')
    cart.add_item("banana", 1)

    with pytest.raises(NoSuchCurrencyException):
        cart.print_receipt()
Exemplo n.º 24
0
def test_add_different_items():
    cart = ShoppingCart()
    cart.add_item('banana', 1)
    cart.add_item('kiwi', 1)

    receipt = cart.print_receipt()

    assert receipt[0] == 'banana - 1 - €1.10'
    assert receipt[1] == 'kiwi - 1 - €3.00'

    return receipt
Exemplo n.º 25
0
def test_add_different_items():
    cart = ShoppingCart()
    cart.add_item("apple", 1)
    cart.add_item("kiwi", 1)
    receipt = cart.print_receipt()
    assert receipt[0]['item'] == "apple"
    assert receipt[0]['quantity'] == "1"
    assert receipt[0]['cost'] == "€1.10"
    assert receipt[1]['item'] == "kiwi"
    assert receipt[1]['quantity'] == "1"
    assert receipt[1]['cost'] == "€1.30"
Exemplo n.º 26
0
def test_set_product_source_to_dict():
    os.environ["data_source"] = "DICT"
    reload(config)

    cart = ShoppingCart()
    cart.add_item("apple", 1)

    receipt = cart.print_receipt()

    assert receipt[0] == "apple - 1 - €1.00"

    cart.modify_currency('GBP')
    receipt = cart.print_receipt()

    assert receipt[0] == "apple - 1 - £0.86"
Exemplo n.º 27
0
    def add_invalid_items(self, reader: PriceReader):
        cart = ShoppingCart(reader)
        cart.add_item("a", 1)
        cart.add_item("b", 2)
        cart.add_item("x", 1) # add not defined item

        receipt = cart.print_receipt()

        print (receipt)
        self.assertEqual(receipt[0],"a - 1 - €1.00 - $%.2f - £%.2f" % (convert_wrapup(1.00, USDcurrency), convert_wrapup(1.00, GBPcurrency)))
        self.assertEqual(receipt[1],"b - 2 - €2.20 - $%.2f - £%.2f" % (convert_wrapup(2.20, USDcurrency), convert_wrapup(2.20, GBPcurrency)))
        self.assertEqual(receipt[2],"Total: €3.20 - $%.2f - £%.2f" % (convert_wrapup(3.20, USDcurrency), convert_wrapup(3.20, GBPcurrency)))
Exemplo n.º 28
0
    def add_items_with_negative_quantity(self, reader: PriceReader):
        cart = ShoppingCart(reader)
        cart.add_item("a", 1)
        cart.add_item("b", 2)
        cart.add_item("c", -2) # add negative quantity item

        receipt = cart.print_receipt()

        print (receipt)
        self.assertEqual(receipt[0],"a - 1 - €1.00 - $%.2f - £%.2f" % (convert_wrapup(1.00, USDcurrency), convert_wrapup(1.00, GBPcurrency)))
        self.assertEqual(receipt[1],"b - 2 - €2.20 - $%.2f - £%.2f" % (convert_wrapup(2.20, USDcurrency), convert_wrapup(2.20, GBPcurrency)))
        self.assertEqual(receipt[2],"Total: €3.20 - $%.2f - £%.2f" % (convert_wrapup(3.20, USDcurrency), convert_wrapup(3.20, GBPcurrency)))
Exemplo n.º 29
0
def test_add_item():
    cart = ShoppingCart()
    cart.add_item("apple", 1)
    cart.add_item("banana", 2)
    receipt = cart.print_receipt()
    assert receipt[0] == "apple - 1 - €1.00"
Exemplo n.º 30
0
def test_total_price():
    cart = ShoppingCart()
    cart.add_item("apple", 1)

    receipt = cart.print_receipt()
    assert receipt[1] == "Total Price = €1.00"