コード例 #1
0
def test_main(_init_data):
    """
        Integration tests combining add, delete, update, and list
    """

    # Adding some data to start
    for customer in _init_data:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])
    assert _init_data[0][1] == l.search_customer(_init_data[0][0])['name']
    assert _init_data[1][2] == l.search_customer(_init_data[1][0])['last_name']

    # Delete a customer

    deleted = l.delete_customer(594)
    assert deleted is True

    # Search for deleted customer, verify empty dict is returned
    gone = l.search_customer(594)
    assert gone == {}

    # Test updating customer credit limit
    updated = l.update_customer_credit(593, 1500)
    assert updated == 1
    new_credit = l.search_customer(593)['credit_limit']
    assert new_credit == 1500

    # Test active customer count
    active = l.list_active_customers()
    assert active == 3
コード例 #2
0
def test_search_customer(_customers):
    """test search customer
    """
    for customer in _customers:
        assert l.search_customer(customer[0]) == {}

    for customer in _customers:

        l.add_customer(
            customer[0],
            customer[1],
            customer[2],
            customer[3],
            customer[4],
            customer[5],
            customer[6],
            customer[7],
        )

        result = l.search_customer(customer[0])
        assert result["customer_id"] == customer[0]
        assert result["name"] == customer[1]
        assert result["lastname"] == customer[2]
        assert result["home_address"] == customer[3]
        assert result["phone_number"] == customer[4]
        assert result["email"] == customer[5]
        assert result["status"] == customer[6].lower()
        assert result["credit_limit"] == customer[7]

    for customer in _customers:
        query = l.db.Customer.delete().where(
            l.db.Customer.customer_id == customer[0])
        query.execute()
コード例 #3
0
def test_search_customer(_search_customers):
    """Tests search
    """
    for customer in _search_customers[0]:
        l.add_customer(
            customer[0],
            customer[1],
            customer[2],
            customer[3],
            customer[4],
            customer[5],
            customer[6],
            customer[7],
        )

    result = l.search_customer(_search_customers[1][1])
    assert result == {}

    result = l.search_customer(_search_customers[1][0])
    assert result["name"] == _search_customers[0][1][1]
    assert result["lastname"] == _search_customers[0][1][2]
    assert result["email"] == _search_customers[0][1][5]
    assert result["phone_number"] == _search_customers[0][1][4]

    for customer in _search_customers[0]:
        print(customer[0])
        l.delete_customer(customer[0])
コード例 #4
0
    def test_search_customer(self):
        """This method tests that the customer search function works properly"""
        add_test_customer()
        LOGGER.info('Closing database')
        DATABASE.close()
        actual_searched_customer1 = basic_operations.search_customer('001')
        actual_searched_customer2 = basic_operations.search_customer('002')
        expected_searched_customer1 = {
            'customer_id': '001',
            'name': 'Joey',
            'lastname': 'Smith',
            'home_address': '123 Jackson Street',
            'phone_number': '1234567890',
            'email_address': '*****@*****.**',
            'status': 'active',
            'credit_limit': 1000.00
        }
        expected_searched_customer2 = {}

        self.assertEqual(actual_searched_customer1,
                         expected_searched_customer1)
        self.assertEqual(actual_searched_customer2,
                         expected_searched_customer2)

        delete_test_customer()
コード例 #5
0
    def test_search_customer(self):
        """This method tests that the customer search function works properly"""
        add_test_customer()
        LOGGER.info('Closing database')
        DATABASE.close()
        actual_searched_customer1 = basic_operations.search_customer('007')
        actual_searched_customer2 = basic_operations.search_customer('008')
        expected_searched_customer1 = {
            'customer_id': '007',
            'name': 'James',
            'lastname': 'Bond',
            'home_address': '007 Bond Street',
            'phone_number': '8885671000',
            'email_address': '*****@*****.**',
            'status': 'active',
            'credit_limit': 10000.00
        }
        expected_searched_customer2 = {}

        self.assertEqual(actual_searched_customer1,
                         expected_searched_customer1)
        self.assertEqual(actual_searched_customer2,
                         expected_searched_customer2)

        delete_test_customer()
