Esempio n. 1
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)
Esempio n. 2
0
    def test_show_rentals(self):
        """Test database.show_rentals"""

        _, _ = database.import_data(DATA_DIR, PRODUCTS, CUSTOMERS, RENTALS)

        if "prodX" not in self.product_data:
            self.assertEqual({}, database.show_rentals("prodX"))
        else:
            raise NameError(
                "Test case invalid - 'prodX' exists as a product key")

        # Compute correct rental data
        for product in self.product_keys:
            correct = {}
            for entry in self.rental_data:
                user, prod, qty = entry[USER_ID], entry[PROD_ID], entry[
                    RENT_QTY]
                if prod == product:  # Add as rental for this product
                    correct[user] = self.customer_data[user]
                    try:
                        correct[user].pop(USER_ID)
                    except KeyError:
                        pass

            self.assertEqual(correct, database.show_rentals(product))
Esempio n. 3
0
    def test_show_rentals(self):
        """ test show_rentals function """
        result = db.show_rentals("prd002")
        self.assertEqual(
            result, {
                'user001': {
                    'name': 'Albert Einstein',
                    'address': '7 Vine Drive, Cleveland, TN 37312',
                    'phone_number': '559-555-0107',
                    'email': '*****@*****.**'
                },
                'user004': {
                    'name': 'Enrico Fermi',
                    'address': '468 Wilson St., Solon, OH 44139',
                    'phone_number': '567-555-0199',
                    'email': '*****@*****.**'
                },
                'user005': {
                    'name': 'Jane Goodall',
                    'address': '52 S. Summer St., Littleton, CO 80123',
                    'phone_number': '970-555-0171',
                    'email': '*****@*****.**'
                }
            })

        with patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            db.drop_database(DATABASE)
            result = db.show_rentals("prd002")
            self.assertEqual(result, {})
            self.assertEqual(fake_stdout.getvalue().strip(),
                             f'Database {DATABASE} not found.')
Esempio n. 4
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()
Esempio n. 5
0
def test_show_rentals():
    """
    returns dict with user id, name, address, phone number, email
    """
    prod2_rentals = database.show_rentals('prd002')
    assert (item for item in prod2_rentals if item['name'] == 'Shirlene Harris')
    prod00X_rentals = database.show_rentals('prodX')
    assert prod00X_rentals == []
Esempio n. 6
0
    def test_show_rentals_works(self):
        """
        Test that we can retrieve customers who have rented a given product.
        """
        products = [
            {'product_id': 'p0', 'description': 'Gum',
             'product_type': 'Candy', 'quantity_available': '5'},
            {'product_id': 'p1', 'description': 'Atomic Fireball',
             'product_type': 'Candy', 'quantity_available': '0'},
        ]
        db.DATABASE['product'].insert_many(products)

        customers = [
            {'customer_id': 'c0', 'first_name': 'Mickey',
             'last_name': 'Mouse', 'address': '123 4th Ave',
             'phone': 1234567890, 'email': '*****@*****.**'},
            {'customer_id': 'c1', 'first_name': 'Minnie',
             'last_name': 'Mouse', 'address': '234 5th Ave',
             'phone': 2345678901, 'email': '*****@*****.**'},
            {'customer_id': 'c2', 'first_name': 'Donald',
             'last_name': 'Duck', 'address': '345 6th Ave',
             'phone': 3456789012, 'email': '*****@*****.**'}
        ]
        db.DATABASE['customer'].insert_many(customers)

        rentals = [
            {'rental_id': 'r0', 'customer_id': 'c0', 'product_id': 'p0'},
            {'rental_id': 'r1', 'customer_id': 'c2', 'product_id': 'p0'},
            {'rental_id': 'r2', 'customer_id': 'c1', 'product_id': 'p1'},
            {'rental_id': 'r3', 'customer_id': 'c2', 'product_id': 'p1'}
        ]
        db.DATABASE['rental'].insert_many(rentals)

        p0_renters = db.show_rentals('p0')
        self.assertEqual(p0_renters,
                         {'c0': {'name': 'Mickey Mouse',
                                 'address': '123 4th Ave',
                                 'phone_number': 1234567890,
                                 'email': '*****@*****.**'},
                          'c2': {'name': 'Donald Duck',
                                 'address': '345 6th Ave',
                                 'phone_number': 3456789012,
                                 'email': '*****@*****.**'},
                          })

        p1_renters = db.show_rentals('p1')
        self.assertEqual(p1_renters,
                         {'c1': {'name': 'Minnie Mouse',
                                 'address': '234 5th Ave',
                                 'phone_number': 2345678901,
                                 'email': '*****@*****.**'},
                          'c2': {'name': 'Donald Duck',
                                 'address': '345 6th Ave',
                                 'phone_number': 3456789012,
                                 'email': '*****@*****.**'},
                          })
