Ejemplo n.º 1
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"
Ejemplo n.º 2
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"
Ejemplo n.º 3
0
def test_add_item():
    cart = ShoppingCart()
    cart.add_item('apple', 1)

    receipt = cart.print_receipt()

    assert receipt[0] == 'apple - 1 - €1.00'
Ejemplo n.º 4
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'
Ejemplo n.º 5
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"
Ejemplo n.º 6
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"
Ejemplo 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)))
Ejemplo n.º 8
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"
Ejemplo n.º 9
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")))
Ejemplo n.º 10
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)
Ejemplo n.º 11
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")))
Ejemplo n.º 12
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"
Ejemplo n.º 13
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"
Ejemplo n.º 14
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"
Ejemplo n.º 15
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)))
Ejemplo n.º 16
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)))
Ejemplo n.º 17
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"
Ejemplo n.º 18
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"
Ejemplo n.º 19
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
Ejemplo n.º 20
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)))
Ejemplo n.º 21
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)))
Ejemplo n.º 22
0
    def test_add_incorrect_product_code(self):
        cart = ShoppingCart(prices_json_path)
        cart.add_item("orangeX",2)
        cart.add_item("banana", 1)
        cart.add_item("pineapple", 3)
        cart.add_item("kiwi", 1)
        receipt = cart.print_receipt()

        self.assertEqual(receipt[0],"banana - 1 - €1.10 - $%.2f - £%.2f" % (cart.get_price_in_currency(1.10, "USD"), cart.get_price_in_currency(1.10, "GBP")))
        self.assertEqual(receipt[1],"pineapple - 3 - €3.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(3.00, "USD"), cart.get_price_in_currency(3.00, "GBP")))
        self.assertEqual(receipt[2],"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[3],"Total = €7.10 - $%.2f - £%.2f" % (cart.get_price_in_currency(7.10, "USD"), cart.get_price_in_currency(7.10, "GBP")))
Ejemplo n.º 23
0
def test_add_same_item_multiple_times():
    cart = ShoppingCart()
    cart.add_item("banana", 1)
    cart.add_item("kiwi", 1)
    cart.add_item("banana", 1)
    cart.add_item("kiwi", 1)
    cart.add_item("banana", 1)
    cart.add_item("kiwi", 1)

    receipt = cart.print_receipt()

    assert receipt[0] == "banana - 3 - €3.30"
    assert receipt[1] == "kiwi - 3 - €9.00"
Ejemplo n.º 24
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
Ejemplo n.º 25
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)))
Ejemplo n.º 26
0
def test_add_different_items():
    cart = ShoppingCart(PriceStoreCode())
    cart.add_item("banana", 1)
    cart.add_item("pear", 1)
    cart.add_item("kiwi", 1)
    cart.add_item("orange", 1)
    cart.add_item("apple", 1)
    cart.add_item("apple", 1)

    receipt = cart.print_receipt()

    assert receipt[0] == "banana - 1 - €1.10"
    assert receipt[1] == "pear - 1 - €2.00"
    assert receipt[2] == "kiwi - 1 - €3.00"
    assert receipt[3] == "orange - 1 - €1.50"
    assert receipt[4] == "apple - 2 - €2.00"
    assert receipt[5] == "Total - €9.60"
Ejemplo n.º 27
0
 def test_add_item(self):
     cart = ShoppingCart(prices_json_path)
     cart.add_item("apple", 1)
     receipt = cart.print_receipt()
     self.assertEqual(receipt[0],"apple - 1 - €1.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(1.00, "USD"), cart.get_price_in_currency(1.00, "GBP")))
Ejemplo n.º 28
0
def test_total_price():
    cart = ShoppingCart()
    cart.add_item("apple", 1)

    receipt = cart.print_receipt()
    assert receipt[1] == "Total Price = €1.00"
Ejemplo n.º 29
0
    def test_add_item_with_multiple_quantity(self):
        cart = ShoppingCart(prices_json_path)
        cart.add_item("apple", 2)

        receipt = cart.print_receipt()
        self.assertEqual(receipt[0],"apple - 2 - €2.00 - $%.2f - £%.2f" % (cart.get_price_in_currency(2.00, "USD"), cart.get_price_in_currency(2.00, "GBP")))
Ejemplo n.º 30
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"