class CustomerRequestTest(MyTest): def setUp(self): MyTest.setUp(self) self.customer = Customer(name="Test", email="*****@*****.**", phone="123 456 7890", address="Test address") self.customer.add()
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")
class QuoteRequestTest(MyTest): 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()
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)