Esempio n. 7
0
 def test_show_rentals(self):
     """Test for show_rentals function from database.py"""
     client = MongoClient()
     db = client['database']
     customer = db['customer']
     rentals = db['rentals']
     add_data(customer, 'customers.csv')
     add_data(rentals, 'rentals.csv')
     test_result = show_rentals(db, '6921')
     self.assertTrue('AP987' in test_result)
     test_result2 = show_rentals(db, '2953')
     self.assertTrue('AP990' in test_result2)
     test_result3 = show_rentals(db, '0000')
     self.assertEqual(None, test_result3)
     drop_all(db)
 def test_show_rentals(self):
     '''Test show rentals'''
     db.import_data('tests', 'products', 'customers', 'rentals')
     result = db.show_rentals('prd001')
     expected = {
         'user002': {
             'name': 'Maya Data',
             'address': '4936 Elliot Avenue',
             'phone_number': '206-777-1927',
             'email': '*****@*****.**'
         }
     }
     self.assertEqual(expected, result)
     # Tests for non-existant product
     result = db.show_rentals('prd003')
     self.assertEqual({}, result)
 def test_show_rentals_empty(self):
     '''
     Test method to confirm behavior when product with no rentals is
     queried
     '''
     self.load_data()
     self.assertEqual({}, show_rentals('prd999'))
Esempio n. 10
0
    def test_show_rentals(self):
        """
        Validates that show_rentals returns the expected dictionary
        """
        hold_connection = Database.MongoDBConnection
        hold_hp = Database.HPNorton

        Database.MongoDBConnection = MockMongoDBConnection
        Database.HPNorton = MockHpNorton

        rentals = Database.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])

        Database.MongoDBConnection = hold_connection
        Database.HPNorton = hold_hp
Esempio n. 11
0
def test_show_rentals(_show_rentals):
    students_response = l.show_rentals("prd010")
    assert students_response == _show_rentals

    with l.MONGO:
        TO_DROP = l.MONGO.connection
        TO_DROP.drop_database("assignment_05")
Esempio n. 12
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"]
    def test_show_rentals(self):
        """Tests a database query to return a dictionary of customers
         who have rented a certain product"""
        current_dir = os.getcwd()
        path = current_dir + r"\data_files"
        clear_db()
        import_data(path, "customer_data.csv", "product_data.csv",
                    "rental_data.csv")

        expected_dict2 = {
            "1001": {
                "address": "35 Kentucky Rd",
                "email_address": "*****@*****.**",
                "name": "Jim Beam",
                "phone_number": "111-222-3333"
            },
            "1004": {
                "address": "66934 Redmond Way",
                "email_address": "*****@*****.**",
                "name": "Harry Henderson",
                "phone_number": "444-555-6666"
            }
        }

        renters_test = show_rentals("2002")
        self.assertEqual(renters_test, expected_dict2)