コード例 #6
0
def test_search_customer(_search_customers):
    """ search """
    for customer in _search_customers[0]:
        l.add_customer(*customer)

    result = l.search_customer(_search_customers[1][1])
    assert result == {}

    result = l.search_customer(_search_customers[1][0])
    assert result["name"] == _search_customers[0][1][1]
    assert result["last_name"] == _search_customers[0][1][2]
    assert result["email_address"] == _search_customers[0][1][5]
    assert result["phone_number"] == _search_customers[0][1][4]

    for customer in _search_customers[0]:
        l.delete_customer(customer[0])
コード例 #7
0
    def test_delete_customer_exists(self):
        """Test if the delete_customer function works for existing customers"""
        # Given
        expected_customer = {
            "name": CUSTOMER1[1],
            "last_name": CUSTOMER1[2],
            "phone_number": CUSTOMER1[4],
            "email_address": CUSTOMER1[5],
        }

        # When

        actual_customer = basic_operations.search_customer("FY2020-001")
        self.assertEqual(expected_customer, actual_customer)
        basic_operations.delete_customer("FY2020-001")
        actual_customer = basic_operations.search_customer("FY2020-001")
        self.assertEqual({}, actual_customer)
コード例 #8
0
def test_search_customer(_search_customers):
    """ search """
    for customer in _search_customers:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])

    result = l.search_customer(1000)  # check nonexistent customer
    assert result == {}

    result = l.search_customer(_search_customers[1][0])
    assert result["name"] == _search_customers[1][1]
    assert result["last_name"] == _search_customers[1][2]
    assert result["email_address"] == _search_customers[1][5]
    assert result["phone_number"] == _search_customers[1][4]

    for customer in _search_customers:
        l.delete_customer(customer[0])
コード例 #9
0
def test_search_customer(_customers):
    """Test search customer
    """
    # Assert that customers are not in the database
    for customer in _customers:
        assert l.search_customer(customer[0]) == {}

    # Add customers to database
    for customer in _customers:
        l.add_customer(
            customer[0],
            customer[1],
            customer[2],
            customer[3],
            customer[4],
            customer[5],
            customer[6],
            customer[7],
        )

        # Assert that all fields are now present in the database
        result = l.search_customer(customer[0])
        assert result["customer_id"] == customer[0]
        assert result["name"] == customer[1]
        assert result["lastname"] == customer[2]
        assert result["home_address"] == customer[3]
        assert result["phone_number"] == customer[4]
        assert result["email"] == customer[5]
        assert result["status"] == customer[6].lower()
        assert result["credit_limit"] == customer[7]

    # Delete all new entries from the database
    for customer in _customers:
        query = l.CUSTOMERS.delete().where(
            l.CUSTOMERS.c.customer_id == customer[0]
        )
        query.execute()

    # Verify that the database is again empty.
    for customer in _customers:
        with pytest.raises(NoResultFound):
            query = l.SESSION.query(l.db.Customer).filter(
                l.db.Customer.customer_id == customer[0]
            )
            query.one()
コード例 #10
0
def test_update_customer_credit(_update_customer_credit):
    """ update """
    for customer in _update_customer_credit:
        l.add_customer(*customer)

    l.update_customer_credit("798", 0)
    assert l.search_customer("798")['credit_limit'] == 0
    l.update_customer_credit("797", 1000)
    assert l.search_customer("797")['credit_limit'] == 1000
    l.update_customer_credit("797", -42)
    assert l.search_customer("797")['credit_limit'] == -42
    l.update_customer_credit("796", 500)
    assert l.search_customer("796")['credit_limit'] == 500
    with pytest.raises(ValueError) as excinfo:
        l.update_customer_credit("00100", 1000)  # error
        assert 'NoCustomer' in str(excinfo.value)
    for customer in _update_customer_credit:
        assert l.delete_customer(customer[0]) == True
コード例 #11
0
def test_delete_customer(_delete_customers):
    """ delete """
    for customer in _delete_customers:
        l.add_customer(*customer)

        response = l.delete_customer(customer[0])
        assert response is True

        deleted = l.search_customer(customer[0])
        assert deleted == {}
コード例 #12
0
def test_integration_basic_operation(_customer):
    for customer in _customer:
        l.add_customer(*customer)
    for customer in _customer:
        assert l.search_customer(customer[0])['name'] == customer[1]
        assert l.search_customer(customer[0])['last_name'] == customer[2]
    with pytest.raises(IntegrityError) as e:
        l.add_customer(*_customer[0])
        assert "DoubleEntry" in str(e.value)
    l.update_customer_credit("C000000", 10000)
    assert l.search_customer('C000000')['credit_limit'] == 10000
    with pytest.raises(ValueError) as e:
        l.update_customer_credit("C001011", 10)
        assert 'NoCustomer' in str(e.value)
    assert l.list_active_customers() == 9

    for customer in _customer:
        assert l.delete_customer(customer[0]) is True
        assert l.search_customer(customer[0]) == {}
