def test_should_add_customer(self): customer = Customer(customer_name="Test Customer", address="Test dirección", rfc="Opcional RFC") customer.add() self.assertIn(customer, self.db.session)
class CustomerTest(Test): def setUp(self): Test.setUp(self) self.customer = Customer(customer_name="Test Name", address="Test Address", rfc="Test RFC") self.customer.add()
def customers(): customers = Customer.get_all() if request.method == "POST": customers = Customer.search_all(request.form["search_term"]) return render_template('customer/customers.html', customer_heads=customer_heads, customers=customers)
def setUp(self): CustomerTest.setUp(self) self.customer2 = Customer( customer_name="Name Two", address="Address Two", rfc="RFC Two" ) self.customer2.add()
def setUp(self): ReceiptTest.setUp(self) customer2 = Customer( customer_name="Name Two", address="Address Two", rfc="" ) customer2.add() self.create_test_users()
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 test_should_not_return_error_given_valid_phone(self): customer = Customer(customer_name="Test Name", address="Test Address", phone="+442 303 2121") error = customer.validation.validate_phone() self.assertEqual(error, None)
def test_should_not_return_error_given_unique_name(self): customer = Customer(customer_name="Unique Name", address="Test Address", rfc="TESTRFC 123") error = customer.validation.validate_unique_value("customer_name") self.assertEqual(error, None)
def test_should_return_error_given_empty_name(self): customer = Customer(customer_name="", address="Test Address", rfc="TESTRFC 123") error = customer.validation.validate_empty_values() self.assertNotEqual(error, None)
def test_should_not_return_error_given_empty_rfc(self): customer = Customer(customer_name="Test Name", address="Test Address", rfc="") error = customer.validation.validate_empty_values() self.assertEqual(error, None)
def test_should_return_error_given_repeated_rfc(self): customer = Customer(customer_name="Test Name", address="Test Address", rfc="Test RFC") error = customer.validation.validate_unique_values() self.assertNotEqual(error, None)
def test_should_return_error_given_invalid_phone(self): customer = Customer(customer_name="Test Name", address="Test Address", phone="invalid phone") error = customer.validation.validate_phone() self.assertNotEqual(error, None)
def test_should_not_return_error_given_valid_customer(self): customer = Customer(customer_name="Test Name", address="Test Address", rfc="Unique RFC") error = customer.validation.validate() self.assertEqual(error, None)
def test_should_add_customer_given_valid_customer(self): customer = Customer( customer_name="Valid Name", address="Valid Address", rfc="Valid RFC" ) customer.request.add() self.assertIn(customer, self.db.session)
def test_should_not_return_error_given_two_customers_with_empty_rfc(self): self.customer.rfc = "" self.customer.update() customer = Customer(customer_name="Valid Name", address="Valid Address", rfc="") error = customer.validation.validate_unique_values() self.assertEqual(error, None)
def test_should_add_customer_given_valid_customer_data_and_LUHP(self): self.login_user(self.admin_user) customer_data = dict(customer_name="Valid Name", address="Valid Address", phone="+123 456 7890", rfc="") with self.client as client: client.post(url_for('customer.add'), data=customer_data) self.assertEqual(len(Customer.get_all()), 2)
def test_should_not_return_error_given_two_customers_with_empty_name(self): self.customer.customer_name = "" self.customer.update() customer = Customer(customer_name="", address="Valid Address", rfc="Test RFC") error = customer.validation.validate_optional_unique_value( 'customer_name') self.assertEqual(error, None)
def update(id): customer = Customer.get(id) if request.method == "POST": update_obj_attrs(customer, customer_heads) error = customer.request.update() if not error: return redirect(url_for('customer.customers')) flash(error) return render_template('customer/update.html', customer_heads=customer_heads, customer=customer)
def receipts(id): selected_date_str = "" customer = Customer.get(id) receipts = customer.receipts if request.method == "POST": selected_date_str = request.form["selected_date"] selected_date = datetime.strptime(selected_date_str, "%Y-%m-%d") receipts = filter_receipts_by_date(receipts, selected_date) return render_template('customer/receipts.html', receipt_heads=receipt_heads, selected_date=selected_date_str, customer=customer, receipts=receipts)
class TestUpdate(CustomerTest): def setUp(self): CustomerTest.setUp(self) self.customer2 = Customer( customer_name="Name Two", address="Address Two", rfc="RFC Two" ) self.customer2.add() def test_should_update_customer_given_valid_change(self): self.customer.customer_name = "New Name" self.customer.request.update() self.db.session.rollback() self.assertEqual(self.customer.customer_name, "New Name") def test_should_not_update_customer_given_invalid_change(self): self.customer2.rfc = "Test RFC" self.customer2.request.update() self.db.session.rollback() self.assertNotEqual(self.customer2.rfc, "Test RFC")
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 add(): form = get_form(customer_heads) if request.method == 'POST': customer = Customer(customer_name=request.form['customer_name'], address=request.form['address'], phone=request.form['phone'], rfc=request.form['rfc']) error = customer.request.add() if not error: return redirect(url_for('customer.customers')) flash(error) return render_template('customer/add.html', customer_heads=customer_heads, form=form)
def test_should_add_receipt_and_new_customer_given_valid_customer_data_and_LUHP(self): self.login_user(self.admin_user) customer_data = dict( customer_name="Valid New Name", address="Valid Address", phone="+123 456 7890" ) prev_receipts = Receipt.get_all() with self.client as client: client.post( url_for('receipt.add'), data=customer_data ) self.assertNotEqual(len(Receipt.get_all()), len(prev_receipts)) self.assertEqual(len(Customer.search_all('Valid New Name')), 1)
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 delete(id): customer = Customer.get(id) customer.delete() return redirect(url_for('customer.customers'))
def test_should_return_customer_given_valid_id(self): customer = Customer.get(self.customer.id) self.assertEqual(customer, self.customer)
def test_should_return_none_given_invalid_id(self): customer = Customer.get(2) self.assertEqual(customer, None)
def test_should_return_list_of_all_customers(self): customers = Customer.get_all() self.assertEqual(customers, [self.customer])
def test_should_return_list_of_customers_given_valid_rfc(self): customers = Customer.search_all(self.customer.rfc) self.assertEqual(customers, [self.customer])
def test_should_return_empty_list_given_invalid_search_term(self): customer = Customer.search_all("invalid search term") self.assertEqual(customer, [])