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()
Example #2
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
Example #3
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)
    #with pytest.raises(Exception) as excinfo:
    dne = l.update_customer_credit("00100", 1000)  # error
    assert '<Model: Customer> instance matching query does not exist:' in str(
        dne)
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
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]) == {}
Example #6
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)
Example #7
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)
    with pytest.raises(ValueError) as excinfo:
        l.update_customer_credit("00100", 1000)  # error
        assert 'NoCustomer' in str(excinfo.value)
Example #8
0
def test_update_customer(_customers):
    """Test update customer
    """
    for customer in _customers:
        with pytest.raises(ValueError):
            l.update_customer_credit(customer[0], 1000)

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

    for customer in _customers:
        query = l.SESSION.query(l.db.Customer).filter(
            l.db.Customer.customer_id == customer[0]
        )
        result = query.one()
        assert result.credit_limit != 1000
        l.update_customer_credit(customer[0], "1000")
        query = l.SESSION.query(l.db.Customer).filter(
            l.db.Customer.customer_id == customer[0]
        )
        result = query.one()
        assert result.credit_limit == 1000

    # 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()
    def test_update_credit(self):
        """Test that you can update a customer's credit limit"""

        add_test_customer()
        LOGGER.info('Closing database')
        DATABASE.close()

        basic_operations.update_customer_credit('002', 2000)
        updated_credit_customer1 = Customers.get(
            Customers.customer_id == '001')
        actual_credit_update1 = updated_credit_customer1.credit_limit
        expected_credit_update1 = 1000.00

        self.assertEqual(actual_credit_update1, expected_credit_update1)

        basic_operations.update_customer_credit('001', 2000)
        updated_credit_customer2 = Customers.get(
            Customers.customer_id == '001')
        actual_credit_update2 = updated_credit_customer2.credit_limit
        expected_credit_update2 = 2000.00

        self.assertEqual(actual_credit_update2, expected_credit_update2)

        delete_test_customer()
    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")