Exemplo n.º 1
0
    def test_import_data(self):
        '''testing import_data function'''
        LOGGER.info('Testing import_data')
        data = import_data('csv_files', 'product_file.csv',
                           'customer_file.csv', 'rentals_file.csv')
        expected_data = ((4, 5, 5), (2, 2, 1))
        self.assertEqual(data, expected_data)

        LOGGER.info('test FileNotFoundError for Product File')
        data = import_data('csv_files', 'product.csv', 'customer_file.csv',
                           'rentals_file.csv')
        expected_data = ((0, 5, 5), (1, 2, 1))
        self.assertEqual(data, expected_data)

        LOGGER.info('test FileNotFoundError for Customer File')
        data = import_data('csv_files', 'product_file.csv', 'customer.csv',
                           'rentals_file.csv')
        expected_data = ((4, 0, 5), (2, 1, 1))
        self.assertEqual(data, expected_data)

        LOGGER.info('test FileNotFoundError for Rentals File')
        data = import_data('csv_files', 'product_file.csv',
                           'customer_file.csv', 'rentals.csv')
        expected_data = ((4, 5, 0), (2, 2, 1))
        self.assertEqual(data, expected_data)

        LOGGER.info('import_data tests passed')
Exemplo n.º 2
0
    def test_import_data(self):
        """testing import for three cases, empty, correct, repetitive"""
        database.clear()
        #test that the file not found error works for all three fake files
        test_count, test_errors = database.import_data(os.getcwd(),
                                                       'prod_none.csv',
                                                       'cust_none.csv',
                                                       'rental_none.csv')
        self.assertEqual(test_count, (0, 0, 0))
        self.assertEqual(test_errors, (1, 1, 1))
        #test the actual files are imported properly without errors
        test_count, test_errors = database.import_data(os.getcwd(),
                                                       'products.csv',
                                                       'customers.csv',
                                                       'rentals.csv')

        self.assertEqual(test_count, (5, 10, 10))
        self.assertEqual(test_errors, (0, 0, 0))

        #database not cleared and same files are imported, should raise duplicate errors
        #as long as the original file
        test_count, test_errors = database.import_data(os.getcwd(),
                                                       'products.csv',
                                                       'customers.csv',
                                                       'rentals.csv')

        self.assertEqual(test_errors, (5, 10, 10))
        database.clear()
Exemplo n.º 3
0
    def test_import_data(self):
        """
        Test import_data function
        """
        database.drop_db()

        actual_1 = database.import_data('', 'data/products.csv',
                                        'data/customers.csv',
                                        'data/rentals.csv')
        expected_1 = ((8, 5, 9), (0, 0, 0))

        actual_2 = database.import_data('', 'data/products12345.csv',
                                        'data/customers.csv',
                                        'data/rentals.csv')
        expected_2 = ((0, 5, 9), (1, 0, 0))

        actual_3 = database.import_data('', 'data/products.csv',
                                        'data/customers007.csv',
                                        'data/rentals.csv')
        expected_3 = ((8, 0, 9), (0, 1, 0))

        actual_4 = database.import_data('', 'data/products.csv',
                                        'data/customers.csv',
                                        'data/rentals5.csv')
        expected_4 = ((8, 5, 0), (0, 0, 1))

        self.assertEqual(actual_1, expected_1)
        self.assertEqual(actual_2, expected_2)
        self.assertEqual(actual_3, expected_3)
        self.assertEqual(actual_4, expected_4)
Exemplo n.º 4
0
    def test_show_customers(self):
        """test for show_customers"""

        delete_database()

        import_data(self.folder_name, 'inventory.csv', 'customers.csv',
                    'rental.csv')

        customers_dict = show_customers()

        gold = {
            'Customer_ID': 'c00007',
            'Name': 'Bettey White',
            'Home_Address': '232 Mohuland Drive, Hollywood, CA, 98546',
            'Phone_Number': '555-444-4444',
            'Email_Address': '*****@*****.**',
            'Status': 1,
            'Credit_Limit': 100000
        }

        self.assertDictEqual(customers_dict['c00007'], gold)


# if __name__ == "__main__":

#     test = TestDatabase()

#     test.test_import_data()

#     test.test_show_rentals()

#     test.test_show_customers()

