예제 #1
0
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(_mongo_database, _show_available_products):
    ''' available products '''
    p.import_data(_mongo_database, '../data', '../data/product.csv',
                  '../data/customer.csv', '../data/rental.csv')
    students_response = p.show_available_products(_mongo_database)
    assert len(students_response) == 9999

    assert "P000001" in students_response

    assert "P010999" not in students_response
예제 #3
0
    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())
예제 #4
0
 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 = parallel.show_available_products()
     self.assertEqual(actual, expected)
예제 #5
0
    def test_show_available_products(self):
        """show user info that have rented"""
        build_test_csvs()
        database = database_setup()
        import_data(PATH, 'products.csv', 'customers.csv', 'rentals.csv')

        products = import_csv(PATH + 'products.csv')['data']
        for row in products:
            row['quantity_available'] = int(row['quantity_available'])
        csv_results = [
            next(prod for prod in products
                 if int(prod['quantity_available']) > 0)
        ]
        self.assertEqual(
            show_available_products(),
            {product.pop('product_id'): product
             for product in csv_results})
        database.test.drop()
        delete_test_csv()
예제 #6
0
 def test_show_available_products(self):
     '''testing show_available_products function'''
     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'}}
     expected_str = str(expected_dict)
     result_str = str(result_dict)
     x = expected_str.find(expected_str)
     assert x >= 0
     LOGGER.info('test show_available_products tests completed')
예제 #7
0
    def test_show_available_products(self):
        """
        Validates that show_available_products returns the expected dictionary
        """
        hold_connection = ParallelDB.MongoDBConnection
        ParallelDB.MongoDBConnection = MockMongoDBConnection

        products = ParallelDB.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])

        ParallelDB.MongoDBConnection = hold_connection
예제 #8
0
 def test_show_available_products(self):
     with patch("builtins.input", side_effect=("yes")):
         db.import_data("./Data/data_files_n=40", "products", "customers", "rentals")
     a = db.show_available_products()
     self.assertEqual(a["prd1"][" Description"], ' 60-inch TV stand')
예제 #9
0
 def test_clear_database(self):
     """Test that clear_database empties linear."""
     parallel.clear_database()
     available_products = parallel.show_available_products()
     self.assertEqual({}, available_products)