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_import_csv(self):
        """imports a csv from a file path and makes a json"""
        build_test_csvs()

        test = import_csv('customers.csv')
        self.assertEqual(test['data'][0]['user_id'], 'user001')
        self.assertEqual(test['data'][0]['name'], 'Guy Dudeman')
        self.assertEqual(test['data'][0]['address'], '1139 Bro Street')
        self.assertEqual(test['data'][0]['phone'], '800-123-4567')
        self.assertEqual(test['data'][0]['email'], '*****@*****.**')
        self.assertEqual(test['data'][0]['user_id'], 'user001')
        self.assertEqual(test['errors'], 0)

        test = import_csv('products.csv')
        self.assertEqual(test['data'][0]['product_id'], 'prd001')
        self.assertEqual(test['data'][0]['description'], '60-inch TV stand')
        self.assertEqual(test['data'][0]['product_type'], 'livingroom')
        self.assertEqual(test['data'][0]['quantity_available'], '3')
        self.assertEqual(test['errors'], 0)

        test = import_csv('rentals.csv')
        self.assertEqual(test['data'][0]['rental_id'], 'rnt001')
        self.assertEqual(test['data'][0]['product_id'], 'prd001')
        self.assertEqual(test['data'][0]['customer_id'], 'user001')
        self.assertEqual(test['data'][0]['amount'], '1')
        self.assertEqual(test['data'][0]['time'], '7')
        self.assertEqual(test['data'][0]['price'], '10')
        self.assertEqual(test['data'][0]['total'], '70')
        self.assertEqual(test['errors'], 0)

        test = import_csv('missing.csv')
        self.assertEqual(test, {'data': [], 'errors': 1})
        delete_test_csv()

        test = import_csv("does_not_exist.csv")
        self.assertEqual(test, {'data': [], 'errors': 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()
Example #4
0
def test_import_csv():
    """docstring"""

    rentals_list = l.import_csv("../data1/rental.csv")
    assert {'product_id': 'prd002', 'user_id': 'user008'} in rentals_list
    assert len(rentals_list) == 9
Example #5
0
 def test_import_csv(self):
     """Test import function."""
     input, count = database.import_csv('data/', 'products.csv')
     self.assertEqual(self.test_product_input, input)
     self.assertEqual(count, 8)