Esempio n. 1
0
    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")
Esempio n. 2
0
    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)
Esempio n. 3
0
    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")
Esempio n. 4
0
    def test_should_not_update_given_invalid_data(self):
        customer_request = CustomerRequest(self.customer)
        url = url_for('customer.update', id=self.customer.id)
        customer_data = dict(name="",
                             email="*****@*****.**",
                             phone="123 456 7890",
                             address="Test address")
        with self.request_context(url, customer_data):
            customer_request.update()
        self.db.session.rollback()

        self.assertEqual(self.customer.name, "Test")
Esempio n. 5
0
    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, "")