def test_delete_customer(self): self.assertGreater(Customer.select().count(), 0) # Delete Bob bo.delete_customer(1) self.assertEqual(0, Customer.select().count()) # Delete non-existent ID bo.delete_customer(6)
def test_delete_customer(self): self.assertGreater(Customer.select().count(), 0) # Delete first customer bo.delete_customer(self.first_cust['id']) self.assertEqual(0, Customer.select().count()) # Delete non-existent ID bo.delete_customer(-1)
def list_active_customers(): """ Return count of active customers in the database """ active_members = Customer.select().where( Customer.status == 'active').count() # Alternate solution for comprehension / generator exercise i = 0 active_members = sum( 1 for customer in Customer.select().where(Customer.status == 'active')) return active_members
def list_active_customers(): ''' Return an integer with the number of customers whose status is currently active ''' active_customers = Customer.select().where(Customer.c_status == 'Active').count() LOGGER.info('Currently [%i] active customers in the database.', active_customers) return active_customers
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 list_active_customers(): """ This function will return an integer with the number of customers whose status is currently active. """ active_customer_count = Customer.select().where(Customer.status).count() return active_customer_count
def list_active_customers(): """Display a count of active customers in the database.""" active_customers = Customer.select().where( Customer.status == 'Active').count() LOGGER.info('Number of customers whose status is currently active: %s.', active_customers) return active_customers
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 list_active_customers(): """ Get the number of customers whose status is currently active :return Integer: The number of active customers """ LOGGER.info("Fetching the number of active customers") return Customer.select().where(Customer.status).count()
def query_all_customers(): """Return entries for all the customers in the DB """ query = Customer.select() c_id = (customer.id for customer in query) all_customers = [search_customer(customer_id) for customer_id in c_id] return all_customers
def list_active_customers(): """ return number of active customers and list their ids """ try: # open database DATABASE.connect() DATABASE.execute_sql('PRAGMA foreign_keys=ON;') LOGGER.info("connected to database") # return number of active customers and their ids active_ids = [ cid.customer_id for cid in Customer.select().where(Customer.status == "active") ] LOGGER.info("database has %s active customers", len(active_ids)) return {len(active_ids): active_ids} except OperationalError as err: LOGGER.info("conection to database failed") LOGGER.info(err) except (IntegrityError, DataError) as err: LOGGER.info(err) finally: # close database DATABASE.close() LOGGER.info("database closed")
def list_active_customers(): """ Gets customers whose status is currently active returns: int; number of active customers """ logging.info("getting active customers...") return Customer.select().where(Customer.status).count()
def list_active_customers(): """ use list comprehension to return number of active customers and their ids """ try: # open database DATABASE.connect() DATABASE.execute_sql('PRAGMA foreign_keys=ON;') LOGGER.info("connected to database") # return number of active customers and their ids active_ids = [ cid.customer_id for cid in Customer.select().where(Customer.status == "active") if Customer.customer_id is not None ] LOGGER.info("database has %s active customers", len(active_ids)) if not bool(len(active_ids)): raise ValueError('empty database') return {len(active_ids): active_ids} except ValueError as err: LOGGER.info(err) finally: # close database DATABASE.close() LOGGER.info("database closed")
def test_list_active_customers(self): """tests ist_active_customers function""" add_customer("C00002", "Steve", "Jobs", "456 fake st, Seattle, WA", "206-999-9999", "*****@*****.**", True, 10000.00) active_customers = Customer.select().where( Customer.active_status).count() self.assertEqual(active_customers, 1)
def list_active_customer_names(): """ Return names of active customers """ acustomer_list = Customer.select().where(Customer.status) LOGGER.info('Retrieving the active customers in the database.') return [cust.name for cust in acustomer_list]
def list_active_customers(): """ This function will return an integer with the number of customers whose status is currently active """ active_customers = Customer.select().where(Customer.active_status).count() LOGGING.info(f'We have {active_customers} active customers.') return active_customers
def list_active_customer(): """ Return the number of customers with the active status.""" LOGGER.debug("Searching the total active users") active_members = Customer.select().where(Customer.status).count() msg = f'Active Customers = {active_members}' LOGGER.info(msg) return active_members
def display_customers(): """ Displays all customers (by first and last name) in the database as a list """ query = Customer.select() logger.info('Now listing all customers in database') m = [(p.customer_name + ' ' + p.customer_last_name) for p in query] return m
def list_active_customers(): """ Return an integer with the number of customers whose status is currently active. """ acustomer_count = Customer.select().where(Customer.status).count() LOGGER.info(f'This is the number of active customers: {acustomer_count}.') return acustomer_count
def list_active_customer(): """ Show the status of customer :return: Count of all active customers """ active_customer = Customer.select().where(Customer.is_active) LOGGER.info('Number of active customers retrieved.') return len([customer.customer_id for customer in active_customer])
def list_active_customers() -> int: """ Return number of customers whose status is currently active. :return: int """ return Customer.select().where(Customer.status).count()
def list_active_customers(): """Display the active customers""" # db.connect() # db.execute_sql('PRAGMA foreign_keys = ON;') count = Customer.select().where(Customer.status == "1").count() logging.info(f"Total number of active customers are {count}") print(count) return count
def return_customer_ids(): ''' Return all customer IDs from database. Note that this function returns a generator so all customers aren't collected at once (provision for large customer database). ''' for customer_id in Customer.select(Customer.id): yield search_customer(customer_id)
def search_customer(name): '''Return a dictionary locate customer by id and return as dictionary.''' try: result = Customer.select().where(Customer.name == name).dicts().get() except peewee.DoesNotExist: result = {} return result
def search_customer(find_name): '''locate customer by name''' try: result = Customer.select().where( Customer.name == find_name).dicts().get() except DoesNotExist: result = f'{find_name} does not exist' return result
def list_active_customers(): """list all active customer: status = 1 (Active), status = 0 (Inactive)""" active_count = 0 for _ in Customer.select().where(Customer.status == True): active_count += 1 LOGGER.info("Total active customers: %d", active_count) return active_count
def display_all_customer_names(): """Function to display the customers using comprehensions""" all_customers = Customer.select() customer_names = [ customer.name + " " + customer.last_name for customer in all_customers ] LOGGER.info(f"customer_names {customer_names}") return customer_names
def __init__(self, max_records=1000): """ Initialize the iterator. """ self.cur_customer = 0 self.full_list = Customer.select().dicts() # The calling function can set a lower max than the length of the customer DB self.max = (max_records if max_records < len(self.full_list) else len( self.full_list)) - 1
def active_customer_sales_calls(): """Return a list of active customer names and phone numbers for sales calls""" customers_to_call = Customer.select().where(Customer.active_status) customer_count = list_active_customers() logging.info("Getting %s records for sales call query", customer_count) return [ f"{i.first_name} {i.last_name} {i.phone_number}" for i in customers_to_call ]