コード例 #13
0
def test_update_customer_credit(_update_customer_credit):
    """ update """
    for customer in _update_customer_credit:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])

    l.update_customer_credit("798", 0)
    l.update_customer_credit("797", 1000)
    l.update_customer_credit("797", -42)
    l.update_customer_credit("796", 500)
    updated = l.search_customer('798')
    assert updated['credit_limit'] == 0
    updated = l.search_customer('797')
    assert updated['credit_limit'] == -42
    updated = l.search_customer('796')
    assert updated['credit_limit'] == 500

    with pytest.raises(ValueError) as excinfo:
        l.update_customer_credit("00100", 1000)  # error
        assert 'NoCustomer' in str(excinfo.value)
コード例 #14
0
def test_delete_customer(_delete_customers):
    """ delete """
    for customer in _delete_customers:
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])

        response = l.delete_customer(customer[0])
        assert response is True

        deleted = l.search_customer(customer[0])
        assert deleted == {}
コード例 #15
0
    def test_search_customer_does_not_exist(self):
        """ Testing search for non-existing customer"""

        # Given
        expected_customer = {}

        # When
        actual_customer = basic_operations.search_customer("FY2020-999")

        # Then
        self.assertEqual(expected_customer, actual_customer)
コード例 #16
0
def test_add_customer(_add_customers):
    """ additions """
    for customer in _add_customers:
        l.add_customer(*customer)
        added = l.search_customer(customer[0])
        assert added["name"] == customer[1]
        assert added["last_name"] == customer[2]
        assert added["email_address"] == customer[5]
        assert added["phone_number"] == customer[4]

    for customer in _add_customers:
        l.delete_customer(customer[0])
コード例 #17
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])
コード例 #18
0
def test_search_customer(_search_customers):
    """ search """
    while True:
        try:
            customer = next(_search_customers)
            # if customer == _search_customers[-1]:
            #     break

        except StopIteration:
            break
        l.add_customer(customer[0], customer[1], customer[2], customer[3],
                       customer[4], customer[5], customer[6], customer[7])

        result = l.search_customer(customer[1][1])
        assert result == {}

        result = l.search_customer(customer[0])
        assert result["name"] == customer[1]
        assert result["lastname"] == customer[2]
        assert result["email"] == customer[5]
        assert result["phone_number"] == customer[4]

        l.delete_customer(customer[0])
コード例 #19
0
    def test_search_customer(self):
        bo.add_customer(1, 'Lady', 'Gaga', '453 Hollywood Blvd',
                        555334290, '*****@*****.**', True, 20000)

        customer_dict = bo.search_customer(1)

        test_customer = {
            'first_name': 'Lady',
            'last_name': 'Gaga',
            'email': '*****@*****.**',
            'phone_number': 555334290
        }

        self.assertDictEqual(test_customer, customer_dict)
コード例 #20
0
    def test_search_customer(self):
        bo.add_customer('C00002', 'Lady', 'Gaga', '453 Hollywood Blvd',
                        '555334290', '*****@*****.**', 'Active', '20000')

        customer_dict = bo.search_customer('C00002')

        test_customer = {
            'first_name': 'Lady',
            'last_name': 'Gaga',
            'email': '*****@*****.**',
            'phone_number': '555334290'
        }

        self.assertDictEqual(test_customer, customer_dict)
コード例 #21
0
def test_add_customer(_add_customers):
    """ additions """
    while True:
        try:
            customer = next(_add_customers)
        except StopIteration:
            break
        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]
        l.delete_customer(customer[0])
