def test_list_active_customers(_customers): """test list active customers """ active = l.list_active_customers() assert active == 0 for customer in _customers: l.add_customer( customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7], ) active = l.list_active_customers() assert active == 6 for customer in _customers: query = l.db.Customer.delete().where( l.db.Customer.customer_id == customer[0]) query.execute()
def test_list_active_customers(_customers): """Test list active customers """ active = l.list_active_customers() assert active == 0 for customer in _customers: l.add_customer( customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7], ) active = l.list_active_customers() assert active == 6 # Delete all new entries from the database for customer in _customers: query = l.CUSTOMERS.delete().where( l.CUSTOMERS.c.customer_id == customer[0] ) query.execute()
def test_list_active_customers(_list_active_customers): """ actives """ for customer in _list_active_customers: l.add_customer(*customer) actives = l.list_active_customers() assert actives == 4 for customer in _list_active_customers: l.delete_customer(customer[0]) assert l.list_active_customers() == 0
def test_list_active(self): """Test that you can display the correct number of active customers""" actual_customer_count1 = basic_operations.list_active_customers() self.assertEqual(actual_customer_count1, 0) add_test_customer() LOGGER.info('Closing database') DATABASE.close() actual_customer_count2 = basic_operations.list_active_customers() self.assertEqual(actual_customer_count2, 1) delete_test_customer()
def test_main(_init_data): """ Integration tests combining add, delete, update, and list """ # Adding some data to start for customer in _init_data: l.add_customer(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7]) assert _init_data[0][1] == l.search_customer(_init_data[0][0])['name'] assert _init_data[1][2] == l.search_customer(_init_data[1][0])['last_name'] # Delete a customer deleted = l.delete_customer(594) assert deleted is True # Search for deleted customer, verify empty dict is returned gone = l.search_customer(594) assert gone == {} # Test updating customer credit limit updated = l.update_customer_credit(593, 1500) assert updated == 1 new_credit = l.search_customer(593)['credit_limit'] assert new_credit == 1500 # Test active customer count active = l.list_active_customers() assert active == 3
def test_list_active_customer_when_there_are_none(self): """Test the function list_active_customers when no active customers exist""" LOGGER.info("*** TEST ***: list_active_customers when none") # Given basic_operations.delete_customer("FY2020-001") # When self.assertEqual(0, basic_operations.list_active_customers())
def test_list_active_customers(_list_active_customers): """ actives """ for customer in _list_active_customers: l.add_customer(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7]) actives = l.list_active_customers() assert actives == 4 for customer in _list_active_customers: l.delete_customer(customer[0])
def test_list_active_customers(self): """Test that the function lists all active customers""" # Given basic_operations.add_customer(*CUSTOMER2) basic_operations.add_customer(*CUSTOMER3) # When # Then self.assertEqual(2, basic_operations.list_active_customers()) basic_operations.delete_customer(CUSTOMER2[0]) basic_operations.delete_customer(CUSTOMER3[0])
def test_list_active_customers(_list_active_customers): """ actives """ active_count = 0 for customer in _list_active_customers: if customer[-2] == 'active': active_count += 1 l.add_customer(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7]) actives = l.list_active_customers() assert actives == active_count for customer in _list_active_customers: l.delete_customer(customer[0])
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()
def test_load_data(datafiles): """ verify that data load from file works """ # make sure dir has at least one file assert len(os.listdir(datafiles)) == 1 file = os.listdir(datafiles)[0] iterable = l.load_data(f"{datafiles}/{file}") count = 0 while count < 10: # take 10 values from iterator iter_value = next(iterable) l.add_customer(*iter_value) count += 1 actives = l.list_active_customers() assert actives == 10 # check for actives added = l.search_customer(iter_value[0]) assert added["name"] == iter_value[1] assert added["home_address"] == iter_value[3]
def test_integration_basic_operation(_customer): for customer in _customer: l.add_customer(*customer) for customer in _customer: assert l.search_customer(customer[0])['name'] == customer[1] assert l.search_customer(customer[0])['last_name'] == customer[2] with pytest.raises(IntegrityError) as e: l.add_customer(*_customer[0]) assert "DoubleEntry" in str(e.value) l.update_customer_credit("C000000", 10000) assert l.search_customer('C000000')['credit_limit'] == 10000 with pytest.raises(ValueError) as e: l.update_customer_credit("C001011", 10) assert 'NoCustomer' in str(e.value) assert l.list_active_customers() == 9 for customer in _customer: assert l.delete_customer(customer[0]) is True assert l.search_customer(customer[0]) == {}
def test_list_active_customers(_list_active_customers): """ actives """ for customer in _list_active_customers: try: l.add_customer(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7]) except IndexError as e: print(e) print( 'Index out of range. Cannot add customer that doesn\'t exist') print(l.list_active_customers) actives = l.list_active_customers() assert len(actives) == 4 try: for customer in _list_active_customers: l.delete_customer(customer[0]) except IndexError: pass
def test_basic_operations(self): """Test all basic operations in one integration test""" # Add customer basic_operations.add_customer( "TEST001", "Matt", "Casari", "Washington", "999-999-9999", "*****@*****.**", True, 500000.00, ) # Add a second customer basic_operations.add_customer( "TEST002", "Ringo", "Bingo", "California", "999-999-9990", "*****@*****.**", True, 20000.00, ) # Try to add another customer TEST002 basic_operations.add_customer( "TEST002", "Ringo", "Bingo", "California", "999-999-9990", "*****@*****.**", True, 20000.00, ) # Update customer 1 credit basic_operations.update_customer_credit("TEST001", 999999.99) # Delete customer 2 basic_operations.delete_customer("TEST002") # Update customer 2 credit (who no longer exists) basic_operations.update_customer_credit("TEST002", 55.99) # Delete a non-existing customer basic_operations.delete_customer("Happy1") # Search customer 1 customer1 = basic_operations.search_customer("TEST001") # Search customer 2 (who no longer exists) customer2 = basic_operations.search_customer("TEST002") # list number customers customer_count = basic_operations.list_active_customers() # Get the email list email_list = basic_operations.list_active_emails() # Assert all self.assertEqual({}, customer2) self.assertEqual("Matt", customer1["name"]) self.assertEqual("999-999-9999", customer1["phone_number"]) self.assertEqual(1, customer_count) self.assertEqual(["*****@*****.**"], email_list) # Delete the remaining customer basic_operations.delete_customer("TEST001") # Mark end of test LOGGER.info("END: test_integration")
def test_list_active_customers(self): bo.add_customer(1, 'Lady', 'Gaga', '453 Hollywood Blvd', 555334290, '*****@*****.**', True, 20000) self.assertEqual(1, bo.list_active_customers())
def test_list_active_customers(self): bo.add_customer('C00002', 'Lady', 'Gaga', '453 Hollywood Blvd', '555334290', '*****@*****.**', 'Active', '20000') self.assertEqual(1, bo.list_active_customers())