def test_update_customer_credit_missing(): create_sample_database() with pytest.raises(pw.DoesNotExist): bo.update_customer_credit("44", 300) clear_database()
def test_integration(self): # Add Alice and Bob2 alice = self.definitions['Alice'] bob2 = self.definitions['Bob2'] bo.add_customer(alice['id'], alice['name'], alice['last_name'], alice['address'], alice['phone'], alice['email'], alice['status'], alice['credit_limit']) bo.add_customer(bob2['id'], bob2['name'], bob2['last_name'], bob2['address'], bob2['phone'], bob2['email'], bob2['status'], bob2['credit_limit']) # Assert that all 3 are in the DB self.assertEqual(3, Customer.select().count()) # Modify Alice's credit limit bo.update_customer_credit(alice['id'], 12.32) self.assertEqual( 12.32, float(Customer.get(Customer.name == 'Alice').credit_limit)) # Search for Bob2 res = bo.search_customer(bob2['id']) for k in ['name', 'last_name', 'email', 'phone']: self.assertEqual(bob2[k], res[k]) # Delete Bob2 bo.delete_customer(bob2['id']) res = bo.search_customer(bob2['id']) self.assertEqual({}, res)
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_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_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_update_fake_customer_credit(self): ''' Tests case where customer being updated does not exist ''' # Ensure that updating a fake customer's credit raises a value error with self.assertRaises(ValueError): basic_operations.update_customer_credit('99999', 5000)
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_update_credit(self): """Test the update_customer_credit function""" bo.add_customer(**CUST1) bo.update_customer_credit(CUST1['customer_id'], 5000) querydata = bo.Customer.get( bo.Customer.customer_id == CUST1['customer_id']) self.assertEqual(querydata.credit_limit, 5000)
def test_integration(self): # Add customers 2 and 3 c2, c3 = next(self.def_tuples), next(self.def_tuples) # alice = self.definitions['Alice'] # bob2 = self.definitions['Bob2'] bo.add_customer(*c2) bo.add_customer(*c3) # bo.add_customer(alice['id'], alice['name'], alice['last_name'], alice['address'], # alice['phone'], alice['email'], alice['status'], alice['credit_limit']) # bo.add_customer(bob2['id'], bob2['name'], bob2['last_name'], bob2['address'], # bob2['phone'], bob2['email'], bob2['status'], bob2['credit_limit']) # Assert that all 3 are in the DB self.assertEqual(3, Customer.select().count()) # Modify c2's credit limit bo.update_customer_credit(c2[0], 12.32) self.assertEqual(12.32, float(Customer.get(Customer.name == c2[1]).credit_limit)) # Search for c3 res = bo.search_customer(c3[0]) for k in ['name', 'last_name', 'email', 'phone']: self.assertEqual(c3[self.labels.index(k)], res[k]) # Delete c3 bo.delete_customer(c3[0]) res = bo.search_customer(c3[0]) self.assertEqual({}, res)
def test_update_customer_credit(self): """Test to check that updating a customer behaves properly""" main.update_customer_credit(1, 12000) customer = Customer.get(Customer.customer_id == 1) self.assertEqual(12000, customer.credit_limit) update = main.update_customer_credit(2, 2000) self.assertEqual(update, None)
def test_update_credit(): create_sample_database() bops.update_customer_credit('1', 25500) cust_update = cs.Customer.get(cs.Customer.customer_id == 1) assert cust_update.credit_limit == 25500 clear_database()
def test_update_credit_none(): create_sample_database() with pytest.raises(peewee.DoesNotExist): bops.update_customer_credit('44', 5000) clear_database()
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_update_customer_credit(self): logging.info('Testing update_customer_credit...') self.clear_database() basic_operations.add_customer(*self.CUST_LIST[2]) new_credit = 505050 try: # Confirm that the existing credit limit field exists. acust = Customer.get(Customer.cust_id == '003') exist_limit = acust.cust_credit_limit self.assertEqual(self.CUST_LIST[2][7], exist_limit) # Update the credit limit. basic_operations.update_customer_credit('003', new_credit) # Confirm that the credit limit changed for the customer. self.assertEqual( new_credit, Customer.get(Customer.cust_id == '003').cust_credit_limit) # Test that a ValueError is raised for a credit limit that isn't available. with self.assertRaises(ValueError): basic_operations.update_customer_credit('002', new_credit) except peewee.DoesNotExist as e: assert False
def test_basic_operations(self): for test_customer in customers: basic_operations.add_customer(test_customer[CUSTOMER_ID], test_customer[CUSTOMER_NAME], test_customer[CUSTOMER_LASTNAME], test_customer[CUSTOMER_HOME_ADDRESS], test_customer[CUSTOMER_PHONE_NUMBER], test_customer[CUSTOMER_EMAIL_ADDRESS], test_customer[CUSTOMER_STATUS], test_customer[CUSTOMER_CREDIT_LIMIT]) customer = basic_operations.search_customer('1') self.assertEqual(customer.lastname, 'Lillard') basic_operations.update_customer_credit('2', 250.99) customer = basic_operations.search_customer('2') self.assertEqual(float(customer.credit_limit), 250.99) self.assertEqual(basic_operations.list_active_customers(), 2) index = 0 for customer in basic_operations.list_all_customers(): self.assertEqual(customer, pp_customers[index]) index = index + 1 self.assertEqual(basic_operations.delete_customer('3'), 1)
def test_update_customer_credit(self): """tests the function update_customer_credit that will count the active customers in the database""" logging.info('Testing update_customer_credit...') clear_database() basic_operations.add_customer(*self.customer_list[2]) new_credit = 40000 try: # Confirm that the existing credit limit field exists. acustomer = Customer.get(Customer.cust_id == '3') exist_limit = acustomer.cust_credit_limit self.assertEqual(self.customer_list[2][7], exist_limit) # Update the credit limit. basic_operations.update_customer_credit('3', new_credit) # Confirm that the credit limit changed for the customer. self.assertEqual( new_credit, Customer.get(Customer.cust_id == '3').cust_credit_limit) # Test that a ValueError is raised for a customer that isn't in the database with self.assertRaises(ValueError): basic_operations.update_customer_credit('2', new_credit) except peewee.DoesNotExist: assert False
def test_update_customer_credit(_update_customer_credit): """ update """ new_credit = 369 customer_id = 6 b_ops.update_customer_credit(new_credit, customer_id) result = b_ops.search_customer(6) assert result['credit_limit'] == 369
def test_update_customer_credit(self, mock_database): """Testing updating customer credit via update_customer_credit function.""" basic_operations.DATABASE_NAME = TEST_DATABASE self.assertTrue(update_customer_credit(5, 5000)) self.assertEqual(Customer.get_by_id(5).credit_limit, 5000) with self.assertRaises(ValueError): update_customer_credit(4, 80000)
def test_update_customer_credit_no_match(): add_customer(**ok_customer) second_customer = add_second_customer() with pytest.raises(ValueError): update_customer_credit("12345", 100.0) clean_up(ok_customer['customer_id']) clean_up(second_customer['customer_id'])
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_update_customer_credit_limit_if_customer_exists(database_connection): add_customer(**ok_customer2) update_customer_credit("W54Hi66", "800") updated_customer = Customers.get(Customers.customer_id == "W54Hi66") assert updated_customer.credit_limit == "800"
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): """ 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_update_customer_credit(): add_customer(**ok_customer) second_customer = add_second_customer() update_customer_credit(second_customer["customer_id"], 100.0) customer_dict = search_customer(second_customer["customer_id"]) assert customer_dict["credit_limit"] == 100.0 clean_up(ok_customer['customer_id']) clean_up(second_customer['customer_id'])
def test_update_customer_credit(self): """tests update_customer_credit""" create_db() add_customer(123, "Bob", "Smith", "123 Lane Lane", "123-4567", "*****@*****.**", True, 10000) update_customer_credit(123, 15000) query = Customer.get(Customer.customer_id == 123) self.assertEqual(query.credit_limit, 15000)
def test_update_customer_credit(): ''' Tests update_customer_credit. ''' update_customer_credit(OK_CUSTOMER['customer_id'], 75.00) test_customer = Customer.get( Customer.customer_id == OK_CUSTOMER['customer_id']) assert test_customer.credit_limit == 75.00
def test_update_customer_credit(set_up_connection): ''' Tests update_customer_credit. ''' add_customer(**OK_CUSTOMER) update_customer_credit(OK_CUSTOMER['customer_id'], 75.00) test_customer = Customer.get( Customer.customer_id == OK_CUSTOMER['customer_id']) assert test_customer.credit_limit == 75.00
def test_update_customer_credit(self): """ Tests function to update customer's credit """ setup_db() update_customer_credit(3, 300.00) test_customer = Customer.get(Customer.customer_id == 3) self.assertEqual(300.00, test_customer.credit_limit) with self.assertRaises(ValueError): update_customer_credit(10, 300.00)
def test_csv_update_customer_credit(csv_database): bo.update_customer_credit("C000003", 100) target_customer = cm.Customer.get(cm.Customer.customer_id == "C000003") assert target_customer.credit_limit == 100 with pytest.raises(pw.DoesNotExist): bo.update_customer_credit("200", 200)
def test_update_customer_credit(self): # Update first_cust's credit bo.update_customer_credit(1, 3000) first_cust = Customer.get(Customer.id == 1) self.assertEqual(3000, first_cust.credit_limit) # Update non-existent customer with self.assertRaises(ValueError): bo.update_customer_credit(-1, 100)