Example #1
0
    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)
Example #2
0
 def test_delete_customer(self):
     '''
     Tests method to delete customer from database
     '''
     # Add customer to database
     self.add_customer_to_database()
     # Delete customer from database
     basic_operations.delete_customer(self.new_customer['id'])
     # Verify that trying to retrive the customer yields a DoesNotExist Error
     with self.assertRaises(DoesNotExist):
         Customer.get(Customer.id == self.new_customer['id'])
def test_list_active_customers(_list_active_customers):
    """ actives """
    for customer in _list_active_customers:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])
    actives = l.list_active_customers()

    assert actives == 2

    for customer in _list_active_customers:
        l.delete_customer(customer[0])
def test_delete_customer():
    create_sample_database()

    number_of_customer2s = (cm.Customer.select().where(cm.Customer.customer_id == "2").count())
    assert number_of_customer2s == 1

    bo.delete_customer("2")
    new_number_of_customer2s = (cm.Customer.select().where(cm.Customer.customer_id == "2").count())
    assert new_number_of_customer2s == 0

    clear_database()
def test_delete_customer_count():
    create_customer_db()
    number_of_customers = (cm.Customer.select().count())
    assert number_of_customers == 2

    bo.delete_customer("W54Hi66")

    current_number_of_customers = (cm.Customer.select().count())
    assert current_number_of_customers == 1

    drop_db()
    def test_delete_customer(self):
        """ Verify that customers can be deleted correctly """
        create_database()
        add_customer(1738, 'Bartholomew', 'Simpson', '742 Evergreen Terrace',
                     12065554682, '*****@*****.**', True, 101.50)
        add_customer(1739, 'Monty', 'Burns', '1 Money Street', 12065554531,
                     '*****@*****.**', True, 1000000)

        delete_customer(1738)

        self.assertRaises(ValueError, search_customer, 1738)
        self.assertRaises(ValueError, delete_customer, 2000)
    def test_3_delete_records(self):
        """Test that a record is deleted if it exists."""

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

        self.assertEqual(basic_operations.delete_customer(1), True)
        self.assertEqual(basic_operations.delete_customer(2), True)

        self.assertEqual(basic_operations.delete_customer(3), False)
        self.assertEqual(basic_operations.delete_customer(4), True)

        self.assertEqual(basic_operations.list_active_customers(), 0)
def test_list_active_users(_list_active_customers):
    """ Testing to ensure users status is set and retrieved properly. """
    for customer in _list_active_customers:
        bo.add_customer(customer[0], customer[1], customer[2], customer[3],
                        customer[4], customer[5], customer[6], customer[7])

    assert bo.list_active_customers() == 4

    for customer in _list_active_customers:
        bo.delete_customer(customer[0])

    assert bo.list_active_customers() == 0
Example #9
0
 def test_add_customer(self):
     """tests add_customer function"""
     add_customer("C00001",
                  "Tim",
                  "Cook",
                  "123 fake st, Seattle, WA",
                  "206-123-4567",
                  "*****@*****.**",
                  True,
                  10000.00)
     self.assertEqual(Customer.get(Customer.customer_id == "C00001").first_name, "Tim")
     delete_customer('C00001')
Example #10
0
def test_list_active_customers(set_up_connection):
    '''
    Test that list_active customers returns the amount of those active.
    First get an accurate count of active customers,
    add a new customerthat is active
    Test to see that the active customers number has increased.
    '''
    num_active = list_active_customers()
    add_customer(**OK_CUSTOMER_3)  # bad customer should work
    num_active_2 = list_active_customers()
    delete_customer(OK_CUSTOMER_3['customer_id'])
    assert (num_active + 1) == num_active_2
Example #11
0
    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'])
Example #12
0
    def test_delete_customer(self):
        """Test the ability to delete a customer"""
        database_setup()

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

        delete_customer(1)
        self.assertEqual(search_customer(1), dict())

        with self.assertRaises(pw.DoesNotExist):
            delete_customer(1)
def test_delete_customer_missing():
    create_sample_database()

    number_of_customers = (cm.Customer.select().count())
    assert number_of_customers == 4

    bo.delete_customer("9")

    new_number_of_customers = (cm.Customer.select().count())
    assert new_number_of_customers == 4

    clear_database()
Example #14
0
 def test_delete_customer(self):
     '''
     Tests if customer gets deleted or will return 0 if not
     '''
     add_customer(300, 'John', 'Doe', '100 Main St', '123-456-6789',
                  '*****@*****.**', 'active', 10000)
     number = delete_customer(300)
     number2 = delete_customer(400)
     #add logic here to check whether its empty
     self.assertEqual(number, 1)
     #add logic here for attempting to delete non-existing ID
     self.assertEqual(number2, 0)
