def test_show_rentals(set_up_connection): """ Tests show_rentals function which accepts a product_id as a parameter, queries rentals_db retrieves the customer_id and then queries the customer_db to retrieve the customers contact information. This function returns a dictionary with the product_id as key, and the customers name, phone number, address, and email as the value. The db object Id, product id and zip code are omitted from the return dictionary. """ db = set_up_connection rentals_db = db['rentals_db'] customers_db = db['customers_db'] _read_csv(db, rentals_db, 'rentals.csv') _read_csv(db, customers_db, 'customers.csv') results = show_rentals(db, 'prd002') assert results == { 'user008': { 'name': 'Shirlene Harris', 'address': '4329 Honeysuckle Lane', 'phone_number': '206-279-5340', 'email': '*****@*****.**' }, 'user005': { 'name': 'Dan Sounders', 'address': '861 Honeysuckle Lane', 'phone_number': '206-279-1723', 'email': '*****@*****.**' } }
def test_c_show_rentals(self): expected = { "user00001": { "name": "Elisa Miles", "address": "4490 Union Street", "phone": "206-922-0882", "email": "*****@*****.**" } } actual = linear.show_rentals('prd00002') self.assertEqual(actual, expected)
def test_show_rentals(mongo_database): d.import_data(mongo_database, "", "products.csv", "customers.csv", "rentals.csv") result = d.show_rentals(mongo_database, "P000004") expected = {'C000002': {'first_name': 'Blanca', 'last_name': 'Bashirian', 'address': '0193 Malvina Lake', 'phone_number': '(240)014-9496 x08349', 'email': '*****@*****.**', 'status': 'Active', 'credit_limit': '689'}, 'C000004': {'first_name': 'Mittie', 'last_name': 'Turner', 'address': '996 Lorenza Points', 'phone_number': '1-324-023-8861 x025', 'email': '*****@*****.**', 'status': 'Active', 'credit_limit': '565'}} assert len(result) == 2 assert list(result.keys()) == ["C000002", "C000004"] assert result == expected
def test_show_rentals(self): """ Validates that show_rentals returns the expected dictionary """ hold_connection = Database.MongoDBConnection Database.MongoDBConnection = MockMongoDBConnection rentals = Database.show_rentals("1") self.assertEqual(len(rentals), 1) customer = MockMongoDBConnection.MockCustomers().customer rental_cust = rentals.get(customer["_id"]) self.assertIsNotNone(rental_cust) for key, value in customer.items(): if key == "_id": continue self.assertEqual(value, rental_cust[key]) Database.MongoDBConnection = hold_connection
def test_show_rentals(self): """Test show_rentals function""" # Clear the database linear.drop_all() expected_data = { 'cust0003': { 'name': 'George Garfield', 'address': '1078 106th Cir.', 'phone_number': '9660121107', 'email': '*****@*****.**' }, 'cust0008': { 'name': 'Tom Miller', 'address': '3999 30th Dr.', 'phone_number': '1100632224', 'email': '*****@*****.**' } } linear.import_products(PATH, 'products.csv') linear.import_customers(PATH, 'customers.csv') linear.import_rentals(PATH, 'rentals.csv') return_dict = linear.show_rentals('prd0001') self.assertEqual(expected_data, return_dict) linear.drop_all()
def test_show_rentals(self): ''' test show rentals ''' LOGGER.info('test start show_rentals') expected_data = { 'cid001': { 'name': 'JohnSmith', 'address': '111 Broad St.', 'phone_number': '111-222-3333', 'email': '*****@*****.**' }, 'cid004': { 'name': 'BettySims', 'address': '444 First St.', 'phone_number': '444-555-6666', 'email': '*****@*****.**' } } result_dict = show_rentals('pid001') self.assertEqual(result_dict, expected_data) LOGGER.info('test show_rentals customer who rented product %s, are %s', 'pid001', result_dict) LOGGER.info('test show_rentals completed') pass
def test_2_show_rentals(self): """ Test the integrity of the returned dictionary of active rentals. """ cust_1 = {'name': 'George Washington', 'address': '4 Bowling Green', 'phone_number': '2125555555', 'email': '*****@*****.**'} cust_2 = {'name': 'John Adams', 'address': '524-30 Market St', 'phone_number': '2675551212', 'email': '*****@*****.**'} cust_3 = {'name': 'Thomas Jefferson', 'address': '1600 Pennsylvania Ave', 'phone_number': '2029999999', 'email': '*****@*****.**'} result = linear.show_rentals('prod_1') self.assertEqual(result['cust_1'], cust_1) self.assertEqual(result['cust_3'], cust_3) result = linear.show_rentals('prod_3') self.assertEqual(result['cust_1'], cust_1) self.assertEqual(result['cust_2'], cust_2) self.assertEqual(result['cust_3'], cust_3) result = linear.show_rentals('prod_4') self.assertEqual(result['cust_2'], cust_2) self.assertEqual(result['cust_3'], cust_3) result = linear.show_rentals('prod_5') self.assertEqual(result['cust_3'], cust_3) result = linear.show_rentals('prod_0') # Validate an empty dict is received self.assertEqual(result, {}) self.assertEqual(linear.show_rentals('prod_1'), parallel.show_rentals('prod_1'))
def test_show_rentals(self): with patch("builtins.input", side_effect=("yes")): a = ln.show_rentals("prd001") b = " Maya Data" self.assertEqual(a["user1"][" Name"], b)