예제 #1
0
 def clear_database():
     '''
     Resets database before tests are run
     '''
     # Set up empty table for testing
     database.drop_tables([Customer])
     database.create_tables([Customer])
    def test_add_customer(self):
        """ create an empty database for testing """
        database.drop_tables([Customer])
        database.create_tables([Customer])

        logger.info('-- Testing adding new customer --')
        bo.add_customer(1, 'Emily', 'Yang', '121 Main street NewYork',
                        '2062847320', '*****@*****.**', True, 10000)

        customer = Customer.get(Customer.customer_id == 1)
        self.assertEqual(customer.name, 'Emily')
        self.assertEqual(customer.lastname, 'Yang')
        self.assertEqual(customer.home_address, '121 Main street NewYork')
        self.assertEqual(customer.phone_number, '2062847320')
        self.assertEqual(customer.email_address, '*****@*****.**')
        self.assertEqual(customer.status, True)
        self.assertEqual(customer.credit_limit, 10000)
        bo.add_customer(2, 'Adam', 'Chilly', '233 Jone street LA',
                        '4342941868', '*****@*****.**', True, 5000)
        bo.add_customer(3, 'Steve', 'Wagon', '4508 Lord Ave Seattle',
                        '6879337640', '*****@*****.**', False, 0)
        bo.add_customer(4, 'Jone', 'Comba', '1129 Brand street Boise',
                        '3745689770', '*****@*****.**', False, 100)
        bo.add_customer(5, 'Zaler', 'Danny', '29 Colb street Portland',
                        '2323456787', '*****@*****.**', True, 1000)
        self.assertEqual(len(Customer), 5)

        for customer in Customer:
            logger.info(f'{customer.name} {customer.home_address} '
                        f'{customer.phone_number} {customer.email_address} '
                        f'{customer.status} {customer.credit_limit}')
        logger.info('-- End of Testing adding new customer --\n')
예제 #3
0
 def setUp(self):
     database.drop_tables([Customer])
     database.create_tables([Customer])
     for customer in customers:
         Customer.create(customer_id=customer[CUSTOMER_ID],
                         name=customer[CUSTOMER_NAME],
                         lastname=customer[CUSTOMER_LASTNAME],
                         home_address=customer[CUSTOMER_HOME_ADDRESS],
                         phone_number=customer[CUSTOMER_PHONE_NUMNER],
                         email_address=customer[CUSTOMER_EMAIL_ADDRESS],
                         status=customer[CUSTOMER_STATUS],
                         credit_limit=customer[CUSTOMER_CREDIT_LIMIT])
예제 #4
0
def util_drop_tables():
    """
    Utility function that drops tables after testing
    """
    tables = [Customer, PhoneInfo]

    try:
        database.connect()
        database.execute_sql('PRAGMA foreign_keys = ON;') # needed for sqlite
        database.drop_tables(tables)
        logger.info('Database table drop successful')
    except Exception as thrown_exception:
        logger.info('Error dropping Customer table')
        logger.info(thrown_exception)
        logger.info('See how the database protects our data')
    finally:
        database.close()
예제 #5
0
    def test_module(self):
        '''
        Test overall basic_operations functionality
        '''

        # Set up empty table for testing
        database.drop_tables([Customer])
        database.create_tables([Customer])

        # Create new customers
        new_customer = {
            'id': '00001',
            'firstname': 'Ron',
            'lastname': 'Swanson',
            'address': '123 Fake Street',
            'phone': '555-867-5309',
            'email': '*****@*****.**',
            'status': 0,
            'credit_limit': 10000
        }
        second_customer = {
            'id': '00002',
            'firstname': 'Leslie',
            'lastname': 'Knope',
            'address': '345 Any Drive',
            'phone': '555-867-5310',
            'email': '*****@*****.**',
            'status': 1,
            'credit_limit': 20000
        }

        # Add customers
        for customer in [new_customer, second_customer]:
            basic_operations.add_customer(
                customer['id'], customer['firstname'], customer['lastname'],
                customer['address'], customer['phone'], customer['email'],
                customer['status'], customer['credit_limit'])

        # Delete a customer
        basic_operations.delete_customer(new_customer['id'])

        # Query number of active customers, should be 1
        num_active = basic_operations.list_active_customers()
        self.assertEqual(num_active, 1)
            'credit_limit': 10000
        },
        {
            'customer_id': 2,
            'name': 'Peter',
            'lastname': 'Young',
            'home_address': "This is Peter's home address",
            'phone_number': '425-222-2222',
            'email_address': '*****@*****.**',
            'status': True,
            'credit_limit': 5000
        },
    ]

    # Create Customer table in the database
    database.drop_tables(MODELS)
    database.create_tables(MODELS)
    logging.info(f"database = {database.get_tables()}")

    # All all customers in the CLIENTS dictionary into the database
    for person in CLIENTS:
        add_customer(**person)

    # Search for an existing customer in the database
    a_client = search_customer(1)
    logging.info(f"a_client = {a_client}")

    # Update an existing customer's credit limit in the database
    update_customer_credit(2, 15000)
    logging.info(f"new limit = {Customer.get_by_id(2).credit_limit}")
예제 #7
0
 def tearDown(self):
     database.drop_tables([Customer])