def add_customer(customer_id, name, lastname, home_address, phone_number, email_address, status, credit_limit): """ Add a new customer to the database """ logging.info("add_customer()") # Convert inputs into a dictionary customer_dict = [ { 'customer_id': customer_id, 'name': name, 'lastname': lastname, 'home_address': home_address, 'phone_number': phone_number, 'email_address': email_address, 'status': status, 'credit_limit': credit_limit }, ] # Insert the given customer data into the database try: with database.atomic(): Customer.insert_many(customer_dict).execute() except IntegrityError as err_msg: logging.error( f"Failed to add customer {customer_id}: {name} {lastname} to the database: {err_msg}" ) raise IntegrityError
def add_customer(customer_id, name, lastname, home_address, phone_number, email_address, status, credit_limit): """ Add a new customer to the database """ logging.info("add_customer()") # Insert the given customer data into the database try: with database.atomic(): Customer.insert_many( get_customer_generator(customer_id, name, lastname, home_address, phone_number, email_address, status, credit_limit)).execute() except (OperationalError, IntegrityError) as err_msg: logging.error( f"Failed to add customer {customer_id}: {name} {lastname} to the database: {err_msg}" ) raise IntegrityError
def setUp(self): """Defines starting test database used for function testing.""" self.starting_db = [(1, 'Bob', 'Bobbo', '12 Green St', '1112223344', '*****@*****.**', False, 85000), (2, 'Jane', 'Janeo', '1550 Red Rd', '1118675309', '*****@*****.**', True, 150000), (5, 'Wilson', 'Volleyball', '1 Castaway Island', '0000000000', '*****@*****.**', True, 0) ] database.init(TEST_DATABASE) database.connect() database.execute_sql('PRAGMA foreign_keys = ON') database.create_tables([Customer]) with database.transaction(): Customer.delete().execute() Customer.insert_many(self.starting_db, fields=[Customer.customer_id, Customer.name, Customer.lastname, Customer.home_address, Customer.phone_number, Customer.email_address, Customer.active_status, Customer.credit_limit ]).execute() database.close()