コード例 #1
0
 def test_search_customer_not_found(self):
     """ Test search_customer() with a non-existent customer id """
     logging.info("test_search_customer_not_found()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     self.assertDictEqual({}, search_customer(-1))
     # Remove data and exit database
     tear_down()
コード例 #2
0
 def test_search_customer(self):
     """ Test search_customer() """
     logging.info("test_search_customer()")
     expected_result = {'name': 'Andrew', 'lastname': 'York', 'email_address': '*****@*****.**', 'phone_number': '425-111-1111'}
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     self.assertDictEqual(expected_result, search_customer(1))
     # Remove data and exit database
     tear_down()
コード例 #3
0
 def test_add_customer(self):
     """ Test add_customer() """
     logging.info("test_add_customer()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
         self.assertEqual(person['phone_number'], Customer.get_by_id(person['customer_id']).phone_number)
         logging.critical(f"Add new customer to database: {person['name']} {person['lastname']} (id={person['customer_id']})")
     # Remove data and exit database
     tear_down()
コード例 #4
0
 def test_list_active_customers(self):
     """ Test list_active_customers() """
     logging.info("test_list_active_customers()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Get the number of customers whose status is currently active
     self.assertEqual(2, list_active_customers())
     # Remove data and exit database
     tear_down()
コード例 #5
0
 def test_display_customers(self):
     """ Test display_customers() """
     logging.info("test_display_customers()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Display all customers
     display_customers()
     # Remove data and exit database
     tear_down()
コード例 #6
0
 def test_update_customer_credit_not_found(self):
     """ Test update_customer_credit() with a non-existent customer id """
     logging.info("test_update_customer_credit_not_found()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Update credit limit of customer id = 0
     with self.assertRaises(ValueError):
         update_customer_credit(0, 15000)
     # Remove data and exit database
     tear_down()
コード例 #7
0
 def test_update_customer_credit(self):
     """ Test update_customer_credit() """
     logging.info("test_update_customer_credit()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Update credit limit of customer id = 2
     update_customer_credit(2, 15000)
     self.assertEqual(15000, Customer.get_by_id(2).credit_limit)
     logging.critical(f"Update credit limit of customer {CLIENTS[1]['name']} {CLIENTS[1]['lastname']} (id={CLIENTS[1]['customer_id']}) from ${CLIENTS[1]['credit_limit']} to $15000")
     # Remove data and exit database
     tear_down()
コード例 #8
0
 def test_delete_customer(self):
     """ Test delete_customer() """
     logging.info("test_delete_customer()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Delete customer with id = 1
     delete_customer(1)
     self.assertDictEqual({}, search_customer(1))
     logging.critical(f"Delete customer from database: {CLIENTS[0]['name']} {CLIENTS[0]['lastname']} (id={CLIENTS[0]['customer_id']})")
     # Remove data and exit database
     tear_down()
コード例 #9
0
 def test_add_customer_invalid_phone(self):
     """ Test add_customer() with an invalid phone number """
     CLIENTS_INVALID_PHONE = [
         {'customer_id': 1, 'name': 'Andrew', 'lastname': 'York', 'home_address': "This is Andrew's home address", 'phone_number': '425-111-1111-dummy', 'email_address': '*****@*****.**', 'status': True, 'credit_limit': 10000},
         {'customer_id': 2, 'name': 'Peter', 'lastname': 'Young', 'home_address': "This is Peter's home address", 'phone_number': '425-222-2222-extra', 'email_address': '*****@*****.**', 'status': False, 'credit_limit': 5000},
     ]
     logging.info("test_add_customer_invalid_phone()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS_INVALID_PHONE:
         with self.assertRaises(IntegrityError):
             add_customer(**person)
             logging.info(Customer.get_by_id(person['customer_id']).phone_number)
     # Remove data and exit database
     tear_down()
コード例 #10
0
def tear_down():
    """ Delete all tables and close database """
    logging.info("tear_down()")
    test_db.drop_tables(MODELS)
    test_db.close()
コード例 #11
0
def set_up():
    """ Set up database connection for Customer model """
    logging.info("set_up()")
    test_db.drop_tables(MODELS)
    test_db.create_tables(MODELS)