#     test.test_show_available_products()
Exemplo n.º 5
0
 def test_show_available_products(self):
     """list all available products in the database"""
     import_data('csv_data', 'products.csv', 'customers.csv', 'rentals.csv')
     product_results = show_available_products()
     self.assertEqual(product_results, {'867': {'description': 'couch', 'product_type': 'livingroom', 'quantity': '8'},
                                        '1009': {'description': 'chair', 'product_type': 'kitchen', 'quantity': '2'},
                                        '148': {'description': 'table', 'product_type': 'office', 'quantity': '4'}})
Exemplo n.º 6
0
    def test_show_available_products(self):
        """
        Test show_available_products function
        """
        database.drop_db()
        database.import_data('', 'data/products.csv',
                             'data/customers.csv',
                             'data/rentals.csv')
        actual = database.show_available_products()
        expected = {'prd001': {'description': '700-W microwave',
                               'product_type': 'kitchen',
                               'quantity_available': '5'},
                    'prd002': {'description': 'coffee table',
                               'product_type': 'living room',
                               'quantity_available': '2'},
                    'prd003': {'description': 'standing desk',
                               'product_type': 'office',
                               'quantity_available': '14'},
                    'prd004': {'description': 'futon',
                               'product_type': 'living room',
                               'quantity_available': '1'},
                    'prd005': {'description': 'office chair',
                               'product_type': 'office',
                               'quantity_available': '2'},
                    'prd006': {'description': 'bar stool',
                               'product_type': 'kitchen',
                               'quantity_available': '13'},
                    'prd007': {'description': 'tv stand',
                               'product_type': 'living room',
                               'quantity_available': '3'}}

        self.assertEqual(actual, expected)
Exemplo n.º 7
0
def test_show_rentals(mongo_database):
    d.import_data(mongo_database, "", "products.csv", "customers.csv", "rentals.csv")

    result = d.show_rentals(mongo_database, "prd005")
    assert len(result) == 2

    assert list(result.keys()) == ["user001", "user003"]
Exemplo n.º 8
0
 def test_show_available_products(self):
     """ Unit test for the show_available_products function """
     expected_result = {
         '001': {
             'available': '25',
             'description': 'Mafex Justice League Superman',
             'type': '6 inch Action Figure'
         },
         '002': {
             'available': '12',
             'description': 'One 12 Justice League Tactical Suit Batman',
             'type': '6 inch Action Figure'
         },
         '003': {
             'available': '1',
             'description': 'S.H. Figuarts Iron Man Mark LXXXV',
             'type': '6 inch Action Figure'
         },
         '004': {
             'available': '15',
             'description': 'Black Series Stormtrooper',
             'type': '6 inch Action Figure'
         }
     }
     database.drop_all_collections()
     database.import_data("../csv_files", "products.csv", "customers.csv",
                          "rentals.csv")
     self.assertDictEqual(expected_result,
                          database.show_available_products())
Exemplo n.º 9
0
    def test_show_available_product(self):
        """ test show_available_product """
        import_data(DATA_FILE_PATH, DATA_FILE_PRODUCT, DATA_FILE_CUSTOMER,
                    DATA_FILE_RENTAL)

        expected_product_list = {
            'E0001': {
                'description': 'Television',
                'product_type': 'electronics',
                'quantity_available': 502
            },
            'F0001': {
                'description': 'Sofa',
                'product_type': 'furniture',
                'quantity_available': 398
            },
            'I0003': {
                'description': 'Computer',
                'product_type': 'electronics',
                'quantity_available': 19
            }
        }

        products_available = show_available_products()

        self.assertDictEqual(products_available['E0001'],
                             expected_product_list['E0001'])
Exemplo n.º 10
0
 def test_show_available_products(self):
     """Tests displaying available products"""
     database.clear_database()
     database.import_data('', 'test_files/products_test.csv',
                          'test_files/customers_test.csv',
                          'test_files/rentals_test.csv')
     real = database.show_available_products()
     expected = {
         'Couch': {
             'description': 'You sit on it',
             'product_type': 'living room',
             'quantity_available': '1'
         },
         'Desk': {
             'description': 'You do work at it',
             'product_type': 'bedroom',
             'quantity_available': '4'
         },
         'TV': {
             'description': 'You watch it',
             'product_type': 'den',
             'quantity_available': '3'
         },
         'Table': {
             'description': 'You eat at it',
             'product_type': 'dining room',
             'quantity_available': '2'
         }
     }
     self.assertEqual(real, expected)
