def test_add_two_of_a_product(self): cart = ShoppingCart() product = Product('shoes', 'S', 'blue') cart.add_product(product, quantity=2) self.assertDictEqual({'SHOES-S-BLUE': {'quantity': 2}}, cart.products)
def test_add_two_products(self): cart = ShoppingCart() product1 = Product('shoes', 'S', 'blue') product2 = Product('tshirt', 'M', 'black') cart.add_product(product1) cart.add_product(product2) expected_cart_value = {'SHOES-S-BLUE':{'quantity': 1}, 'TSHIRT-M-BLACK':{'quantity':1}} self.assertDictEqual(expected_cart_value, cart.products)
def test_add_two_different_products(self): cart = ShoppingCart() product_one = Product('shoes', 'S', 'blue') product_two = Product('shirt', 'M', 'gray') cart.add_product(product_one) cart.add_product(product_two) self.assertDictEqual( { 'SHOES-S-BLUE': { 'quantity': 1 }, 'SHIRT-M-GRAY': { 'quantity': 1 } }, cart.products)
def test_add_and_remove_product(self): cart = ShoppingCart() product = Product('shoes', 'S', 'blue') cart.add_product(product) cart.remove_product(product) self.assertDictEqual({}, cart.products)
def test_remove_too_many_products(self): cart = ShoppingCart() product = Product('shoes', 'S', 'blue') cart.add_product(product) cart.remove_product(product, quantity=2) self.assertDictEqual({}, cart.products)
def test_add_and_remove_product(self): cart = ShoppingCart() # <2> product = Product('shoes', 'S', 'blue') # <3> cart.add_product(product) # <4> cart.remove_product(product) # <5> self.assertDictEqual({}, cart.products) # <6>
def add_to_cart(): if request.form: try: product = get_or_404(Product, request.form['product_id']) except KeyError: return redirect(request.referrer) shoppingcart = ShoppingCart.for_session_cart(request.cart) form = AddToCartForm(request.form, product=product, cart=shoppingcart) if form.validate(): flash('Added {0} {1} to the cart'.format( form.quantity.data, product.name)) form.save() return redirect(url_for('.index')) return redirect(request.referrer)
def test_add_and_remove_product(self): """ We can consider this an integration test as it tests a chain of functional units """ cart = ShoppingCart() product = Product('Cap', 'M', 'Orange') # these are two distinct actions cart.add_product(product) cart.remove_product(product) self.assertDictEqual({}, cart.products)
def new_cart(self): return ShoppingCart()
def test_add_remove(list_of_books): cart = ShoppingCart() for book in list_of_books: cart.add(book) cart.remove(book) assert cart.total == 0.00
def test_add(list_of_books): cart = ShoppingCart() for book in list_of_books: cart.add(book) total = sum(book.price for book in list_of_books) assert cart.total == total
def test_add_discount(example_book): cart = ShoppingCart() cart.add(example_book) cart.add_discount(COUPONS["10OFF"]) assert cart.total == 9.00
def test_add_remove(example_book): cart = ShoppingCart() cart.add(example_book) cart.remove(example_book) assert cart.total == 0.00
def test_cart_initially_empty(self): cart = ShoppingCart() self.assertDictEqual({}, cart.products)
def index(): shoppingcart = ShoppingCart.for_session_cart(request.cart) forms = [ReplaceCartLineForm(request.form, product=product, cart=shoppingcart, product_id=product.id_) for product in shoppingcart.items] return render_template('cart.html', cart=shoppingcart, forms=forms)
def test_remove_product_from_empty_cart(self): cart = ShoppingCart() product1 = Product('shoes', 'S', 'blue') cart.remove_product(product1) self.assertDictEqual({}, cart.products)
def test_add(example_book): cart = ShoppingCart() cart.add(example_book) assert cart.total == 10.00
engine = create_engine('sqlite:///user.db', echo=True) from sqlalchemy.sql import text app = Flask(__name__) photos = UploadSet('photos', IMAGES) app.config.from_object( 'config' ) # link config.py to this file(with all databse file paths, image upload paths) configure_uploads(app, photos) db = SQLAlchemy(app) bootstrap = Bootstrap(app) em_cart = ShoppingCart() em_cart.total = 0 @app.route('/') def home(): items = Retailer.query.all() w_items = Wholeseller.query.all() govt = Government.query.all() retailer_list = ['kiran', 'raju', 'mani', 'jayanthi', 'naresh'] best_retailer = random.choice(retailer_list) connection = engine.connect() s = text("SELECT SUM(price) FROM Retailer WHERE region=:r") total_revenue = 450 return render_template('pages/index.html', items=items,
MAIL_SERVER='smtp.googlemail.com', MAIL_PORT=465, MAIL_USE_TLS=False, MAIL_USE_SSL=True, MAIL_USERNAME='******', MAIL_PASSWORD='******', # administrator list ADMINS=['*****@*****.**', '*****@*****.**'])) configure_uploads(app, photos) db = SQLAlchemy(app) bootstrap = Bootstrap(app) mail = Mail(app) em_cart = ShoppingCart() # initializations em_cart.total = 0 order_placed = False @app.route('/') def home(): items = Retailer.query.all() w_items = Wholeseller.query.all() govt = Government.query.all() retailer_list = ['kiran', 'raju', 'mani', 'jayanthi', 'naresh'] best_retailer = random.choice(retailer_list) total_revenue = 450 return render_template('pages/index.html', items=items, govt=govt,