Esempio n. 14
0
 def test_integration_database(self):
     """Integration test to ensure items can be added and queried correctly"""
     clear_test_collections()
     with patch.object(MongoDBConnection,
                       'set_collection_names',
                       return_value=TEST_DB_NAMES):
         import_data = database.import_data('', 'Products.csv',
                                            'Customers.csv', 'Rentals.csv')
     self.assertEqual([(4, 3, 4), (0, 0, 0)], import_data)
     item_1 = {
         'description': 'Computer keyboard',
         'product_type': 'office',
         'quantity_available': '100'
     }
     with patch.object(MongoDBConnection,
                       'set_collection_names',
                       return_value=TEST_DB_NAMES):
         available_products = database.show_available_products()
     self.assertEqual(item_1, available_products['prd0001'])
     with patch.object(MongoDBConnection,
                       'set_collection_names',
                       return_value=TEST_DB_NAMES):
         rental_customers_1 = database.show_rentals('prd00001')
     customer_1 = {
         'name': 'Matt Walker',
         'address': '5478 17th St',
         'phone_number': '555-154-4848',
         'email': '*****@*****.**'
     }
     self.assertEqual(customer_1, rental_customers_1['user0001'])
     self.assertEqual(2, len(rental_customers_1))
 def test_show_rentals(self):
     """ Tests function to show renter info """
     expected = {"user003": {"name": "John Doe", "address": "4532 2nd Ave", "phone_number": \
                 "206-415-5241", "email": "*****@*****.**"}, "user004": {"name": \
                 "Jane Young", "address": "3234 Belmont Ave", "phone_number": "206-245-4511", \
                 "email": "*****@*****.**"}}
     self.assertEqual(expected, show_rentals("prd007"))
Esempio n. 16
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)
Esempio n. 17
0
 def test_show_rentals(self):
     '''testing show_rentals function'''
     LOGGER.info('testing show_rentals function')
     my_dict = show_rentals('p123')
     expected_dict = {
         'c345': {
             'address': '',
             'email': '',
             'name': 'Fred Armisen',
             'phone_number': '2065647382'
         },
         'c876': {
             'address': '9876 Imaginary Dr W.',
             'email': '*****@*****.**',
             'name': 'Tim Eager',
             'phone_number': '3609208765'
         },
         'c987': {
             'address': '13462 Doesnexist St W.',
             'email': '*****@*****.**',
             'name': 'Sam Jones',
             'phone_number': '4259876543'
         }
     }
     self.assertEqual(my_dict, expected_dict)
     LOGGER.info('show_rentals tests sucessful')
Esempio n. 18
0
def main():
    """
    Ensure you application will create an empty database if one doesn’t exist
    when the app is first run. Call it customers.db
    """

    # Standalone function to initialize logging
    logger.add(stdout, level='WARNING')
    logger.add("logfile_{time}.txt", level='INFO')
    logger.enable(__name__)

    with Connection():
        util_drop_all()

    ingest_customer_csv(CSV_PATH_DBG + CUST_CSV_FILENAME)
    ingest_product_csv(CSV_PATH_DBG + PROD_CSV_FILENAME)
    ingest_rental_csv(CSV_PATH_DBG + RNTL_CSV_FILENAME)

    db_dict = show_available_products()

    print(db_dict)

    db_dict = show_rentals('prd002')

    print(db_dict)
    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'])
 def test_bad_show_rentals(self):
     '''
     Test method to ensure bad mongo DB connection is properly handled
     '''
     mongo = create_mongo_connection(host='127.0.0.1', port=27018)
     rentals_dict = show_rentals('prd001', mongo)
     self.assertEqual(rentals_dict, {})
Esempio n. 21
0
def main():
    """
    Ensure you application will create an empty database if one doesn’t exist
    when the app is first run. Call it customers.db
    """

    print("Start linear ingest from CSV files")

    ret_list_linear = linear()

    print("Start parallel ingest from CSV files")

    ret_list_parallel = parallel()

    print("CSV ingest completed")

    result = show_rentals('P000003')
    print(result)

    print("Linear ingest statistics:")
    for docstats in ret_list_linear:
        print(f"{docstats[0]} doc: num  records: {docstats[3]}")
        print(f"{docstats[0]} doc: time elapsed: {docstats[4]}")

    print("Parallel ingest statistics:")
    for docstats in ret_list_parallel:
        print(f"{docstats[0]} doc: num  records: {docstats[3]}")
        print(f"{docstats[0]} doc: time elapsed: {docstats[4]}")
