예제 #1
0
    def test_basic_operations(self):
        for test_customer in customers:
            basic_operations.add_customer(test_customer[CUSTOMER_ID],
                                          test_customer[CUSTOMER_NAME],
                                          test_customer[CUSTOMER_LASTNAME],
                                          test_customer[CUSTOMER_HOME_ADDRESS],
                                          test_customer[CUSTOMER_PHONE_NUMBER],
                                          test_customer[CUSTOMER_EMAIL_ADDRESS],
                                          test_customer[CUSTOMER_STATUS],
                                          test_customer[CUSTOMER_CREDIT_LIMIT])

        customer = basic_operations.search_customer('1')
        self.assertEqual(customer.lastname, 'Lillard')

        basic_operations.update_customer_credit('2', 250.99)
        customer = basic_operations.search_customer('2')
        self.assertEqual(float(customer.credit_limit), 250.99)

        self.assertEqual(basic_operations.list_active_customers(), 2)

        index = 0
        for customer in basic_operations.list_all_customers():
            self.assertEqual(customer, pp_customers[index])
            index = index + 1

        self.assertEqual(basic_operations.delete_customer('3'), 1)
예제 #2
0
    def test_delete_customer(self):
        create_empty_db()

        customer_1 = {
            'customer_id': '0000',
            'name': 'Victor',
            'last_name': 'Medina',
            'home_address': '809 Newton ave',
            'phone_number': '5165996074',
            'email_address': '*****@*****.**',
            'status': True,
            'credit_limit': 800
        }
        customer_2 = {
            'customer_id': '9860',
            'name': 'Roger',
            'last_name': 'Fortune',
            'home_address': '676 Grand ave',
            'phone_number': '5165946824',
            'email_address': '*****@*****.**',
            'status': True,
            'credit_limit': 750
        }
        add_customer(**customer_1)
        add_customer(**customer_2)
        delete_customer(customer_1['customer_id'])
        search_customer(customer_1['customer_id'])
        self.assertEqual({}, search_customer(customer_1['customer_id']))
예제 #3
0
 def test_display_all_customers(self):
     """
     :return:
     :rtype:
     """
     create_empty_db()
     customer_1 = {
         'customer_id': '0000',
         'name': 'Victor',
         'last_name': 'Medina',
         'home_address': '809 Newton ave',
         'phone_number': '5165996074',
         'email_address': '*****@*****.**',
         'status': True,
         'credit_limit': 800
     }
     customer_2 = {
         'customer_id': '9860',
         'name': 'Roger',
         'last_name': 'Fortune',
         'home_address': '676 Grand ave',
         'phone_number': '5165946824',
         'email_address': '*****@*****.**',
         'status': True,
         'credit_limit': 750
     }
     add_customer(**customer_1)
     add_customer(**customer_2)
     customer_list = [
         customer_1['last_name'] + ',' + customer_1['name'],
         customer_2['last_name'] + ',' + customer_2['name']
     ]
     self.assertEqual(customer_list, display_all_customers())
예제 #4
0
def add_third_customer():
    third_customer = dict(ok_customer)
    third_customer["customer_id"] = "M3233bb"
    third_customer["first_name"] = "Jackson"
    third_customer["status"] = False
    add_customer(**third_customer)
    return third_customer
예제 #5
0
def add_fourth_customer():
    fourth_customer = dict(ok_customer)
    fourth_customer["customer_id"] = "M3233cc"
    fourth_customer["first_name"] = "Michael"
    fourth_customer["status"] = False
    add_customer(**fourth_customer)
    return fourth_customer
예제 #6
0
def test_update_customer_credit_no_match():
    add_customer(**ok_customer)
    second_customer = add_second_customer()
    with pytest.raises(ValueError):
        update_customer(customer_id="12345", credit_limit=100.0)
    clean_up(ok_customer['customer_id'])
    clean_up(second_customer['customer_id'])
예제 #7
0
def add_second_customer():
    second_customer = dict(ok_customer)
    second_customer["customer_id"] = "W3434ff"
    second_customer["first_name"] = "Bob"
    second_customer["email_address"] = '*****@*****.**'
    add_customer(**second_customer)
    return second_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')
