示例#1
0
    def test_show_available_products(self):
        """ test show_available_products function """
        result = db.show_available_products()
        self.assertEqual(
            result, {
                'prd001': {
                    'description': '60-inch TV stand',
                    'product_type': 'livingroom',
                    'quantity_available': '3'
                },
                'prd002': {
                    'description': 'L-shaped sofa',
                    'product_type': 'livingroom',
                    'quantity_available': '1'
                },
                'prd005': {
                    'description': 'Nightstand',
                    'product_type': 'bedroom',
                    'quantity_available': '20'
                }
            })

        with patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            db.drop_database(DATABASE)
            result = db.show_available_products()
            self.assertEqual(result, {})
            self.assertEqual(fake_stdout.getvalue().strip(),
                             f'Database {DATABASE} not found.')
示例#2
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()
示例#3
0
 def test_show_available_products(self):
     """Test for show_available_products function from database.py"""
     client = MongoClient()
     db = client['database']
     product = db['product']
     add_data(product, 'products.csv')
     self.assertEqual(4, len(show_available_products(db)))
     test_result = show_available_products(db)
     self.assertTrue('9736' in test_result)
     self.assertTrue('6001' not in test_result)
     drop_all(db)
    def test_show_available_products(self):
        """
        Test that show_available_products() satisfies the following requirement:
            Returns a Python dictionary of products listed as available with the following fields:
                product_id
                description
                product_type
                quantity_available
        Assumes that import_data() works as intended
        """
        test_dict1 = database.show_available_products()

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

        # Add products and check we return the added products
        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_available_products()

        expected_dict = {
            'prod1': {
                'product_id': '1',
                'description': 'Table',
                'product_type': 'Dining Room',
                'quantity_available': '25'
            },
            'prod2': {
                'product_id': '2',
                'description': 'Chair',
                'product_type': 'Dining Room',
                'quantity_available': '654'
            },
            'prod3': {
                'product_id': '3',
                'description': 'Mattress',
                'product_type': 'Bedroom',
                'quantity_available': '200'
            },
            'prod4': {
                'product_id': '4',
                'description': 'Couch',
                'product_type': 'Living Room',
                'quantity_available': '36'
            }
        }
        # print(expected_dict)
        # print(test_dict2)
        self.assertDictEqual(test_dict2, expected_dict)
    def test_available_products(self):
        '''
        Test method to find all available products
        '''
        available_expected = {'prd001': {'description': 'sofa',
                                         'product_type': 'livingroom',
                                         'quantity_available': '4'},
                              'prd002': {'description': 'coffee table',
                                         'product_type': 'livingroom',
                                         'quantity_available': '2'},
                              'prd004': {'description': 'refrigerator',
                                         'product_type': 'kitchen',
                                         'quantity_available': '2'},
                              'prd005': {'description': 'microwave',
                                         'product_type': 'kitchen',
                                         'quantity_available': '5'},
                              'prd006': {'description': 'toaster',
                                         'product_type': 'kitchen',
                                         'quantity_available': '1'},
                              'prd007': {'description': 'night stand',
                                         'product_type': 'bedroom',
                                         'quantity_available': '6'},
                              'prd009': {'description': 'queen mattress',
                                         'product_type': 'bedroom',
                                         'quantity_available': '3'},
                              'prd010': {'description': 'queen box spring',
                                         'product_type': 'bedroom',
                                         'quantity_available': '3'}}

        self.load_data()
        product_dict = show_available_products()

        self.assertEqual(product_dict, available_expected)
示例#6
0
    def test_show_available_products(self):
        """Test show_available_products"""
        # Clear the database
        database.clear()
        expected_data = {
            'prd001': {
                'description': 'table',
                'product_type': 'diningroom',
                'quantity_available': '2'
            },
            'prd002': {
                'description': 'lamp',
                'product_type': 'office',
                'quantity_available': '3'
            },
            'prd003': {
                'description': 'desk',
                'product_type': 'office',
                'quantity_available': '1'
            },
            'prd005': {
                'description': 'shovel',
                'product_type': 'yard',
                'quantity_available': '5'
            }
        }

        database.import_data(os.getcwd(), 'products.csv', 'customers.csv',
                             'rentals.csv')
        return_dict = database.show_available_products()
        self.assertEqual(expected_data, return_dict)
        database.clear()
示例#7
0
    def test_clear_database(self):
        """This tests that the database is cleared """

        database.clear_database()
        real = database.show_available_products()
        expected = {}
        self.assertEqual(real, expected)
示例#8
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)
示例#9
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)
    def test_show_available_product(self):
        """ Test that the dictionary of available products returned is correct.
        """
        available_products = db.show_available_products()

        test_dict = {
            1: {
                'description': 'violet fuzzy velvet sofa',
                'type': 'livingroom',
                'quantity_available': 43
            },
            2: {
                'description': 'that leg lamp from Christmas Story',
                'type': 'lighting',
                'quantity_available': 55
            },
            3: {
                'description': 'giant psychedelic lava lamp',
                'type': 'lighting',
                'quantity_available': 234
            },
            5: {
                'description': 'rotating pink water bed',
                'type': 'bedroom',
                'quantity_available': 2
            }
        }

        self.assertDictEqual(available_products, test_dict)
