def test_full_integration(self):
        """Integrates all methods into one test"""
        basic_operations.add_customer('004', 'Joey', 'Smith',
                                      '123 Jackson Street', 1234567890,
                                      '*****@*****.**', 'active', 1000.00)
        basic_operations.update_customer_credit('004', 2000)
        basic_operations.update_status('004', 'inactive')
        expected_customer = {
            'customer_id': '004',
            'name': 'Joey',
            'lastname': 'Smith',
            'home_address': '123 Jackson Street',
            'phone_number': '1234567890',
            'email_address': '*****@*****.**',
            'status': 'inactive',
            'credit_limit': 2000.00
        }
        actual_searched_customer = basic_operations.search_customer('004')
        self.assertEqual(actual_searched_customer, expected_customer)
        actual_customer_count = basic_operations.list_active_customers()
        self.assertEqual(actual_customer_count, 0)
        basic_operations.delete_customer('004')

        try:
            DATABASE.connect()
            DATABASE.execute_sql('PRAGMA foreign_keys = ON;')
            LOGGER.info('Successfully connected to the database')
            searched_customer = Customers.get(Customers.customer_id == '004')
            LOGGER.info('Customer Found!')
            deleted_customer = {
                'customer_id': searched_customer.customer_id,
                'name': searched_customer.name,
                'lastname': searched_customer.lastname,
                'home_address': searched_customer.home_address,
                'phone_number': searched_customer.phone_number,
                'email_address': searched_customer.email_address,
                'status': searched_customer.status,
                'credit_limit': searched_customer.credit_limit
            }

        except Exception as ex:
            LOGGER.info('Error finding customer 004')
            LOGGER.info(ex)
            deleted_customer = {}

        self.assertEqual(deleted_customer, {})
        LOGGER.info('Closing database')
        DATABASE.close()
Exemplo n.º 2
0
    def test_update_status(self):
        """Test that you can update a customer's status to only either active or inactive"""
        add_test_customer()
        LOGGER.info('Closing database')
        DATABASE.close()

        basic_operations.update_status('007', 20000)
        updated_status_customer_fail = Customers.get(
            Customers.customer_id == '007')
        actual_status_update_fail = updated_status_customer_fail.status
        expected_status_fail = 'active'

        self.assertEqual(actual_status_update_fail, expected_status_fail)

        basic_operations.update_status('007', 'inactive')
        updated_status_customer_success = Customers.get(
            Customers.customer_id == '007')
        actual_status_update_success = updated_status_customer_success.status
        expected_status_success = 'inactive'

        self.assertEqual(actual_status_update_success, expected_status_success)

        basic_operations.update_status('007', 'active')
        updated_status_customer_active = Customers.get(
            Customers.customer_id == '007')
        actual_status_update_active = updated_status_customer_active.status
        expected_status_active = 'active'

        self.assertEqual(actual_status_update_active, expected_status_active)

        delete_test_customer()