def setUp(self): WarehouseTest.setUp(self) self.create_test_users() self.product = Product(warehouse_id=self.warehouse.id, code="Test Product", description="Test Description", price=1) self.product.add()
def test_should_add_product(self): product = Product(warehouse_id=1, code="Some Code", description="Optional description", price=10) product.add() self.assertIn(product, self.db.session)
def test_should_not_return_error_given_product_already_in_database(self): product = Product(warehouse_id=1, code="Unique Code", description="Optional description", price=10) product.add() error = product.validation.validate_unique_values() self.assertEqual(error, None)
def setUp(self): Test.setUp(self) self.warehouse = Warehouse(name="Test Warehouse") self.warehouse.add() self.product = Product(warehouse_id=self.warehouse.id, code="Test Code", description="Optional description", price=10) self.product.add()
def setUp(self): Test.setUp(self) self.customer = Customer(customer_name="Test Name", address="Test Address", rfc="Test RFC") self.customer.add() self.product_1 = Product(warehouse_id=1, code="Code 1", price=10) self.product_1.add() self.product_2 = Product(warehouse_id=1, code="Code 2", price=10) self.product_2.add() self.receipt = Receipt(customer_id=self.customer.id) self.receipt.add()
def setUp(self): Test.setUp(self) self.product = Product( warehouse_id=1, code="Test Code", description="Optional description", price=10 ) self.product.add() self.finished_product = FinishedProduct( product_id=self.product.id, quantity=1, unit="pz" ) self.finished_product.add()
def test_should_return_error_given_empty_price(self): product = Product(code="Valid Code", description="Optional description", price="") error = product.validation.validate_empty_values() self.assertNotEqual(error, None)
def test_should_not_return_error_given_valid_nums(self): product = Product(code="Some Code", description="Optional description", price=10) error = product.validation.validate_nums() self.assertEqual(error, None)
def test_should_return_error_given_repeated_value(self): product = Product(code="Test Code", description="Optional description", price=10) error = product.validation.validate_unique_values() self.assertNotEqual(error, None)
def test_should_return_error_given_invalid_price(self): product = Product(code="Some Code", description="Optional description", price="invalid price") error = product.validation.validate() self.assertNotEqual(error, None)
def products(): products = Product.query.all() if request.method == "POST": product = Product.search(request.form['search_term']) if product: return redirect(url_for('product.update', id=product.id)) return render_template("product/products.html", product_heads=product_heads, products=products)
def test_should_not_add_product_given_invalid_product_data_and_LUHP(self): self.login_user(self.admin_user) product_data = dict(code="", description="Some description", price="invalid price") with self.client as client: client.post(url_for("product.add", warehouse_id=1), data=product_data) self.assertEqual(len(Product.get_all()), 1)
def update(id): product = Product.get(id) if request.method == "POST": update_obj_attrs(product, product_heads) error = product.request.update() if not error: return redirect( url_for('warehouse.inventory', id=product.warehouse_id)) flash(error) return render_template("product/update.html", product_heads=product_heads, product=product)
def add(warehouse_id): if request.method == "POST": product = Product(warehouse_id=warehouse_id, code=request.form["code"], description=request.form["description"], price=request.form["price"]) error = product.request.add() if not error: return redirect(url_for('warehouse.inventory', id=warehouse_id)) flash(error) return render_template("product/add.html", product_heads=product_heads, form=request.form)
def get_autocomplete_data(group, attribute): groups = dict( users=User.get_all(), products=Product.get_all(), customers = Customer.get_all(), expenses=Expense.get_all(), warehouses=Warehouse.get_all() ) data = [] for obj in groups[group]: value = getattr(obj, attribute) if value not in set(data): data.append(value) return data
def search_bar(): search_term = request.form['search_term'] try: customer = Customer.search_all(search_term)[0] except IndexError: customer = None if customer: return redirect( url_for("customer.update", id=customer.id) ) user = User.search(search_term) if user: return redirect( url_for("user.profile", id=user.id) ) product = Product.search(search_term) if product: return redirect( url_for("product.update", id=product.id) ) return redirect( request.referrer )
def test_should_add_product_given_valid_product(self): product = Product(warehouse_id=1, code="Test Code 2", price=10) product.request.add() self.assertIn(product, self.db.session)
def search_products(self): self.product = Product.search(self.search_term)
def delete(id): product = Product.get(id) warehouse_id = product.warehouse_id product.delete() return redirect(url_for('product.products', warehouse_id=warehouse_id))
def test_should_return_product_given_valid_id(self): product = Product.get(1) self.assertEqual(product, self.product)
def test_should_return_product_given_valid_code(self): product = Product.search('Test Code') self.assertEqual(product, self.product)
def test_should_return_none_given_invalid_id(self): product = Product.get(2) self.assertEqual(product, None)
def test_should_return_a_list_of_all_products(self): products = Product.get_all() self.assertEqual(products, [self.product])