def test_list_active_customers(self): """ Test that list_active_customers() returns correct amount of active customers """ active_count = b_o.list_active_customers() self.assertEqual(active_count, 0) Customer.create(customer_id='1564', name='First', lastname='Last', home_address='12 1st st, Seattle, WA 98101', phone_number='5551251255', email_address='*****@*****.**', status=True, credit_limit=150.00) active_count = b_o.list_active_customers() self.assertEqual(active_count, 1) Customer.create(customer_id='2', name='First2', lastname='Last2', home_address='12 2nd st, Seattle, WA 98101', phone_number='5551251252', email_address='*****@*****.**', status=False, credit_limit=152.00) active_count = b_o.list_active_customers() self.assertEqual(active_count, 1)
def test_integration(self): """Test the entire application functionality.""" self.assertIsInstance(basic_operations.CUSTOMER_DB, peewee.SqliteDatabase) cust_1 = { 'customer_id': 1, 'first_name': 'George', 'last_name': 'Washington', 'home_address': '4 Bowling Green', 'phone_number': 2125555555, 'email_address': '*****@*****.**', 'is_active': False, 'credit_limit': 5.00 } cust_2 = { 'customer_id': 2, 'first_name': 'John', 'last_name': 'Adams', 'home_address': '524-30 Market St', 'phone_number': 2675551212, 'email_address': '*****@*****.**', 'is_active': False, 'credit_limit': 100.00 } cust_3 = { 'customer_id': 3, 'first_name': 'Thoams', 'last_name': 'Jefferson', 'home_address': '1600 Pennsylvania Ave', 'phone_number': 2029999999, 'email_address': '*****@*****.**', 'is_active': True, 'credit_limit': 10000.00 } self.assertEqual(basic_operations.list_active_customers(), 0) self.assertEqual(basic_operations.add_customer(**cust_1), True) self.assertEqual(basic_operations.add_customer(**cust_2), True) self.assertEqual(basic_operations.add_customer(**cust_3), True) self.assertEqual(basic_operations.list_active_customers(), 1) self.assertEqual(basic_operations.update_customer_credit(1, 10000), True) self.assertEqual(basic_operations.update_customer_credit(3, 15000), True) self.assertEqual( basic_operations.search_customer(1)['credit_limit'], 10000) self.assertEqual( basic_operations.search_customer(3)['credit_limit'], 15000) self.assertEqual(basic_operations.delete_customer(1), True) self.assertEqual(basic_operations.delete_customer(2), True) self.assertEqual(basic_operations.delete_customer(3), True) self.assertEqual(basic_operations.list_active_customers(), 0)
def test_active_customers(self): ''' Tests method to return integer count of active customers ''' # Empty database should have no active customers num_active = basic_operations.list_active_customers() self.assertEqual(num_active, 0) # Add first customer and ensure that active count returns 0 self.add_customer_to_database() num_active = basic_operations.list_active_customers() self.assertEqual(num_active, 0) # Change customer status to active customer = Customer.get(Customer.id == self.new_customer['id']) customer.status = 1 customer.save() # Query number of active customers, should now be 1 num_active = basic_operations.list_active_customers() self.assertEqual(num_active, 1) # Change customer status back to inactive (for other tests) customer.status = 0 customer.save()
def test_integration(self): '''testing that basic_operations functions work together''' database.drop_tables([Customer]) database.create_tables([Customer]) add_customer('D123', 'John', 'Coder', '12345 High St W', 4258291234, '*****@*****.**', True, 10500) add_customer('C123', 'Cody', 'Coder', None, 4258299876, '*****@*****.**', False, None) customer_dict = search_customer('D123') expected_dict = { 'first_name': 'John', 'last_name': 'Coder', 'email_address': '*****@*****.**', 'phone_number': 4258291234 } self.assertEqual(customer_dict, expected_dict) active = list_active_customers() self.assertEqual(1, active) update_customer_credit('D123', 100) customer = Customer.get(Customer.customer_id == 'D123') self.assertEqual(customer.credit_limit, 100) delete_customer('D123') active = list_active_customers() self.assertEqual(0, active)
def test_integration(self): ''' This fucntion tests the model and basic_fuctions classes ''' add_customer(300, 'John', 'Doe', '100 Main St', '123-456-6789', '*****@*****.**', 'active', 10000) add_customer(400, 'Jane', 'Doe', '200 Main St', '123-456-6789', '*****@*****.**', 'inactive', 20000) searched_dict = search_customer(300) self.assertEqual(search_customer(500), {}) self.assertEqual( searched_dict, { 'name': 'John', 'lastname': 'Doe', 'email_address': '*****@*****.**', 'phone_number': '123-456-6789' }) self.assertEqual(list_active_customers(), 1) update_customer_credit(300, 40000) updated_customer = Customer.select().where( Customer.customer_id == 300).get() self.assertEqual(updated_customer.credit_limit, 40000) with self.assertRaises(ValueError): update_customer_credit(500, 20000) delete_customer(300) number = delete_customer(400) self.assertEqual(number, 1) number = delete_customer(500) self.assertEqual(number, 0) self.assertEqual(list_active_customers(), 0) add_customer('abc', 'John', 'Doe', '100 Main St', '123-456-6789', '*****@*****.**', 'active', 10000) customer = Customer.get_or_none() self.assertIsNone(customer)
def test_add_customer(self): num_before = len(basic_operations.list_active_customers()) basic_operations.add_customer('C000055', 'John', 'Doe', '100 Campus Dr', '555.343.1009', '*****@*****.**', 'Active', 535) num_after = len(basic_operations.list_active_customers()) self.assertEqual(num_after - num_before, 1)
def test_basic_operations(self): """" Integration test for the basic operations """ DATABASE.drop_tables([Customer]) DATABASE.close() DATABASE.create_tables([Customer]) DATABASE.close() # Add customers to the db add_customers(self.test_customer) cust_found = search_customer(2) self.assertEqual(self.test_customer[1][5], cust_found.get("email")) update_customer_credit(1, 500.00) self.assertEqual(500.00, Customer.get_by_id(1).credit_limit) # Find out how many customers are active active_cust = list_active_customers() self.assertEqual(2, active_cust) # Delete a customer then try to find it delete_customer(2) self.assertDictEqual({}, search_customer(2)) # Find out how many customers are active and list their names self.assertEqual(1, list_active_customers()) self.assertEqual(["Reed Richards"], list_active_customer_names())
def test_basic_operations_integration(self): """ Test that list_active_customers() returns correct amount of active customers """ test_user = { 'customer_id': '1255', 'name': 'Tim', 'lastname': 'Allen', 'home_address': "15402 W 8 Mile Rd, Detroit, MI 48219", 'phone_number': '5558468665', 'email_address': '*****@*****.**', 'status': True, 'credit_limit': 10000.00 } b_o.add_customer(**test_user) test_search = b_o.search_customer('1255') self.assertEqual(test_search['name'], 'Tim') self.assertEqual(test_search['lastname'], 'Allen') self.assertEqual(test_search['phone_number'], '5558468665') self.assertEqual(test_search['email_address'], '*****@*****.**') b_o.update_customer_credit('1255', 520) db_query = Customer.get_by_id('1255') self.assertEqual(db_query.credit_limit, 520) customer_count = b_o.list_active_customers() self.assertEqual(customer_count, 1) b_o.delete_customer('1255') customer_count = b_o.list_active_customers() self.assertEqual(customer_count, 0)
def test_list_active_customers(self): """ test active customers """ # test exception (empty dataset) number_list_active = basic_operations.list_active_customers() # define a test customer inserted_customer = ("1", "Lara", "Croft", "Los Angeles", "*****@*****.**", "888-888-8888", "active", 100.00, "01-04-2019", "02-04-2019", "03-04-2019", "tennis") # add customer to database via 'add_customer' method basic_operations.add_customer( inserted_customer[0], inserted_customer[1], inserted_customer[2], inserted_customer[3], inserted_customer[4], inserted_customer[5], inserted_customer[6], inserted_customer[7], inserted_customer[8], inserted_customer[9], inserted_customer[10], inserted_customer[11]) # test the list of active customers try: # retrive the a list of active customers from database number_list_active = basic_operations.list_active_customers() # test if inserted active customer exists in database self.assertEqual(list(number_list_active.keys())[0], 1) LOGGER.info("number of customers in database tested sucesfully") # test if inserted customer is in list of active customers self.assertEqual( list(number_list_active.values())[0], [inserted_customer[0]]) LOGGER.info("id %s customer exist in database", inserted_customer[0]) except DoesNotExist as err: assert False LOGGER.info(err) # clean database ------------------- try: # open database DATABASE.connect() DATABASE.execute_sql("PRAGMA foreign_keys = ON;") # remove inserted customer for customer in Customer: customer.delete_instance() LOGGER.info("inserted customer removed; database cleared") except IndexError as err: LOGGER.info("failed to remove customer; database not cleared") LOGGER.info(err) finally: # close database DATABASE.close() LOGGER.info("database closed") LOGGER.info("==================================")
def test_integration(self): """ Test the following all together -add new customers to the database -search customers in the database -delete existing customers from the database -update customers credit -list the number of active customers in the database """ # add a couple users all active ba.add_customer(1, 'Fran', 'K', '100 New York Ave, NYC, 98109', '248-331-6243', '*****@*****.**', 'Active', 1000) ba.add_customer(2, 'Emily', 'H', '200 New York Ave, MA, 98109', '248-331-6243', '*****@*****.**', 'Active', 2000) ba.add_customer(3, 'John', 'H', '300 New York Ave, MA, 98109', '248-331-6243', '*****@*****.**', 'Active', 3000) # check the credit limit for an added user customer_1 = Customer.get(Customer.customer_id == 1) self.assertEqual(customer_1.credit_limit, 1000) # update the credit limit for a user and search for that user customer_3 = ba.search_customer(3) self.assertEqual(customer_3['credit_limit'], 3000) ba.update_customer_credit(3, 3333) customer_3 = ba.search_customer(3) self.assertEqual(customer_3['credit_limit'], 3333) # add a couple more users some active some not ba.add_customer(4, 'John', 'H', '300 New York Ave, MA, 98109', '248-331-6243', '*****@*****.**', 'Inative', 4000) ba.add_customer(5, 'John', 'H', '300 New York Ave, MA, 98109', '248-331-6243', '*****@*****.**', 'Inactive', 5000) ba.add_customer(6, 'John', 'H', '300 New York Ave, MA, 98109', '248-331-6243', '*****@*****.**', 'Active', 6000) # add an existing customer, should throw out a warning ba.add_customer(3, 'John', 'H', '300 New York Ave, MA, 98109', '248-331-6243', '*****@*****.**', 'Active', 3000) # check how many active users we have active_users = ba.list_active_customers() self.assertEqual(active_users, 4) # delete all our active users ba.delete_customer(1) ba.delete_customer(2) ba.delete_customer(3) ba.delete_customer(6) # ensure we don't have any active users left active_users_2 = ba.list_active_customers() self.assertEqual(active_users_2, 0)
def test_list_active_customers(self): initial_count = bo.list_active_customers() bo.add_customer("456", "Name5", "Lastname6", "Address", "phone8", "email7", "Inactive", 50) now_count = bo.list_active_customers() assert initial_count == now_count bo.add_customer("234", "Name5", "Lastname6", "Address", "phone8", "email7", "Active", 50) now_count = bo.list_active_customers() assert initial_count+1 == now_count
def test_list_active_customers(self): '''Tests the list_active_customers whose status is currently active.''' reset_db() # Testing no active customers self.assertEqual(basic_operations.list_active_customers(), 0) basic_operations.add_customers(TEST_LIST) # Testing some active customers self.assertEqual(basic_operations.list_active_customers(), 2)
def test_list_active_customers(self): '''tests list_active_customers function''' active_count = list_active_customers() self.assertEqual(1, active_count) customer = Customer.get(Customer.customer_id == 'D123') customer.delete_instance() active_count = list_active_customers() self.assertEqual(0, active_count)
def test_list_active_customers(self): """ unit test for getting the number of active customers """ # set up self.add_customers() self.assertEqual(3, basic_operations.list_active_customers()) self.assertNotEqual(0, basic_operations.list_active_customers()) # clean up self.delete_customers()
def test_list_active_users(_list_active_customers): """ Testing to ensure users status is set and retrieved properly. """ for customer in _list_active_customers: bo.add_customer(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7]) assert bo.list_active_customers() == 4 for customer in _list_active_customers: bo.delete_customer(customer[0]) assert bo.list_active_customers() == 0
def test_3_delete_records(self): """Test that a record is deleted if it exists.""" self.assertEqual(basic_operations.list_active_customers(), 2) self.assertEqual(basic_operations.delete_customer(1), True) self.assertEqual(basic_operations.delete_customer(2), True) self.assertEqual(basic_operations.delete_customer(3), False) self.assertEqual(basic_operations.delete_customer(4), True) self.assertEqual(basic_operations.list_active_customers(), 0)
def test_list_active_customers(set_up_connection): ''' Test that list_active customers returns the amount of those active. First get an accurate count of active customers, add a new customerthat is active Test to see that the active customers number has increased. ''' num_active = list_active_customers() add_customer(**OK_CUSTOMER_3) # bad customer should work num_active_2 = list_active_customers() delete_customer(OK_CUSTOMER_3['customer_id']) assert (num_active + 1) == num_active_2
def test_list_active_customers(self): '''Tests the list_active_customers whose status is currently active.''' reset_db() try: LOGGER.info('Testing no active customers') self.assertEqual(basic_operations.list_active_customers(), 0) basic_operations.add_customer(*TEST_LIST[0]) basic_operations.add_customer(*TEST_LIST[1]) basic_operations.add_customer(*TEST_LIST[2]) LOGGER.info('Testing some active customers') self.assertEqual(basic_operations.list_active_customers(), 2) except peewee.DoesNotExist: assert False
def test_list_active_customers(_list_active_customers): """ actives """ num_active = l.list_active_customers() 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 == 2 for customer in _list_active_customers: l.delete_customer(customer[0]) assert (num_active + 6) == actives
def test_list_active_customers(self): '''test list active customers''' pass add_customer(self.customer_111[0], self.customer_111[1], self.customer_111[2], self.customer_111[3], self.customer_111[4], self.customer_111[5], self.customer_111[6], self.customer_111[7]) active_count = list_active_customers() self.assertEqual(1, active_count) customer = Customer.get(Customer.customer_id == self.customer_111[0]) customer.delete_instance() active_count = list_active_customers() self.assertEqual(0, active_count) LOGGER.info('test list active customers completed')
def test_list_active_customers(self): self.assertEqual(1, bo.list_active_customers()) counter = 1 while True: # Add all defined customers, check if status added correctly try: cust = next(self.def_tuples) except StopIteration: break else: status = cust[self.labels.index("status")] if status: counter += 1 bo.add_customer(*cust) self.assertEqual(counter, bo.list_active_customers())
def test_integration(self): """Testing integration of the modules""" bo.add_customer('100', 'Peter', 'Parker', '135 W. 50th Street, New York City, NY 10011', '212-576-4000', '*****@*****.**', True, 1000) bo.add_customer('200', 'Iron', 'Man', '17801 International Blvd, Seattle, WA 98101', '206-787-5388', '*****@*****.**', True, 5000) bo.update_customer_credit('200', 9000) a_customer = cm.Customer.get(cm.Customer.customer_id == '200') self.assertEqual(a_customer.credit_limit, 9000) bo.add_customer('300', 'Ramkumar', 'Rajanbabu', '7525 166th Ave NE, Redmond, WA 98052', '425-556-2900', '*****@*****.**', False, 7078) self.assertEqual(bo.list_active_customers(), 2) a_customer_2 = bo.search_customer('100') a_customer_2_dict = { 'first_name': 'Peter', 'last_name': 'Parker', 'email_address': '*****@*****.**', 'phone_number': '212-576-4000' } self.assertEqual(a_customer_2, a_customer_2_dict) bo.delete_customer('100') self.assertEqual(bo.search_customer('100'), {})
def test_list_active_customers(self): """ Validates active customer count """ peewee.Model.select = MagicMock() peewee.Model.select().where = MagicMock(return_value=[1, 2, 3]) count = BaseOps.list_active_customers() self.assertEqual(3, count)
def test_integration(self): """ Tests integration of modules """ database = cm.DATABASE database.drop_tables([cm.Customer]) database.create_tables([cm.Customer]) bo.add_customer('1150', 'Mark', 'Rollins', '46 Hawthorne Lane, Great Falls, MT 59404', '406-604-4060', '*****@*****.**', True, 575.00) bo.add_customer('5102', 'Parker', 'Phan', '8811 Kingston Road, Boynton Beach, FL 33435', '786-115-5125', '*****@*****.**', True, 250.00) bo.update_customer('1150', 175.75) a_customer = cm.Customer.get(cm.Customer.customer_id == '1150') self.assertEqual(a_customer.customer_credit, 175.75) bo.add_customer('3030', 'Joseph', 'Tribbiani', '43 Foster Avenue, New York, NY 10003', '212-013-7564', '*****@*****.**', False, 1000.00) self.assertEqual(bo.list_active_customers(), 2) a_customer2 = bo.search_customer('3030') a_customer2_dict = {'first_name': 'Joseph', 'last_name': 'Tribbiani', 'email_address': '43 Foster Avenue, New York, NY 10003', 'phone_number': '212-013-7564'} self.assertEqual(a_customer2, a_customer2_dict) bo.delete_customer('3030') self.assertEqual(bo.search_customer('3030'), {}) all_customers = [{'1150': ('Mark', 'Rollins')}, {'5102': ('Parker', 'Phan')}] self.assertEqual(bo.return_all_customers(), all_customers)
def test_list_active_customers(self): """ :return: :rtype: """ create_empty_db() customer_1 = { 'customer_id': '0000', 'name': 'Victor', 'last_name': 'Medina', 'home_address': '809 Newton ave', 'phone_number': '5165996074', 'email_address': '*****@*****.**', 'status': True, 'credit_limit': 800 } customer_2 = { 'customer_id': '9860', 'name': 'Roger', 'last_name': 'Fortune', 'home_address': '676 Grand ave', 'phone_number': '5165946824', 'email_address': '*****@*****.**', 'status': True, 'credit_limit': 750 } add_customer(**customer_1) add_customer(**customer_2) self.assertEqual(2, list_active_customers())
def test_list_active_customers(self): """Test to check that customer list correctly outputs count""" reset_database() main.add_customer(*CUSTOMER_1) main.add_customer(*CUSTOMER_3) expected = main.list_active_customers() self.assertEqual(expected, 2)
def test_whole_system(self): '''make sure the database is exist''' self.assertIsNotNone(basic_operations.DATABASE) '''make sure the Customer table exist''' self.assertIsNotNone(basic_operations.Customer) '''start with an empty database''' basic_operations.delete_all_customers() '''add a new customer''' basic_operations.add_customer(1, 'Michael', 'Jordan', '3421 S Bull Street \ North Carolina', '203-231-3223', '*****@*****.**', 'Active', 212109) customer = basic_operations.search_customer(1) self.assertDictEqual(gold, customer) '''add another customer''' basic_operations.add_customer(2, 'Shawn', 'Kemp', '3423 Green Lake \ Street Seattle WA', '206-240-4023', '*****@*****.**', 'Active', 212109) count = basic_operations.list_active_customers() self.assertEqual(2, count) '''update customer 1 credit''' basic_operations.update_customer_credit(1, 200) customer = basic_operations.search_customer(1) self.assertEqual(200, customer['credit_limit']) '''update non-exist customer and catch the error''' try: basic_operations.update_customer_credit(10, 300) except ValueError: self.assertRaises(ValueError) '''delete customer 1''' basic_operations.delete_customer(1) customer = basic_operations.search_customer(1) self.assertIsNone(customer)
def test_list_active_customer(): """ sets up a new db, adds customers, runs assertions and tears down db """ setup_test_db() customer_jae = dict(OK_CUSTOMER) customer_bob = dict(OK_CUSTOMER) customer_erin = dict(OK_CUSTOMER) customer_jae['status'] = True customer_jae['name'] = 'Jae' customer_jae['customer_id'] = 0 customer_erin['status'] = True customer_erin['name'] = 'Erin' customer_erin['customer_id'] = 1 customer_bob['status'] = False customer_bob['name'] = 'Bob' customer_bob['customer_id'] = 2 # Add 3 customers to DB, only first two are Status = True add_customer(**customer_jae) add_customer(**customer_erin) add_customer(**customer_bob) # list_active_customers - Returns a dict with 2 results active_customers = list_active_customers(stage='dev') # assert first two rows are Jae and Erin assert active_customers[0]['first_name'] == customer_jae['name'] assert active_customers[1]['first_name'] == customer_erin['name'] # drop db teardown_test_db()
def test_load_csv(_data): test = l.load_customer_data(_data) ct = 0 cust_id_list = [] for customer in test: if ct < 40: l.add_customer(customer[0], customer[1], customer[2], customer[3], customer[4], customer[5], customer[6], customer[7] ) cust_id_list.append(customer[0]) ct += 1 else: break actives = l.list_active_customers() assert actives == 30 for customer in cust_id_list: l.delete_customer(customer)
def test_list_active_customers(): create_customer_db() # list_active_customers = cm.Customer.get(cm.Customer.customer_id == CUSTOMER_1['customer_id']) # assert bo.list_active_customers. == 0 for customer in bo.list_active_customers(): assert customer in ['W54Hi66', 'OO4Hi66'] drop_db()