def test_basic_checkout__should_total_half_pound_beef_and_half_pound_cheese( self): beef = Product('beef', 5.99, .5) cheese = Product('cheese', 2.38, .5) self.cart.products = [beef, cheese] actual = self.cart.basic_checkout() assert actual == 4.19
def hello_world(): product = Product(name="product_1") category = Category(name="category_1", description='description') product.categories = [category] session.add(product) session.commit() return 'Hello, World!'
def create(self, data): try: product_price = data['price'] data.pop("price", None) product = Product(**data) db.session.add(product) price_data = { "price": product_price, "product_id": data['source_product_id'] } price = Price(**price_data) db.session.add(price) db.session.commit() return self.__make_response(201, True, 'created', {"id": product.id}) except Exception as err: db.session.rollback() return self.__make_response(500, False, str(err))
class TestProduct: def setup_method(self): self.soup = Product('soup', 1.89) self.beef = Product('beef', 5.99, .75) def test_calculate_product_cost__should_return_cost_based_on_standard_price_and_weight( self): actual = self.beef.calculate_product_cost() assert actual == 4.49
def delete_product(cls): print("-------- delete product --------") _id = input("please enter product_id for delete: ") if not _id: print("you forget enter id") elif Product.delete(_id): print(f"product with id {_id} deleted successfully ") else: print(f"product with id {_id} not found")
def insert_product(product): with session_scope() as db: category = get_category_by_id(product.category_id) p = Product(category_id=category.id, name=product.name, amount=product.amount, price=product.price) db.add(p) return f"{p.name} inserted with success" pass
def setup_method(self): self.store = Store() self.cart = Cart() self.soup = Product('soup', 1.89) self.soup.has_special = True self.soup.special_details = { 'specialType': 'basic unit discount', 'perUnitDiscount': 0.20, 'limit': 5 } self.soda = Product('soda', 1.49) self.soda.has_special = True self.soda.special_details = { 'specialType': 'buy some get some', 'buyAmount': 2, 'getAmount': 1, 'percentOff': 100, 'limit': 2 } self.soap = Product('soap', 2.49) self.soap.has_special = True self.soap.special_details = { 'specialType': 'buy some for amount', 'buyAmount': 3, 'dollarAmount': 5, 'limit': 2 } self.beef = Product('beef', 5.99, 1) self.cheese = Product('cheese', 2.38, 1) self.store.products = [ self.soup, self.soda, self.soap, self.beef, self.cheese ] self.soups = [self.soup, self.soup, self.soup, self.soup, self.soup] self.sodas = [ self.soda, self.soda, self.soda, self.soda, self.soda, self.soda ] self.soaps = [self.soap, self.soap, self.soap, self.soap] self.beefs = [self.beef] self.cheeses = [self.cheese, self.cheese] self.cart.products = self.soups + self.sodas + self.soaps + self.beefs + self.cheeses self.cart.standard_items = self.cheeses + self.beefs self.cart.special_items = self.soups + self.sodas + self.soaps
def product(uid): rows = db.execute_query( "SELECT * FROM Product WHERE id = " + str(uid) + ";" ) try: row = rows.pop(0) product = Product(row[0], row[1], row[2], row[3], row[4]) return render_template('product.html', product=product) except Exception as e: return "ERROR: " + str(e)
def add_product(cls): print("-------- add product --------") name = input("product_name: ") price = input("price: ") category = input("category: ") off = input("off: ") if not name or not price or not category or not off: print("you forget enter something") elif Product().save(name, price, category, off): print(f"product {name} add successfully") else: print(f"category {category} not exist " \ f"please first add category {category}")
def show_all_products(cls): print(Product.get_products_db()) # Category().save("cloths") # print(Category.get_all_category()) # Product().save("shoes", 200000, "cloths", 23) # Product().save("dress", 200000, "cloths", 23) # print(Product.get_products_db()) # ProductView.delete_product() # print(Product.get_products_db()) # ProductView.update_product() # print(Product.get_products_db())
def test_instantiation(self): name = "debt collection" year = 2019 product_id = str(year) + name product = Product(name, year) product.complaints += 1 product.complaints += 1 product.complaints += 1 self.assertEqual(name, product.name) self.assertEqual(year, product.year) self.assertEqual(product_id, product.product_id) self.assertEqual(3, product.complaints)
def update_product(cls): print("-------- update product --------") _id = input("please enter Product_id for update: ") if not _id: print("without product_id you couldn't update!") else: name = input("Enter new_name for update: ") price = input("Enter new_price for update: ") off = input("enter new_off for update: ") category = input("Enter new_category for update: ") result, msg = Product.update(_id, name, price, category, off) if result: print(f"product with id {_id} update successfully") else: print(msg)
def test_number_of_reported_companies(self): name = "credit reporting, credit repair services, or other personal consumer reports" year = 2020 product_id = str(year) + name product = Product(name, year) self.assertEqual(product_id, product.product_id) companies = ["acme", "acme", "transunion", "experian", "transunion"] for company in companies: product.reported_companies.add(company) self.assertEqual(3, len(product.reported_companies)) self.assertIn("acme", product.reported_companies) self.assertIn("transunion", product.reported_companies) self.assertIn("experian", product.reported_companies)
def products(): keyword = request.args.get('search', '') keyword = keyword.strip() rows = db.execute_query( "SELECT * FROM Product WHERE lower(name) LIKE lower('%" + keyword + "%') ORDER BY lower(name);" ) products = [] try: for row in rows: product = Product(row[0], row[1], row[2], row[3], row[4]) products.append(product) except Exception as e: return "ERROR: " + str(e) count = len(products) if keyword else None return render_template('index.html', products=products, count=count, keyword=keyword)
def get_product_by_product_id(id: int, item_amount): with session_scope() as db: product = db.query(Product).filter( and_(Product.id == id, Product.amount >= item_amount)).first() if product: return Product(id=product.id, category_id=product.category_id, name=product.name, amount=product.amount, price=product.price) return None # def sum_all_itens_cart(item, cart, product): # with session_scope() as db: # total = product.price * item.amount # item_cart = ItemCart(product_id=item.id, cart_id=cart.id, value=product.value, # amount=item.amount, total=total) # # somar os totais dos itens e dar um update no cart # cart = Cart(id=cart.id, user_id=cart.user_id, total=) # # db.add(p) # return, # pass
def process_csv_input(input_path): year_and_product_dict = {} with open(input_path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=",") for idx, row in enumerate(csv_reader): if idx == 0: continue year = utils.get_year(row[0], idx) name = row[1].lower() product_id = str(year) + name if product_id in year_and_product_dict: product = year_and_product_dict[product_id] else: product = Product(name, year, product_id) year_and_product_dict[product.product_id] = product company = row[7].lower() product.reported_companies.add(company) product.complaints += 1 product.companies.add_company_complaint(company) return year_and_product_dict
def show(cls): print("---------- Welcome ----------") for num, title in cls.menu.items(): if num in ("5", "9", "13", "17", "0"): print("************************") print(f"{num}: {title}") print("*****************************") user_input = input("Enter your number:") while True: if user_input == "1": name = input("name: ") price = int(input("price: ")) category = input("category: ") off = float(input("off: ")) result, err = Product.save(name, price, category, off) if result: print("Successfully add product") else: print(err) if user_input == "2": print(Product.get_all_products()) if user_input == "3": products_fields = [ "id", "name", "price", "category_name", "off" ] _id, name, price, category_name, off = [ input(f"{field}:") for field in products_fields ] print(_id, name, price, category_name, off) result = Product.update(_id, name, price, category_name, off) if result: print("Successfully update product") else: print("Update err") if user_input == "4": result, err = Product.delete(input("id: ")) if result: print("Successfully delete") else: print(err) if user_input == "5": CategoryView.add_category() if user_input == "6": CategoryView.show_all() if user_input == "7": a, b = CategoryView.update_category() print(a, b) if user_input == "8": CategoryView.delete_category() if user_input == "9": RegisterView.create_customer() if user_input == "10": RegisterView.create_employee() if user_input == "16": LoginLogoutView.login() user_input = input("Enter your number:")
def create_product(product): item = product.strip().split(',') return Product(item[0], float(item[1]), int(item[2]))
def setup_method(self): self.soup = Product('soup', 1.89) self.beef = Product('beef', 5.99, .75)
def test_description_too_large(self): with pytest.raises(ValueError): product = Product("name", "b"*600, 10.3)
def my_product(self): product = Product("nome valido", "description valida", 10.32) return product
def test_price_must_be_float(self, price): with pytest.raises(TypeError) as e: product = Product("name ", "description", price)
def test_description_must_be_string(self, description): with pytest.raises(TypeError) as e: product = Product("name ", description, 10)
def test_name_must_be_string(self, name): with pytest.raises(TypeError) as e: product = Product(name, "description", 10)
def insert_data(cnx): """insert data in the database.""" fake = Faker("fr_FR") now = datetime.datetime(2020, 7, 14, 11, 55, 00) Faker.seed(123456) random.seed(123456) print( "\n\n", " Insertion du jeu de données en base ".center(100, "#"), "\n\n", ) # restaurant restaurants = RESTAURANT restaurant_mng = RestaurantManager(cnx) for restaurant in restaurants: restaurant_data = { "restaurant_name": restaurant, "phone_number": fake.pystr_format(string_format="##-##-##-##-##"), "address1": fake.street_address(), "address2": fake.pystr(min_chars=0, max_chars=20), "add_info": fake.pystr_format(string_format="##?##"), "city_name": fake.city(), "zip_code": fake.postcode(), } restaurant_obj = Restaurant(restaurant_data) restaurant_mng.create(restaurant_obj) # Add Lola as Founder founder_data = { "first_name": "Lola", "last_name": "Dupont", "phone_number": "00-00-00-00-00", "email": "*****@*****.**", "password": pbkdf2_sha256.hash( fake.pystr(min_chars=6, max_chars=20) ), "job_name": "Founder", "restaurant_name": restaurant, } founder_obj = Employee(founder_data) founder_mng = EmployeeManager(cnx) founder_mng.create(founder_obj) # employee staff = STAFF employee_mng = EmployeeManager(cnx) for employee_job in staff: employee_first_name = fake.first_name() employee_last_name = fake.last_name() employee_data = { "first_name": employee_first_name, "last_name": employee_last_name, "phone_number": fake.pystr_format( string_format="##-##-##-##-##" ), "email": f"{employee_first_name}.{employee_last_name}@OC-Pizza.com", # noqa: E501 "password": pbkdf2_sha256.hash( fake.pystr(min_chars=6, max_chars=20) ), "job_name": employee_job, "restaurant_name": restaurant, } employee_obj = Employee(employee_data) employee_mng.create(employee_obj) # customer customer_mng = CustomerManager(cnx) restau_custom_mng = RestaurantCustomerManager(cnx) for index in range(50): customer_first_name = fake.first_name() customer_last_name = fake.last_name() customer_data = { "first_name": customer_first_name, "last_name": customer_last_name, "phone_number": fake.pystr_format(string_format="##-##-##-##-##"), "email": f"{customer_first_name}.{customer_last_name}@gmail.com", "password": pbkdf2_sha256.hash( fake.pystr(min_chars=6, max_chars=20) ), "birthdate": fake.date(), "address1": fake.street_address(), "address2": fake.pystr(min_chars=0, max_chars=20), "add_info": fake.pystr_format(string_format="##?##"), "city_name": fake.city(), "zip_code": fake.postcode(), } customer_obj = Customer(customer_data) customer_mng.create(customer_obj) restaurant_list = random.choices(RESTAURANT, k=random.randint(1, 8)) restau_custom_obj = RestaurantCustomer( customer_data.get("email"), restaurant_list ) restau_custom_mng.create(restau_custom_obj) # ingredient & stock ingredients = INGREDIENT ingredient_mng = IngredientManager(cnx) for restaurant in restaurants: for ingredient in ingredients: ingredient_data = { "ingredient_name": ingredient, "ingredient_stock": random.randint(0, 25), "ingredient_restaurant": restaurant, } ingredient_obj = Ingredient(ingredient_data) ingredient_mng.create(ingredient_obj) # product, vat, & category recipes = {} products = PRODUCT product_mng = ProductManager(cnx) for product in products: product_data = { "product_name": product, "vat_100": random.choice(VAT), "price_excluding_tax": random.randint(9, 20), "category": random.choice(CATEGORY), } recipe_data = [] recipe_data = [ (ingredient_recipe, random.randint(1, 3)) for ingredient_recipe in random.choices( INGREDIENT, k=(random.randint(1, 5)) ) ] recipes[product] = recipe_data product_obj = Product(product_data, recipe_data) product_mng.create(product_obj) # recipe recipe_mng = RecipeManager(cnx) for recipe_name, instruction in recipes.items(): recipe_obj = Recipe(instruction, recipe_name) recipe_mng.create(recipe_obj) # status status_mng = StatusManager(cnx) for status in STATUS: status_obj = Status(status) status_mng.create(status_obj) # order SQL_SELECT_CUSTOMER = "SELECT email FROM Customer;" cursor = cnx.cursor() cursor.execute(SQL_SELECT_CUSTOMER) customer_list = cursor.fetchall() order_mng = PurchaseOrderManager(cnx) order_prod_mng = OrderProductManager(cnx) for order in range(1, 101): order_payment_method = random.choice(PAYMENT_METHOD) order_status = random.choice(STATUS) order_restaurant = random.choice(RESTAURANT) order_customer = (random.choice(customer_list))[0] order_data = { "order_date": now.strftime("%Y/%m/%d %H:%M:%S"), "order_number": order, "order_payment_method": order_payment_method, "order_restaurant": order_restaurant, "order_customer": order_customer, "order_status": order_status, "order_mode": random.choice(["livraison", "sur place"]), } order_obj = PurchaseOrder(order_data) order_mng.create(order_obj) order_details = [] for product in random.sample(PRODUCT, k=random.randint(1, 10)): order_details.append((product, random.randint(1, 5))) order_prod_obj = OrderProduct(order, order_details) order_prod_mng.create(order_prod_obj) print( "\n", "> Insertion réalisée avec succès <".center(100, "-"), "\n", )
def setup_method(self): self.store = Store() self.soup = Product('soup', 1.89) self.beef = Product('beef', 5.99)