示例#11
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)
示例#12
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))
示例#13
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)
 def test_bad_show_available(self):
     '''
     Test method to ensure bad mongo DB connection is properly handled
     '''
     mongo = create_mongo_connection(host='127.0.0.1', port=27018)
     product_dict = show_available_products(mongo)
     self.assertEqual(product_dict, {})
    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'])
示例#16
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'
             }
         })
示例#17
0
    def test_show_available_products(self):
        """
        Validates that show_available_products returns the expected dictionary
        """
        hold_connection = Database.MongoDBConnection
        hold_hp = Database.HPNorton

        Database.MongoDBConnection = MockMongoDBConnection
        Database.HPNorton = MockHpNorton

        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, f"ProdID: {products}")

            for key, value in product.items():
                if key == "_id":
                    continue

                self.assertEqual(value, db_product[key])

        Database.MongoDBConnection = hold_connection
        Database.HPNorton = hold_hp
示例#18
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'}})
 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'
         }
     }
     self.assertEqual(result_dict, expected_dict)
     LOGGER.info('available products are %s', result_dict)
     LOGGER.info('test show_available_products tests completed')
示例#20
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())
示例#21
0
 def test_drop_db(self):
     """
     Test drop_db function
     """
     database.drop_db()
     actual = database.show_available_products()
     expected = {}
     self.assertEqual(actual, expected)
示例#22
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
示例#23
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
示例#24
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)
示例#25
0
def test_10show_avail_products():
    db_dict_actual = {
        'prd001': {
            'description': '60-inch TV stand',
            'product_type': 'livingroom',
            'quantity_available': 3
        },
        'prd002': {
            'description': 'L-shaped sofa',
            'product_type': 'livingroom',
            'quantity_available': 0
        },
        'prd003': {
            'description': 'Acacia kitchen table',
            'product_type': 'kitchen',
            'quantity_available': 7
        },
        'prd004': {
            'description': 'Queen bed',
            'product_type': 'bedroom',
            'quantity_available': 10
        },
        'prd005': {
            'description': 'Reading lamp',
            'product_type': 'bedroom',
            'quantity_available': 20
        },
        'prd006': {
            'description': 'Portable heater',
            'product_type': 'bathroom',
            'quantity_available': 14
        },
        'prd007': {
            'description': 'Ballerina painting',
            'product_type': 'livingroom',
            'quantity_available': 0
        },
        'prd008': {
            'description': 'Smart microwave',
            'product_type': 'kitchen',
            'quantity_available': 30
        },
        'prd009': {
            'description': 'Popcorn machine',
            'product_type': 'kitchen',
            'quantity_available': 0
        },
        'prd010': {
            'description': '60-inch TV',
            'product_type': 'livingroom',
            'quantity_available': 3
        }
    }

    db_dict = show_available_products()

    for item in db_dict_actual.keys():
        assert db_dict[item] == db_dict_actual[item]
示例#26
0
 def test_show_available_products(self):
     """ Tests function to show available product data """
     expected = {"prd001": {"desc": "60-inch TV stand", "prod_type": "livingroom", \
                 "qty_avail": "3"}, "prd002": {"desc": "L-shaped sofa", "prod_type": \
                 "livingroom", "qty_avail": "1"}, "prd003": {"desc": "Bar stool", \
                 "prod_type": "kitchen", "qty_avail": "10"}, "prd004": {"desc": \
                 "Bed frame", "prod_type": "bedroom", "qty_avail": "3"}, "prd005": \
                 {"desc": "Desk", "prod_type": "bedroom", "qty_avail": "5"}}
     self.assertEqual(expected, show_available_products())
示例#27
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"
示例#28
0
    def test_show_available_products(self):
        """Test database.show_available_products"""

        self.assertEqual({}, database.show_available_products(),
                         "Nothing so far")

        success, fail = database.import_data(DATA_DIR, PRODUCTS, CUSTOMERS,
                                             RENTALS)

        prods_to_show = database.show_available_products()
        correct = dict(
            zip(prods_to_show, ({
                PROD_DESC: self.product_data[prod][PROD_DESC],
                PROD_TYPE: self.product_data[prod][PROD_TYPE],
                PROD_REMAIN: self.products_remaining[prod]
            } for prod in prods_to_show)))

        self.assertEqual(correct, prods_to_show, "Products to show")
 def test_f_show_available_products(self):
     expected = {
         "prd001": {
             "description": "60-inch TV stand",
             "product_type": "livingroom",
             "quantity_available": "3"
         }
     }
     actual = database.show_available_products()
     self.assertEqual(actual, expected)
示例#30
0
 def test_2_show_available(self):
     """
     Test the integrity of the returned dictionary of available products.  We particularly
     want to validate that quantity_available is deducted to account for existing rentals.
     """
     result = database.show_available_products()
     self.assertEqual(result['SOFA']['quantity_available'], 16)
     self.assertEqual(result['RECLINER']['quantity_available'], 0)
     self.assertEqual(result['DININGTABLE']['quantity_available'], 7)
     self.assertEqual(result['OVEN']['quantity_available'], 4)
     self.assertEqual(result['MOPED']['quantity_available'], 0)