コード例 #22
0
    def test_full_integration(self):
        """Integrates all methods into one test"""
        basic_operations.add_customer('004', 'Joey', 'Smith',
                                      '123 Jackson Street', 1234567890,
                                      '*****@*****.**', 'active', 1000.00)
        basic_operations.update_customer_credit('004', 2000)
        basic_operations.update_status('004', 'inactive')
        expected_customer = {
            'customer_id': '004',
            'name': 'Joey',
            'lastname': 'Smith',
            'home_address': '123 Jackson Street',
            'phone_number': '1234567890',
            'email_address': '*****@*****.**',
            'status': 'inactive',
            'credit_limit': 2000.00
        }
        actual_searched_customer = basic_operations.search_customer('004')
        self.assertEqual(actual_searched_customer, expected_customer)
        actual_customer_count = basic_operations.list_active_customers()
        self.assertEqual(actual_customer_count, 0)
        basic_operations.delete_customer('004')

        try:
            DATABASE.connect()
            DATABASE.execute_sql('PRAGMA foreign_keys = ON;')
            LOGGER.info('Successfully connected to the database')
            searched_customer = Customers.get(Customers.customer_id == '004')
            LOGGER.info('Customer Found!')
            deleted_customer = {
                'customer_id': searched_customer.customer_id,
                'name': searched_customer.name,
                'lastname': searched_customer.lastname,
                'home_address': searched_customer.home_address,
                'phone_number': searched_customer.phone_number,
                'email_address': searched_customer.email_address,
                'status': searched_customer.status,
                'credit_limit': searched_customer.credit_limit
            }

        except Exception as ex:
            LOGGER.info('Error finding customer 004')
            LOGGER.info(ex)
            deleted_customer = {}

        self.assertEqual(deleted_customer, {})
        LOGGER.info('Closing database')
        DATABASE.close()
コード例 #23
0
def test_load_data(datafiles):
    """ verify that data load from file works """
    # make sure dir has at least one file
    assert len(os.listdir(datafiles)) == 1
    file = os.listdir(datafiles)[0]
    iterable = l.load_data(f"{datafiles}/{file}")
    count = 0
    while count < 10:  # take 10 values from iterator
        iter_value = next(iterable)
        l.add_customer(*iter_value)
        count += 1
    actives = l.list_active_customers()
    assert actives == 10  # check for actives
    added = l.search_customer(iter_value[0])
    assert added["name"] == iter_value[1]
    assert added["home_address"] == iter_value[3]
コード例 #24
0
    def test_search_customer_exists(self):
        """ Testing search for existing customer"""

        # Given
        expected_customer = {
            "name": "Sally",
            "last_name": "Ride",
            "phone_number": "206-999-9987",
            "email_address": "*****@*****.**",
        }

        # When
        actual_customer = basic_operations.search_customer("FY2020-001")

        # Then
        self.assertEqual(expected_customer, actual_customer)
コード例 #25
0
    def test_basic_operations(self):
        """Test all basic operations in one integration test"""

        # Add customer
        basic_operations.add_customer(
            "TEST001",
            "Matt",
            "Casari",
            "Washington",
            "999-999-9999",
            "*****@*****.**",
            True,
            500000.00,
        )

        # Add a second customer
        basic_operations.add_customer(
            "TEST002",
            "Ringo",
            "Bingo",
            "California",
            "999-999-9990",
            "*****@*****.**",
            True,
            20000.00,
        )

        # Try to add another customer TEST002
        basic_operations.add_customer(
            "TEST002",
            "Ringo",
            "Bingo",
            "California",
            "999-999-9990",
            "*****@*****.**",
            True,
            20000.00,
        )

        # Update customer 1 credit
        basic_operations.update_customer_credit("TEST001", 999999.99)

        # Delete customer 2
        basic_operations.delete_customer("TEST002")

        # Update customer 2 credit (who no longer exists)
        basic_operations.update_customer_credit("TEST002", 55.99)

        # Delete a non-existing customer
        basic_operations.delete_customer("Happy1")

        # Search customer 1
        customer1 = basic_operations.search_customer("TEST001")

        # Search customer 2 (who no longer exists)
        customer2 = basic_operations.search_customer("TEST002")

        # list number customers
        customer_count = basic_operations.list_active_customers()

        # Get the email list
        email_list = basic_operations.list_active_emails()

        # Assert all
        self.assertEqual({}, customer2)
        self.assertEqual("Matt", customer1["name"])
        self.assertEqual("999-999-9999", customer1["phone_number"])
        self.assertEqual(1, customer_count)
        self.assertEqual(["*****@*****.**"], email_list)

        # Delete the remaining customer
        basic_operations.delete_customer("TEST001")

        # Mark end of test
        LOGGER.info("END: test_integration")