Exemplo n.º 11
0
 def test_show_available_products(self):
     #list all avilable data in database
     import_data('input_csv', 'products.csv', 'customer.csv', 'rentals.csv')
     results = show_available_products()
     self.assertEqual(
         results, {
             'prd001': {
                 'description': '60_inch_tv',
                 'product_type': 'Living_room',
                 'quantity_available': '1'
             },
             'prd002': {
                 'description': 'sofa',
                 'product_type': 'Living_room',
                 'quantity_available': '1'
             },
             'prd003': {
                 'description': 'Queen_bed',
                 'product_type': 'Bed_room',
                 'quantity_available': '2'
             },
             'prd004': {
                 'description': 'Stove',
                 'product_type': 'Kitchen',
                 'quantity_available': '1'
             }
         })
Exemplo n.º 12
0
 def test_show_rentals(self):
     """
     Tests the show_rentals module
     """
     #directory_path = r"C:/Users/Amir G/SP_Python220B_2019/students/amirg/" \
     #                 r"lesson05/assignment/data"
     directory_path = r"data"
     database.import_data(directory_path, 'products.csv', 'customers.csv',
                          'rentals.csv')
     rentals = database.show_rentals('prd002')
     rentals2 = database.show_rentals('prd005')
     rentals_dict = {
         'user001': {
             'name': 'Elisa Miles',
             'address': '4490 Union Street',
             'phone_number': '206-922-0882',
             'email': '*****@*****.**'
         },
         'user002': {
             'name': 'Maya Data',
             'address': '4936 Elliot Avenue',
             'phone_number': '206-777-1927',
             'email': '*****@*****.**'
         }
     }
     rentals2_dict = {}
     self.assertEqual(rentals, rentals_dict)
     self.assertEqual(rentals2, rentals2_dict)
Exemplo n.º 13
0
    def test_show_available_products(self):
        """
        Tests the show_available_products module
        """
        #directory_path = r"C:/Users/Amir G/SP_Python220B_2019/students/amirg/" \
        #                 r"lesson05/assignment/data"
        directory_path = r"data"
        database.import_data(directory_path, 'products.csv', 'customers.csv',
                             'rentals.csv')

        avail_products = database.show_available_products()
        output_dict = {
            'prd002': {
                'description': 'L-shaped sofa',
                'product_type': 'livingroom',
                'quantity_available': '1'
            },
            'prd003': {
                'description': 'Bicycle',
                'product_type': 'recreation',
                'quantity_available': '4'
            },
            'prd004': {
                'description': 'Jacket',
                'product_type': 'apparrel',
                'quantity_available': '2'
            }
        }
        self.assertEqual(avail_products, output_dict)
Exemplo n.º 14
0
    def test_show_rentals(self):
        """ test show_rentals """
        import_data(DATA_FILE_PATH, DATA_FILE_PRODUCT, DATA_FILE_CUSTOMER,
                    DATA_FILE_RENTAL)

        expected_users = {
            'U001': {
                'name': 'Steve Jobs',
                'address': 'One Infinite Loop, Cupertino, CA 95014',
                'phone_number': '800-275-2273',
                'email': '*****@*****.**'
            },
            'U002': {
                'name': 'Bill Gates',
                'address':
                '440 5th Ave N., Seattle, WA 98109440 5th Ave N., Seattle, WA 98109',
                'phone_number': '206-709-3100 ext. 7100',
                'email': '*****@*****.**'
            },
            'U003': {
                'name': 'Mark Zuckerberg',
                'address': '1 Hacker Way, Menlo Park, California 94025',
                'phone_number': None,
                'email': '*****@*****.**'
            }
        }

        users_F0001 = show_rentals('F0001')

        self.assertDictEqual(users_F0001['U002'], expected_users['U002'])