예제 #9
0
 def test_update_credit(self):
     """Test the update_customer_credit function"""
     bo.add_customer(**CUST1)
     bo.update_customer_credit(CUST1['customer_id'], 5000)
     querydata = bo.Customer.get(
         bo.Customer.customer_id == CUST1['customer_id'])
     self.assertEqual(querydata.credit_limit, 5000)
    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 th db
        for cust in self.test_customer:
            add_customer(*cust)

        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
        active_cust = list_active_customers()
        self.assertEqual(1, active_cust)
    def test_add_customer(self):
        name = "Aaren"
        lastname = "Sue"
        home_address = "123 100 st, Bothell, WA 98044"
        phone_number = 1234567899
        email_address = "*****@*****.**"
        status = 1
        credit_limit = 2000

        a_customer = bo.add_customer(name, lastname, home_address,
                                     phone_number, email_address, status,
                                     credit_limit)
        customer_id = 1

        self.assertEqual(customer_id, a_customer.customer_id)
        self.assertEqual(name, a_customer.name)
        self.assertEqual(lastname, a_customer.lastname)
        self.assertEqual(home_address, a_customer.home_address)
        self.assertEqual(phone_number, a_customer.phone_number)
        self.assertEqual(email_address, a_customer.email_address)
        self.assertEqual(status, a_customer.status)
        self.assertEqual(credit_limit, a_customer.credit_limit)

        a_customer = bo.add_customer(name, lastname, home_address,
                                     phone_number, email_address, status,
                                     credit_limit)
예제 #12
0
    def test_a_add_customer(self):
        name = "Bree"
        lastname = "Planica"
        home_address = "123 Main, Palatine, IL 60067"
        phone_number = 1234567899
        email_address = "*****@*****.**"
        status = 1
        credit_limit = 2000

        a_customer = bo.add_customer(name, lastname, home_address,
                                     phone_number, email_address, status,
                                     credit_limit)
        customer_id = 1

        self.assertEqual(customer_id, a_customer.customer_id)
        self.assertEqual(name, a_customer.name)
        self.assertEqual(lastname, a_customer.lastname)
        self.assertEqual(home_address, a_customer.home_address)
        self.assertEqual(phone_number, a_customer.phone_number)
        self.assertEqual(email_address, a_customer.email_address)
        self.assertEqual(status, a_customer.status)
        self.assertEqual(credit_limit, a_customer.credit_limit)

        a_customer = bo.add_customer(name, lastname, home_address,
                                     phone_number, email_address, status,
                                     credit_limit)
    def test_list_active_customers(self):
        """
            test active customers
        """
        # test exception (empty dataset)
        number_list_active = basic_operations.list_active_customers()

        # define a test customer
        inserted_customer = ("1", "Lara", "Croft", "Los Angeles",
                             "*****@*****.**", "888-888-8888", "active",
                             100.00, "01-04-2019", "02-04-2019", "03-04-2019",
                             "tennis")

        # add customer to database via 'add_customer' method
        basic_operations.add_customer(
            inserted_customer[0], inserted_customer[1], inserted_customer[2],
            inserted_customer[3], inserted_customer[4], inserted_customer[5],
            inserted_customer[6], inserted_customer[7], inserted_customer[8],
            inserted_customer[9], inserted_customer[10], inserted_customer[11])

        # test the  list of active customers
        try:
            # retrive the a list of active customers from database
            number_list_active = basic_operations.list_active_customers()

            # test if inserted active customer exists in database
            self.assertEqual(list(number_list_active.keys())[0], 1)
            LOGGER.info("number of customers in database tested sucesfully")

            # test if inserted customer is in list of active customers
            self.assertEqual(
                list(number_list_active.values())[0], [inserted_customer[0]])
            LOGGER.info("id %s customer exist in database",
                        inserted_customer[0])

        except DoesNotExist as err:
            assert False
            LOGGER.info(err)

        # clean database -------------------
        try:
            # open database
            DATABASE.connect()
            DATABASE.execute_sql("PRAGMA foreign_keys = ON;")

            # remove inserted customer
            for customer in Customer:
                customer.delete_instance()
            LOGGER.info("inserted customer removed; database cleared")

        except IndexError as err:
            LOGGER.info("failed to remove customer; database not cleared")
            LOGGER.info(err)

        finally:
            # close database
            DATABASE.close()
            LOGGER.info("database closed")
            LOGGER.info("==================================")
예제 #14
0
def test_csv_add_customer(csv_database):
    bo.add_customer(**CUSTOMER1)

    test_customer = cm.Customer.get(cm.Customer.customer_id == "1")
    assert test_customer.phone_number == CUSTOMER1["phone_number"]

    with pytest.raises(pw.IntegrityError):
        bo.add_customer(**CUSTOMER1)
예제 #15
0
 def test_add_customer_incomplete_data(self):
     bad_cust = 'elmer fudd'
     with self.assertRaises(ValueError) as exc:
         bs.add_customer(bad_cust)
     # problem was I couldn't add a message to a key error, so changed
     # from keyerror to valueerror
     self.assertEqual(str(exc.exception),
                      config.etext['no_save'].format(bad_cust))
예제 #16
0
 def test_update_customer_credit(self):
     """tests update_customer_credit"""
     create_db()
     add_customer(123, "Bob", "Smith", "123 Lane Lane", "123-4567",
                  "*****@*****.**", True, 10000)
     update_customer_credit(123, 15000)
     query = Customer.get(Customer.customer_id == 123)
     self.assertEqual(query.credit_limit, 15000)