Example #15
0
 def test_update_customer_credit(self):
     """tests update_customer_credit function"""
     add_customer("C00001",
                  "Tim",
                  "Cook",
                  "123 fake st, Seattle, WA",
                  "206-123-4567",
                  "*****@*****.**",
                  True,
                  10000.00)
     update_customer_credit('C00001', 50000.00)
     self.assertEqual(Customer.get(Customer.customer_id == "C00001").credit_limit, 50000.00)
     delete_customer('C00001')
def test_delete_customer():
    create_empty_database()
    bo.add_customer(**ok_customer3)

    customer_count = cm.Customer.select().count()
    bo.delete_customer(ok_customer3['customer_id'])
    assert cm.Customer.select().count() == customer_count - 1
    # bo.delete_customer(cm.Customer.get(cm.Customer.customer_id == ok_customer3['customer_id']))

    # customer_deleted = bo.search_customer(ok_customer3['customer_id'])

    # assert customer_deleted is None
    clear_database()
def test_list_active_customers(_list_active_customers):
    """ actives """
    for customer in _list_active_customers:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])
    actives = l.list_active_customers()

    # Obvious bug in this test file (just like the last one).  _list_active_customers contains 4 active, not 2
    # assert actives == 2
    assert actives == 4

    for customer in _list_active_customers:
        l.delete_customer(customer[0])
Example #18
0
 def test_delete_customer(self):
     """tests delete_customer function"""
     add_customer("C00001",
                  "Tim",
                  "Cook",
                  "123 fake st, Seattle, WA",
                  "206-123-4567",
                  "*****@*****.**",
                  True,
                  10000.00)
     delete_customer('C00001')
     active_customers = list_active_customers()
     self.assertEqual(active_customers, 0)
def test_add_customer(_add_customers):
    """ additions """
    for customer in _add_customers:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])
        added = l.search_customer(customer[0])
        assert added["name"] == customer[1]
        assert added["lastname"] == customer[2]
        assert added["email"] == customer[5]
        assert added["phone_number"] == customer[4]

    for customer in _add_customers:
        l.delete_customer(customer[0])
