def test_show_available_products(self): '''testing show_available_products''' pass LOGGER.info('test show products with quantities available') result_dict = show_available_products() expected_dict = { 'pid001': { 'description': 'sofa', 'product_type': 'livingroom', 'quantity_available': '5' }, 'pid002': { 'description': 'washer', 'product_type': 'laundry', 'quantity_available': '4' }, 'pid004': { 'description': 'edger', 'product_type': 'garage', 'quantity_available': '2' }, 'pid005': { 'description': 'desk', 'product_type': 'office', 'quantity_available': '1' } } #self.assertEqual(result_dict, expected_dict) expected_str = str(expected_dict) result_str = str(result_dict) x = expected_str.find(expected_str) assert x >= 0 #print(f'avail prod are {result_dict}') #LOGGER.info('available products are %s', result_dict) LOGGER.info('test show_available_products tests completed')
def test_show_available_products(mongo_database): d.import_data(mongo_database, "", "products.csv", "customers.csv", "rentals.csv") result = d.show_available_products(mongo_database) assert len(result) == 9999 assert "P000001" in result assert "P010999" not in result
def test_show_available_products(self): """Test show_available_products function""" # Clear the database linear.drop_all() self.setup() linear.import_products(PATH, 'test_prod.csv') return_dict = linear.show_available_products() self.assertEqual(AVAIL_PRODS, return_dict) linear.drop_all()
def test_1_import(self): """ Test that the records are successfully imported. """ # Start fresh so we don't mess up all our tests... linear.drop_data() self.assertEqual(linear.show_available_products(), {}) # Check for proper error handling of import_data() with self.assertRaises(FileNotFoundError): result = linear.import_data('data2', 'p.csv', 'c.csv', 'r.csv') # These tests are hard-coded to the expected values from the incluced CSV's. # Your results may vary if the data sets change. :) result = linear.import_data('data', 'products.csv', 'customers.csv', 'rentals.csv') self.assertEqual(result[0][0], 1000) self.assertEqual(result[0][1], 0) self.assertEqual(result[0][2], 1000) self.assertEqual(result[1][0], 1000) self.assertEqual(result[1][1], 0) self.assertEqual(result[1][2], 1000) linear_available = linear.show_available_products() # Run the parallel again -- we're going to grab the results of show_available_products() # to consistency check later. parallel.drop_data() self.assertEqual(parallel.show_available_products(), {}) with self.assertRaises(FileNotFoundError): result = linear.import_data('data2', 'p.csv', 'c.csv', 'r.csv') result = parallel.import_data('data', 'products.csv', 'customers.csv', 'rentals.csv') self.assertEqual(result[0][0], 1000) self.assertEqual(result[0][1], 0) self.assertEqual(result[0][2], 1000) self.assertEqual(result[1][0], 1000) self.assertEqual(result[1][1], 0) self.assertEqual(result[1][2], 1000) self.assertEqual(linear_available, parallel.show_available_products())
def test_c_show_available_products(self): expected = { "prd00001": { "description": "60-inch TV stand", "product_type": "livingroom", "quantity_available": "3" }, "prd00002": { "description": "L-shaped sofa", "product_type": "livingroom", "quantity_available": "1" } } actual = linear.show_available_products() self.assertEqual(actual, expected)
def test_show_available_products(self): """ Validates that show_available_products returns the expected dictionary """ hold_connection = Database.MongoDBConnection Database.MongoDBConnection = MockMongoDBConnection products = Database.show_available_products() expected_products = MockMongoDBConnection.MockProducts().products for product in expected_products: prod_id = product["_id"] db_product = products.get(prod_id) self.assertIsNotNone(db_product) for key, value in product.items(): if key == "_id": continue self.assertEqual(value, db_product[key]) Database.MongoDBConnection = hold_connection
def test_show_available_products(self): with patch("builtins.input", side_effect=("yes")): ln.import_data("./Data/data_files_n=40", "products", "customers", "rentals") a = ln.show_available_products() self.assertEqual(a["prd1"][" Description"], ' 60-inch TV stand')
def test_clear_database(self): """Test that clear_database empties linear.""" linear.clear_database() available_products = linear.show_available_products() self.assertEqual({}, available_products)