예제 #17
0
def test_credit_limit_float(set_up_connection):
    '''
    tests to see that adding a string to 'credit_limit' throws a ValueError
    '''
    BAD_CUSTOMER['credit_limit'] = '$40'

    with pytest.raises(ValueError):
        add_customer(**BAD_CUSTOMER)
예제 #18
0
def test_search_customer():
    add_customer(**ok_customer)
    second_customer = add_second_customer()
    customer_dict = search_customer("W3434ff")
    second_customer["credit_limit"] = float(second_customer["credit_limit"])
    assert customer_dict == second_customer
    clean_up(ok_customer["customer_id"])
    clean_up(second_customer["customer_id"])
예제 #19
0
    def test_list_active_customers(self):
        """Test the ability to test active customer"""
        database_setup()

        add_customer(1, 'Guy', 'Dudeman', '1139 Bro Street', '800-123-4567',
                     '*****@*****.**', True, 1000000)

        self.assertEqual(list_active_customers(), 1)
예제 #20
0
def test_delete_not_a_customer():
    add_customer(**ok_customer)
    second_customer = add_second_customer()
    delete_customer("12345")
    delete_customer(7)
    delete_customer()
    clean_up(ok_customer['customer_id'])
    clean_up(second_customer['customer_id'])
예제 #21
0
def test_update_customer_credit():
    add_customer(**ok_customer)
    second_customer = add_second_customer()
    update_customer_credit(second_customer["customer_id"], 100.0)
    customer_dict = search_customer(second_customer["customer_id"])
    assert customer_dict["credit_limit"] == 100.0
    clean_up(ok_customer['customer_id'])
    clean_up(second_customer['customer_id'])
 def test_list_active_customer(self):
     """tests counting number of active customers"""
     TEST_DB.bind(MODELS, bind_refs=False, bind_backrefs=False)
     TEST_DB.create_tables(MODELS)
     for customer in CUSTOMERS:
         add_customer(*customer)
     test_c5 = list_active_customers()
     self.assertEqual(test_c5, 3)
예제 #23
0
 def test_add_customer(self):
     """Test to check that customer was added to DB properly"""
     reset_database()  # clear database tables
     main.add_customer(*CUSTOMER_1)
     customer = Customer.get(Customer.customer_id == 1)
     self.assertEqual(CUSTOMER_1[1], customer.first_name)
     with self.assertRaises(ValueError):
         main.add_customer(*CUSTOMER_2)
 def test_list_active_customers(self):
     initial_count = bo.list_active_customers()
     bo.add_customer("456", "Name5", "Lastname6", "Address", "phone8", "email7", "Inactive", 50)
     now_count = bo.list_active_customers()
     assert initial_count == now_count
     bo.add_customer("234", "Name5", "Lastname6", "Address", "phone8", "email7", "Active", 50)
     now_count = bo.list_active_customers()
     assert initial_count+1 == now_count
def test_add_customers_duplicate():
    create_empty_database()
    bops.add_customer(**customer1)

    with pytest.raises(peewee.IntegrityError):
        bops.add_customer(**customer1)

    clear_database()
def test_add_customer_good():
    import pdb
    pdb.set_trace()
    add_customer(**OK_CUSTOMER)
    test_customer = Customer.get(
        Customer.customer_id == OK_CUSTOMER['customer_id'])
    assert test_customer.email_address == OK_CUSTOMER['email_address']
    del test_customer
def test_list_active_customers():
    create_empty_database()
    bo.add_customer(**ok_customer1)
    bo.add_customer(**ok_customer2)

    assert bo.list_active_customers() == 2

    clear_database()
예제 #28
0
    def test_add_bad_customer(self):

        try:
            basic_operations.add_customer(
                1, 'Bad', 'Customer', '3421 S Bull Street \
North Carolina', '203-231-3223', '*****@*****.**', 'Active', '100.9')

        except ValueError:
            self.assertRaises(ValueError)
예제 #29
0
    def test_list_active_customers(self):

        basic_operations.delete_all_customers()

        basic_operations.add_customer(2, 'Shawn', 'Kemp', '3423 Green Lake \
Street Seattle WA', '206-240-4023', '*****@*****.**', 'Active', 212109)

        count = basic_operations.list_active_customers()
        self.assertEqual(1, count)
예제 #30
0
 def test_add_customer_golden_path(self):
     """ Validates customers can be added to the DB """
     with self.assertLogs() as mock_logger:
         BaseOps.add_customer("123", "Amelia", "Bedelia",
                              "123 Starshine Ln.", "Pennsylvania 65000",
                              "*****@*****.**", "active", 3.14)
         name = "basic_operations"
         msg = f"INFO:{name}:Saved customer with ID: None"
         self.assertIn(msg, mock_logger.output)