Esempio n. 22
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)
Esempio n. 23
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']
def test_show_rentals():
    show_rentals = db.show_rentals('P000259')

    assert len(show_rentals) == 6

    with db.MONGO:
        TO_DROP = db.MONGO.connection
        TO_DROP.drop_database("assignment_10")
Esempio 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)
    def test_clear_database(self):
        """Tests if all data will be removed from HP Norton database."""

        database.clear_database()

        test = database.show_rentals()
        expected = {}

        self.assertEqual(test, expected)
Esempio n. 27
0
    def test_show_rentals(self):
        '''Test show_available_products function'''
        database.clear_all()
        database.import_data(PATH, 'products.csv', 'customers.csv',
                             'rentals.csv')

        expected_1 = {
            'c004': {
                'name': 'Sokka',
                'address': 'Southern Water Tribe',
                'phone_number': '1-206-444-4444',
                'email': '*****@*****.**'
            },
            'c005': {
                'name': 'Toph',
                'address': 'Southern Earth Kingdom',
                'phone_number': '1-206-555-5555',
                'email': '*****@*****.**'
            }
        }

        expected_2 = {
            'c006': {
                'name': 'Zuko',
                'address': 'Fire Nation',
                'phone_number': '1-206-666-6666',
                'email': '*****@*****.**'
            },
            'c001': {
                'name': 'Aang',
                'address': 'Eastern Air Temple',
                'phone_number': '1-206-111-1111',
                'email': '*****@*****.**'
            }
        }

        dict_test_1 = database.show_rentals('p004')  # meat jerky
        dict_test_2 = database.show_rentals('p006')  # blue mask

        self.assertEqual(expected_1, dict_test_1)
        self.assertEqual(expected_2, dict_test_2)

        database.clear_all()
    def test_show_rentals(self):
        """
        Test that show_rentals(product_id) satisfies the following requirement:
            Returns a Python dictionary with the following user information from users that have
            rented products matching product_id:
                user_id
                name
                address
                phone_number
                email
        """
        test_dict1 = database.show_rentals('1')

        # Check an empty collection returns an empty dict
        self.assertDictEqual(test_dict1, {})

        # Add rentals and check we return the added rentals by prod_id
        directory_path = 'C:/Users/USer/Documents/UW_Python_Certificate/Course_2/' \
                         'SP_Python220B_2019/students/franjaku/lesson05/data_files'
        database.import_data(directory_path, 'product_data.csv',
                             'customer_data.csv', 'rental_data.csv')

        test_dict2 = database.show_rentals('1')

        expected_dict = {
            'rental_2': {
                'customer_id': '2',
                'name': 'Jon',
                'address': '1900 43rd Ave E, Seattle WA 98112',
                'phone_number': '538-987-0245',
                'email': '*****@*****.**'
            },
            'rental_3': {
                'customer_id': '1',
                'name': 'Jim',
                'address': '105 Main Street, Seattle WA 98109',
                'phone_number': '254-553-3600',
                'email': '*****@*****.**'
            }
        }

        self.assertDictEqual(test_dict2, expected_dict)
 def test_d_show_rentals(self):
     expected = {
         "user001": {
             "name": "Elisa Miles",
             "address": "4490 Union Street",
             "phone": "206-922-0882",
             "email": "*****@*****.**"
         }
     }
     actual = database.show_rentals('prd002')
     self.assertEqual(actual, expected)
Esempio n. 30
0
 def test_show_rentals(self):
     import_data('input_csv', 'products.csv', 'customer.csv', 'rentals.csv')
     results = show_rentals('prd003')
     self.assertEqual(
         results, {
             'user001': {
                 'name': 'Elisa Miles',
                 'address': '4490 Union Street',
                 'phone_number': '206-922-0882',
                 'email': '*****@*****.**'
             }
         })