def test_delete_customer(self): """ Test that delete_customer function works """ 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) Customer.create(customer_id='2', name='First2', lastname='Last2', home_address='12 2nd st, Seattle, WA 98101', phone_number='5551251252', email_address='*****@*****.**', status=True, credit_limit=152.00) db_query = Customer.get_by_id('1564') self.assertEqual(db_query.customer_id, '1564') self.assertEqual(Customer.select().count(), 2) try: b_o.delete_customer('doesnt exist') except Exception as exception: # pylint: disable=W0703 self.fail( "delete_customer() raised {} unexpectedly".format(exception)) b_o.delete_customer('1564') self.assertEqual(Customer.select().count(), 1) with self.assertRaises(peewee.DoesNotExist): Customer.get_by_id('1564')
def list_active_customers(): """ This function will return an integer with the number of customers whose status is currently active. """ db_query = Customer.select().where(Customer.status == True).count() # pylint: disable=C0121 return db_query
def list_customer_names(): """Returns a list of customers in the database""" customer_list = Customer.select() return [ person.customer_id + ": " + person.last_name + ", " + person.first_name for person in customer_list ]
def list_active_customers(): """ This function will return an integer with the number of customers whose status is currently active. """ # db_query = Customer.select().where(Customer.status == True).count() # pylint: disable=C0121 # Above line changed to below to show iteration customer_count = 0 for customer in Customer.select(): if customer.status is True: customer_count += 1 return customer_count
def test_add_customer(self): """ Test that add_customer function works and returns correct errors """ 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) db_query = Customer.get_by_id('1255') self.assertEqual(db_query.customer_id, test_user['customer_id']) self.assertEqual(db_query.name, test_user['name']) self.assertEqual(db_query.lastname, test_user['lastname']) self.assertEqual(db_query.home_address, test_user['home_address']) self.assertEqual(db_query.phone_number, test_user['phone_number']) self.assertEqual(db_query.email_address, test_user['email_address']) self.assertEqual(db_query.status, test_user['status']) self.assertEqual(db_query.credit_limit, test_user['credit_limit']) with self.assertRaises(peewee.IntegrityError) as context: b_o.add_customer(**test_user) self.assertTrue('Tried to add a customer_id that already exists:' in str(context.exception)) second_user = { 'customer_id': '1245', 'name': 'Tim', 'lastname': 'Allen', 'home_address': "15402 W 8 Mile Rd, Detroit, MI 48219", 'phone_number': '55584686654433443434344343434334343', 'email_address': '*****@*****.**', 'status': True, 'credit_limit': '100' } b_o.add_customer(**second_user) self.assertEqual(Customer.select().count(), 2)
def list_active_customers(): """Returns number of active customers""" active_count = Customer.select().where(Customer.status).count() LOGGER.info(f'I counted {active_count} active customers') return active_count