def setUp(self): CustomerRequestTest.setUp(self) self.customer2 = Customer(name="Test two", email="*****@*****.**", phone="222 456 7890", address="Test address 2") self.customer2.add()
def setUp(self): MyTest.setUp(self) self.customer = Customer(name="Test", email="*****@*****.**", phone="123 456 7890", address="Test address") self.customer.add()
def setUp(self): CustomerValidationTest.setUp(self) self.customer2 = Customer( name="Test two", email="*****@*****.**", phone="321 654 0987", address="Test address two" ) self.customer2.add()
def search_for_customer(form): for key in customer_heads: customer = Customer.search(form[key]) if customer: return customer return None
def customers(): customers = Customer.get_all() autocomplete_data = [customer.name for customer in customers] placeholder = "Escribe el nombre o el email del cliente que buscas..." if request.method == "POST": search_term = request.form["search_term"] customer = Customer.search(search_term) if customer: return redirect(url_for('customer.profile', id=customer.id)) else: flash("No se encontró ningún cliente") return render_template('customer/customers.html', customers=customers, heads=customer_heads, autocomplete_data=autocomplete_data, placeholder=placeholder)
class TestUpdateAttributes(CustomerRequestTest): def setUp(self): CustomerRequestTest.setUp(self) self.customer2 = Customer(name="Test two", email="*****@*****.**", phone="222 456 7890", address="Test address 2") self.customer2.add() def test_should_update_attributes_given_valid_data(self): customer_request = CustomerRequest(self.customer2) url = url_for('customer.update', id=self.customer2.id) customer_data = dict(name="New Name", email="*****@*****.**", phone="222 456 7890", address="Test address 2") with self.request_context(url, customer_data): customer_request.update_attributes() self.assertEqual(self.customer2.name, "New Name") def test_should_update_attributes_given_invalid_data(self): customer_request = CustomerRequest(self.customer2) url = url_for('customer.update', id=self.customer2.id) customer_data = dict(name="Test", email="test.email.com", phone="invalid phone", address="") with self.request_context(url, customer_data): customer_request.update_attributes() self.assertEqual(self.customer.name, "Test") self.assertEqual(self.customer2.email, "test.email.com") self.assertEqual(self.customer2.phone, "invalid phone") self.assertEqual(self.customer2.address, "") def test_should_not_save_changes_given_any_data(self): customer_request = CustomerRequest(self.customer2) url = url_for('customer.update', id=self.customer2.id) customer_data = dict(name="New Name") with self.request_context(url, customer_data): customer_request.update_attributes() self.db.session.rollback() self.assertEqual(self.customer2.name, "Test two")
def setUp(self): MyTest.setUp(self) self.quote = Quote.new(1) self.customer = Customer( name="Test", email="*****@*****.**", phone="123 456 7890", address="Test address" ) self.customer.add() self.product = Product( quote_id=1, name="Test", material="Material", acabado="Acabado", cristal="Cristal" ) self.product.add()
def __init__(self): self.customers = Customer.get_all() self.heads = customer_heads self.data = self.get_empty_data() self.add_data() self.names = self.data["name"] self.emails = self.data["email"] self.phones = self.data["phone"] self.addresses = self.data["address"]
def test_should_not_add_customer_given_invalid_customer(self): customer = Customer(name="", email="*****@*****.**", phone="123 456 7890", address="Test address") customer_request = CustomerRequest(customer) customer_request.add() self.db.session.rollback() self.assertNotIn(customer, self.db.session)
def test_should_return_error_given_repeated_values(self): customer = Customer( name="Test", email="*****@*****.**", phone="123 456 7891", address="Test address" ) customer_validation = CustomerValidation(customer) error = customer_validation.check_for_repeated_values() self.assertNotEqual(error, None)
def sidebar(): search_term = request.args["sidebar-search-term"] customer = Customer.search(search_term) if customer: return redirect( url_for('customer.profile', id=customer.id) ) return redirect( session['prev_uri'] )
def test_should_not_return_error_given_new_values(self): customer = Customer( name="Test two", email="*****@*****.**", phone="222 4444 7777", address="Test address two" ) customer_validation = CustomerValidation(customer) error = customer_validation.check_for_repeated_values() self.assertEqual(error, None)
def update(id): customer = Customer.get(id) if request.method == "POST": error = customer.request.update() if not error: return redirect(url_for('customer.customers')) flash(error) return render_template('customer/update.html', heads=customer_heads, customer=customer)
class TestCheckForRepeatedValue(CustomerValidationTest): def setUp(self): CustomerValidationTest.setUp(self) self.customer2 = Customer( name="Test two", email="*****@*****.**", phone="321 654 0987", address="Test address two" ) self.customer2.add() def test_should_not_return_error_given_not_repeated_value(self): customer_validation = CustomerValidation(self.customer2) error = customer_validation.check_for_repeated_value("Test two") self.assertEqual(error, None) def test_should_return_error_given_repeated_value(self): customer_validation = CustomerValidation(self.customer2) error = customer_validation.check_for_repeated_value("Test") self.assertNotEqual(error, None)
def add(): form = get_form(customer_heads) if request.method == 'POST': form = get_form(customer_heads) customer = Customer(name=form['name'], email=form['email'], phone=form['phone'], address=form['address']) error = customer.request.add() if not error: return redirect(url_for('customer.customers')) flash(error) return render_template('customer/add.html', heads=customer_heads, form=form)
def add(): form = get_form(customer_heads) if request.method == "POST": error = None customer = search_for_customer(form) if not customer: customer = Customer(name=form['name'], email=form['email'], phone=form['phone'], address=form['address']) error = customer.request.add() if not error: quote = Quote.new(customer.id) return redirect(url_for('quote.edit', id=quote.id)) flash(error) return render_template( 'quote/add.html', form=form, customer_heads=customer_heads, customer_placeholders=customer_placeholders, )
def delete(id): customer = Customer.get(id) customer.delete() return redirect(url_for('customer.customers'))
def profile(id): customer = Customer.get(id) return render_template('customer/profile.html', customer=customer)