Beispiel #1
0
    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())
Beispiel #2
0
 def setUpClass(cls):
     """
     Setup the test case
     """
     # print('setup method is called')
     DATABASE.drop_tables([Customer])
     DATABASE.create_tables([Customer])
def set_up_db():
    """
    Set up routine needed for all tests to make sure the db is in a
    known/empty state
    """
    DATABASE.drop_tables([Customer])
    DATABASE.close()
    DATABASE.create_tables([Customer])
    DATABASE.close()
Beispiel #4
0
    def setUp(self):
        """ Ensure we start with a clean table """

        # Configure logging for test activity
        bo.configure_logger()

        logging.info("Dropping Customer table")
        DATABASE.drop_tables([Customer])
        logging.info("Creating Customer table")
        DATABASE.create_tables([Customer])
Beispiel #5
0
    def tearDown(self):
        """ Ensure we start with a clean table """

        DATABASE.drop_tables([Customer])
        DATABASE.create_tables([Customer])
Beispiel #6
0
'''Integrated testing of the basic_operations module'''

# pylint disabled: C0413, E0401

from unittest import TestCase
import sys

sys.path.insert(1, '../')
from customer_model import DATABASE, Customer
import basic_operations

DATABASE.drop_tables([Customer])
DATABASE.create_tables([Customer])

class TestBasicOperations(TestCase):
    '''Testing basic_operations functioanlity'''
    def test_integration(self):
        '''Integrated test set'''
        cust_list = [(101, 'Bugs', 'Bunny', '123 NE 160th Ave, Kirkland, WA 98034', '425-123-4567',
                      '*****@*****.**', 'Active', 100.00),
                     (123, 'Donald', 'Duck', '456 SE 45th St, Bellevue, WA 98004', '425-234-5678',
                      '*****@*****.**', 'Active', 500.00),
                     (53, 'Elmer', 'Fudd', '789 W 52nd Pl, Bothell, WA 98077', '425-345-6789',
                      '*****@*****.**', 'Inactive', 12000.00)]

        test_list = [{'f_name': 'Elmer', 'l_name': 'Fudd', 'email': '*****@*****.**',
                      'phone': '425-345-6789'},
                     {'f_name': 'Bugs', 'l_name': 'Bunny', 'email': '*****@*****.**',
                      'phone': '425-123-4567'}]

        # Test adding customers
def reset_db():
    '''Resets the database'''
    DATABASE.drop_tables([Customer])
    DATABASE.create_tables([Customer])
class OperationalTests(TestCase):
    """ Define a class for testing operations """

    def setUp(self):
        """ Ensure we start with a clean table """

    DATABASE.drop_tables([Customer])
    DATABASE.create_tables([Customer])

    def test_add_customer(self):
        """ Test adding customers """

        # Add a customer and ensure it is in the DB
        bo.add_customer(**TEST_USER1)
        test_customer = Customer.get(Customer.customer_id == TEST_USER1['customer_id'])
        self.assertEqual(test_customer.name, TEST_USER1['name'])

        # Ensure adding a non-unique customer_id fails
        with self.assertRaises(IntegrityError):
            bo.add_customer(**TEST_USER1)

        # Delete the test user
        bo.delete_customer(TEST_USER1['customer_id'])

    def test_search_customer(self):
        """ Test searching for a customer """

        # Add a customer and ensure it is in the DB
        bo.add_customer(**TEST_USER1)

        # Search for a valid user created in the first test
        test_customer = bo.search_customer(TEST_USER1['customer_id'])
        self.assertEqual(test_customer.name, TEST_USER1['name'])

        # Search for an invalid user
        with self.assertRaises(DoesNotExist):
            test_customer = bo.search_customer(50)

        # Delete the test user
        bo.delete_customer(TEST_USER1['customer_id'])

    def test_delete_customer(self):
        """ Test deleting customers """

        # Add a user to ensure we have something to delete
        bo.add_customer(**TEST_USER2)

        # Delete the test user
        bo.delete_customer(TEST_USER2['customer_id'])

        # Search for an invalid user
        with self.assertRaises(DoesNotExist):
            Customer.get(Customer.customer_id == TEST_USER2['customer_id'])

    def test_update_customer_credit(self):
        """ Test updating a customer's credit limit """

        # Add a user to ensure we have something to delete
        bo.add_customer(**TEST_USER1)

        # Update the limit for the first test user
        bo.update_customer_credit(TEST_USER1['customer_id'], 2500.00)
        test_customer = Customer.get(Customer.customer_id == TEST_USER1['customer_id'])
        self.assertEqual(test_customer.credit_limit, 2500.00)

        # Update the limit for a customer that doesn't exist
        with self.assertRaises(DoesNotExist):
            bo.update_customer_credit(50, 3000.00)

        # Delete the test user
        bo.delete_customer(TEST_USER1['customer_id'])

    def test_list_customers(self):
        """ Test listing all customers in the database """

        # Add an active customer
        bo.add_customer(**TEST_USER1)

        # Add an inactive customer
        bo.add_customer(**TEST_USER2)

        # Print the active customers
        active_customers = bo.list_active_customers()
        self.assertEqual(active_customers, 1)

    def tearDown(self):
        """ Ensure we start with a clean table """

        DATABASE.drop_tables([Customer])
        DATABASE.create_tables([Customer])