Example #20
0
 def test_delete_customer(self):
     """ Test delete_customer() """
     logging.info("test_delete_customer()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Delete customer with id = 1
     delete_customer(1)
     self.assertDictEqual({}, search_customer(1))
     # Remove data and exit database
     tear_down()
 def test_delete_customer(self):
     bo.add_customer("888", "Name5", "Lastname6", "Address", "phone8", "email7", "Active", 999)
     expected_customer = {
         'name': "Name5",
         'lastname': "Lastname6",
         'email_address': "email7",
         'phone_number': "phone8",
     }
     found_customer = bo.search_customer("888")
     assert expected_customer == found_customer
     expected_customer = {}
     bo.delete_customer("888")
     found_customer = bo.search_customer("888")
     assert expected_customer == found_customer
Example #22
0
 def test_delete_customer(self):
     """ Test delete_customer() """
     logging.info("test_delete_customer()")
     # Initial database set up
     set_up()
     # Populate customers data into the database
     for person in CLIENTS:
         add_customer(**person)
     # Delete customer with id = 1
     delete_customer(1)
     self.assertDictEqual({}, search_customer(1))
     logging.critical(f"Delete customer from database: {CLIENTS[0]['name']} {CLIENTS[0]['lastname']} (id={CLIENTS[0]['customer_id']})")
     # Remove data and exit database
     tear_down()
Example #23
0
    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_delete_customer_fail(self):
        """ testing deleting a customer fail """
        setup()
        bo.add_customer('1150', 'Mark', 'Rollins',
                        '46 Hawthorne Lane, Great Falls, MT 59404',
                        '406-604-4060', '*****@*****.**', True,
                        575.00)

        bo.add_customer('3030', 'Joseph', 'Tribbiani',
                        '43 Foster Avenue, New York, NY 10003', '212-013-7564',
                        '*****@*****.**', False, 1000.00)

        with self.assertRaises(pw.DoesNotExist):
            bo.delete_customer('5102')
Example #25
0
    def test_delete_customers(self):
        """
        Tests the delete customer functionality of basic_operations.py
        :return: none
        """

        # Prove Customer 1 exists
        return_dict = search_customer(1)
        self.assertIsNotNone(return_dict)

        # Delete Customer 1
        delete_customer(1)
        return_dict2 = search_customer(1)
        self.assertEqual(0, len(return_dict2))
 def test_delete_customer(self):
     '''Tests the delete_customer function.'''
     reset_db()
     basic_operations.add_customers(TEST_LIST)
     # Testing the delete_customer function
     basic_operations.delete_customer(123)
     self.assertEqual(
         basic_operations.search_customer(101)['f_name'], TEST_LIST[0][1])
     self.assertEqual(
         basic_operations.search_customer(53)['f_name'], TEST_LIST[2][1])
     self.assertEqual(basic_operations.search_customer(123), {})
     # Testing the delete_customer not in the database
     with self.assertRaises(ValueError):
         basic_operations.delete_customer(55)
    def test_integration(self):
        """
            Test the following all together
            -add new customers to the database
            -search customers in the database
            -delete existing customers from the database
            -update customers credit
            -list the number of active customers in the database
        """

        # add a couple users all active
        ba.add_customer(1, 'Fran', 'K', '100 New York Ave, NYC, 98109',
                        '248-331-6243', '*****@*****.**', 'Active', 1000)

        ba.add_customer(2, 'Emily', 'H', '200 New York Ave, MA, 98109',
                        '248-331-6243', '*****@*****.**', 'Active', 2000)

        ba.add_customer(3, 'John', 'H', '300 New York Ave, MA, 98109',
                        '248-331-6243', '*****@*****.**', 'Active', 3000)

        # check the credit limit for an added user
        customer_1 = Customer.get(Customer.customer_id == 1)
        self.assertEqual(customer_1.credit_limit, 1000)

        # update the credit limit for a user and search for that user
        customer_3 = ba.search_customer(3)
        self.assertEqual(customer_3['credit_limit'], 3000)

        ba.update_customer_credit(3, 3333)
        customer_3 = ba.search_customer(3)
        self.assertEqual(customer_3['credit_limit'], 3333)

        # add a couple more users some active some not
        ba.add_customer(4, 'John', 'H', '300 New York Ave, MA, 98109',
                        '248-331-6243', '*****@*****.**', 'Inative', 4000)

        ba.add_customer(5, 'John', 'H', '300 New York Ave, MA, 98109',
                        '248-331-6243', '*****@*****.**', 'Inactive', 5000)

        ba.add_customer(6, 'John', 'H', '300 New York Ave, MA, 98109',
                        '248-331-6243', '*****@*****.**', 'Active', 6000)

        # add an existing customer, should throw out a warning
        ba.add_customer(3, 'John', 'H', '300 New York Ave, MA, 98109',
                        '248-331-6243', '*****@*****.**', 'Active', 3000)

        # check how many active users we have
        active_users = ba.list_active_customers()
        self.assertEqual(active_users, 4)

        # delete all our active users
        ba.delete_customer(1)
        ba.delete_customer(2)
        ba.delete_customer(3)
        ba.delete_customer(6)

        # ensure we don't have any active users left
        active_users_2 = ba.list_active_customers()
        self.assertEqual(active_users_2, 0)
Example #28
0
    def test_integration(self):
        """Test functionality of entire application."""
        self.assertIsInstance(main.CUSTOMER_DB, SqliteDatabase)
        reset_database()
        test_db = [
            (1, 'John', 'Smith', '123 Main Street', '2065551234',
             '*****@*****.**', 'Active', 10000),
            (2, 'Jane', 'Doe', '1000 Market Street', '2065555678',
             '*****@*****.**', 'Active', 5000),
            (3, 'Alice', 'Wonderland', '200 Cherry Street', '2065551357',
             '*****@*****.**', 'Active', 1000),
            (3, 'Mark', 'Allen', '555 Columbia Avenue', '2065552468',
             '*****@*****.**', 'Active', 8500)
        ]

        main.add_customer(*test_db[0])
        main.add_customer(*test_db[1])
        main.add_customer(*test_db[2])

        customer_1 = Customer.get(Customer.customer_id == 1)
        customer_2 = Customer.get(Customer.customer_id == 2)
        customer_3 = Customer.get(Customer.customer_id == 3)

        self.assertEqual(test_db[0][1], customer_1.first_name)
        self.assertEqual(test_db[1][2], customer_2.last_name)
        self.assertEqual(test_db[2][3], customer_3.home_address)

        with self.assertRaises(ValueError):
            main.add_customer(*test_db[3])

        search = main.search_customer(1)
        expected = {
            'First Name': 'John',
            'Last Name': 'Smith',
            'Email Address': '*****@*****.**',
            'Phone Number': '2065551234'
        }
        self.assertEqual(search, expected)
        self.assertEqual(main.search_customer(4), {})

        main.delete_customer(2)
        search = main.delete_customer(2)
        self.assertEqual(search, None)

        main.update_customer_credit(1, 12000)
        customer = Customer.get(Customer.customer_id == 1)
        self.assertEqual(12000, customer.credit_limit)
        update = main.update_customer_credit(4, 2000)
        self.assertEqual(update, None)
Example #29
0
    def test_delete_customer(self):
        """ test delete_customer function """
        logger.info('Test delete_customer')
        op.delete_customer('4')

        names = []
        for customer in db.Customer:
            names.append(customer.name)

        self.assertTrue('Enrico Fermi' not in names)

        # Test customer not found exception
        op.delete_customer('40')

        db.database.close()
Example #30
0
    def test_delete_customer(self):
        """ test delete_customer function """
        op.delete_customer('4')

        names = []
        for customer in db.Customer.select():
            names.append(customer.name)

        self.assertTrue('Enrico Fermi' not in names)

        # Test customer not found exception
        op.delete_customer('40')
        self.assertRaises(peewee.DoesNotExist)

        db.database.close()