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 = parallel.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): ''' 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_show_rentals(self): """show user info that have rented""" build_test_csvs() database = database_setup() import_data(PATH, 'products.csv', 'customers.csv', 'rentals.csv') customers = import_csv(PATH + 'customers.csv')['data'] rentals = import_csv(PATH + 'rentals.csv')['data'] for rental in rentals: query_results = show_rentals(rental['product_id']) csv_results = [ next(cust for cust in customers if cust["user_id"] == rental['customer_id']) ] self.assertEqual(query_results, { customer.pop('user_id'): customer for customer in csv_results }) database.test.drop() delete_test_csv()
def test_show_rentals(self): """ Validates that show_rentals returns the expected dictionary """ hold_connection = ParallelDB.MongoDBConnection ParallelDB.MongoDBConnection = MockMongoDBConnection rentals = ParallelDB.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]) ParallelDB.MongoDBConnection = hold_connection
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 = db.show_rentals("prd001") b = " Maya Data" self.assertEqual(a["user1"][" Name"], b)
def test_show_rentals(_mongo_database, _show_rentals): """ rentals """ p.import_data(_mongo_database, '../data', '../data/product.csv', '../data/customer.csv', '../data/rental.csv') students_response = p.show_rentals(_mongo_database, "P000005") assert students_response == _show_rentals