Exemplo n.º 15
0
    def test_show_rentals(self):
        """test for show_rentals"""

        delete_database()

        import_data(self.folder_name, 'inventory.csv', 'customers.csv',
                    'rental.csv')

        rental_list = []

        rental_list = show_rentals('p00001')

        gold = [{
            'Customer_ID': 'c00001',
            'Name': 'Danny Holme',
            'Home_Address': '231 Richland Street, Santa Ana, CA, 33133',
            'Phone_Number': '253-111-8988',
            'Email_Address': '*****@*****.**'
        }, {
            'Customer_ID': 'c00007',
            'Name': 'Bettey White',
            'Home_Address': '232 Mohuland Drive, Hollywood, CA, 98546',
            'Phone_Number': '555-444-4444',
            'Email_Address': '*****@*****.**'
        }]

        for r, g in zip(rental_list, gold):
            self.assertDictEqual(r, g)

        self.assertEqual(len(rental_list), 2)
Exemplo n.º 16
0
def test_show_rentals(mongo_database):
    d.import_data(mongo_database, '', 'product.csv', 'customer.csv',
                  'rental.csv')

    result = d.show_rentals(mongo_database, 'P000004')

    assert len(result) == 2
    assert list(result.keys()) == ['C000002', 'C000004']
Exemplo n.º 17
0
 def test_show_available_products(self):
     """test show available products function"""
     import_data('csvfiles', 'products.csv', 'customers.csv', 'rentals.csv')
     actual = show_available_products()
     expected = {"prd001": {"description": "60-in tv",
                            "product_type": "livingroom",
                            "quantity_available": "3"}}
     self.assertEqual(actual, expected)
Exemplo n.º 18
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) == 7
    assert "prd001" in result
    assert "prd002" not in result
Exemplo n.º 19
0
 def test_show_rentals(self):
     """tests show rentals function"""
     import_data('csvfiles', 'products.csv', 'customers.csv', 'rentals.csv')
     actual = show_rentals('prd001')
     expected = {"user001": {"name": "Elisa Miles", "address": "4490 Union Street",
                             "phone_number": "206-922-0882",
                             "email": "*****@*****.**"}}
     self.assertEqual(actual, expected)
Exemplo n.º 20
0
def test_show_available_products(mongo_database):
    d.import_data(mongo_database, '', 'product.csv', 'customer.csv',
                  'rental.csv')
    result = d.show_available_products(mongo_database)

    assert len(result) == 9999
    assert 'P000001' in result
    assert 'P010999' not in result
Exemplo n.º 21
0
 def test_import_data(self):
     with patch("builtins.input", side_effect=("yes", "yes")):
         a = db.import_data("data_files", "products", "customers",
                            "rentals")
         self.assertEqual(a, ((1, 1, 1), (0, 0, 0)))
         b = db.import_data("Willy", "wonka", "and",
                            "the choccolate factory")
         self.assertEqual(b, ((0, 0, 0), (1, 1, 1)))
Exemplo n.º 22
0
 def test_get_timing_data(self):
     """ Unit test for the show_available_products function """
     database.drop_all_collections()
     database.import_data("../csv_files", "products.csv", "customers.csv",
                          "rentals.csv")
     database.show_available_products()
     database.show_rentals("005")
     database.drop_all_collections()
Exemplo n.º 23
0
def test_clear_data(mongo_database):
    d.import_data(mongo_database, '', 'product.csv', 'customer.csv',
                  'rental.csv')
    result = sorted(mongo_database.list_collection_names())
    assert result == ['customers', 'products', 'rentals']

    d.clear_data(mongo_database)
    result2 = mongo_database.list_collection_names()
    assert result2 == []
Exemplo n.º 24
0
def test_import_data():
    d.import_data("", "products.csv", "customers.csv", "rentals.csv")
    results = d.show_available_products()

    assert results['1']['description'] == "Playstation 4"
    assert results['2']['description'] == "Xbox One"
    assert results['4']['description'] == "Coca-Cola 20 oz"
    assert results['5']['description'] == "Mountain Dew"
    assert results['6']['description'] == "Pepsi"
Exemplo n.º 25
0
 def test_show_rentals(self):
     """Function to test the return of user details for a product that is rented"""
     database.import_data(directory_name, "products.csv", "customers.csv", "rentals.csv")
     expected_data = {'UID103': {'*****@*****.**', '3 Seattle Dr', 'Dom'},
                      'UID105': {'5 Vincent dr', 'Dan', '*****@*****.**'},
                      'UID101': {'1 Redmond dr', 'Sam', '*****@*****.**'}}
     actual_data = database.show_rentals("p101")
     database.drop_collections()
     self.assertEqual(expected_data, actual_data)