def test_cart_subtotal_calculation(): cart = Cart() cart.add_to_cart(Listing(Jersey("Raptors KyleLowry Jersey", 39.99), 2)) cart.add_to_cart(Listing(Jersey("Celtics JaysenTatum Jersey", 29.99), 1)) cart.add_to_cart(Listing(Jersey("Lakers LeBronJames Jersey", 59.99), 7)) cart.add_to_cart(Listing(Jersey("Nuggets JamalMurray Jersey", 49.99), 5)) assert (cart.get_subtotal_cost() == ( 39.99 + 29.99 + 59.99 + 49.99)), "cart subtotal does not match entered items!"
def test_cart_tax_calculation(): cart = Cart() cart.add_to_cart(Listing(Jersey("Clippers KawhiLeonard Jersey", 39.99), 2)) cart.add_to_cart(Listing(Jersey("Heats JimmyButler Jersey", 29.99), 1)) cart.add_to_cart( Listing(Jersey("Bucks GiannisAntetokounmpo Jersey", 59.99), 7)) cart.add_to_cart(Listing(Jersey("Rockets JamesHarden Jersey", 49.99), 5)) assert (cart.get_tax_cost() == ( ((39.99 + 29.99 + 59.99 + 49.99) / 100) * 13)), "cart tax calculation does not match entered items!"
def test_cart_deletion(): cart = Cart() # adding items to cart for test data cart.add_to_cart(Listing(Jersey("Warriors StephCurry Jersey", 39.99), 2)) cart.add_to_cart(Listing(Jersey("Nets KyrieIrving Jersey", 29.99), 1)) cart.add_to_cart(Listing(Jersey("Knicks DennisSmithJr Jersey", 59.99), 7)) cart.add_to_cart(Listing(Jersey("Spurs DeMarDeRozan Jersey", 49.99), 5)) # pass item to be deleted to the function assert cart.delete_from_cart( Listing(Jersey("Spurs DeMarDeRozan Jersey", 49.99), 5)), "match not found, cannot delete!"
def test_cart_total_calculation(): cart = Cart() cart.add_to_cart(Listing(Jersey("Warriors StephCurry Jersey", 39.99), 2)) cart.add_to_cart(Listing(Jersey("Nets KyrieIrving Jersey", 29.99), 1)) cart.add_to_cart(Listing(Jersey("Knicks DennisSmithJr Jersey", 59.99), 7)) cart.add_to_cart(Listing(Jersey("Spurs DeMarDeRozan Jersey", 49.99), 5)) subtotal = (39.99 + 29.99 + 59.99 + 49.99) tax = (((39.99 + 29.99 + 59.99 + 49.99) / 100) * 13) assert cart.get_total_cost() == ( subtotal + tax), "cart subtotal does not match entered items!"
def cart_view(action, category_id=None, product_id=None): if session.get('logged_in') is True: cart = Cart(session['session_id']) if action == 'view': return render_template('cart.html', cart_items=cart.get_cart(), total_amount=cart.get_cart_total_price()) elif action == 'add': try: cart.add_to_cart(category_id, product_id) except Error as err: flash(err.message, 'danger') return redirect('/cart/view/') else: return redirect('/cart/view') elif action == 'remove': cart.remove_from_cart(category_id, product_id) return redirect('/cart/view') elif action == 'cancel': cart.cancel_cart() return redirect('/cart/view') else: flash("You are not logged in", 'danger') return redirect('/')
def Main(self): prod_1 = Product("Bananas", 1.89, 6) prod_2 = Product("Milk", 5.99, 2) prod_3 = Product("Bread", 2.89, 1) cart_1 = Cart(prod_1) cart_2 = Cart(prod_2) cart_3 = Cart(prod_3) cart_1.add_to_cart() cart_2.add_to_cart() cart_3.add_to_cart() cart_1.create_template() cart_2.create_template() cart_3.create_template()