Beispiel #1
0
 def tearDown(self):
     """Teardown of test database."""
     mongo = MongoDBConnection()
     with mongo:
         test_database = mongo.connection[TEST_DATABASE]
         test_database['rentals'].drop()
         test_database['customers'].drop()
         test_database['products'].drop()
Beispiel #2
0
 def tearDown(cls):
     '''
     Drop mongo collections after each test to ensure a fresh start
     '''
     mongo = MongoDBConnection()
     with mongo:
         db = mongo.connection.HPNorton
         db['product'].drop()
         db['customer'].drop()
         db['rentals'].drop()
def database_setup():
    """function for setting up clean table each time"""
    mongo = MongoDBConnection()
    with mongo:
        database = mongo.connection.myDB

    for collection in database.list_collection_names():
        database[collection].drop()

    return database
def clear_db():
    mongo = MongoDBConnection()

    with mongo:
        db = mongo.connection.media
        product_db = db['product']
        customer_db = db['customer']
        rentals_db = db['rentals']
        product_db.drop()
        customer_db.drop()
        rentals_db.drop()
Beispiel #5
0
def clear_db():
    '''func to clear database of entries'''
    mongo = MongoDBConnection()

    with mongo:
        db = mongo.connection.media
        product_db = db['product']
        customer_db = db['customer']
        rentals_db = db['rentals']
        product_db.drop()
        customer_db.drop()
        rentals_db.drop()
Beispiel #6
0
 def test_write_many_to_database(self):
     """Unit test of the write_many_to_database function."""
     entry_count = write_many_to_database(TEST_DATABASE, 'write_test',
                                          deepcopy(rental_list))
     self.assertEqual(entry_count, 8)
     result_list = []
     mongo = MongoDBConnection()
     with mongo:
         query = mongo.connection[TEST_DATABASE]['write_test'].find()
         for item in query:
             del item['_id']
             result_list.append(item)
         mongo.connection[TEST_DATABASE]['write_test'].drop()
     self.assertListEqual(result_list, rental_list)
Beispiel #7
0
 def setUp(self):
     """Setup for all unit tests"""
     self.product_fields = ('product_id', 'description', 'product_type',
                            'quantity_available')
     self.customer_fields = ('customer_id', 'name', 'address',
                             'phone_number', 'email')
     self.rental_fields = ('rental_id', 'product_id', 'customer_id',
                           'rental_start', 'rental_end')
     for item in product_list:
         item['quantity_available'] = int(item['quantity_available'])
     mongo = MongoDBConnection()
     with mongo:
         test_database = mongo.connection[TEST_DATABASE]
         test_database['rentals'].insert_many(deepcopy(rental_list))
         test_database['customers'].insert_many(deepcopy(customer_list))
         test_database['products'].insert_many(deepcopy(product_list))
def setup_db(request):
    mongo = MongoDBConnection()
    with mongo:
        db = mongo.connection.furniture
        db.product_data.drop()
        db.customer_data.drop()
        db.rental_data.drop()
        files = ["customer_data.csv", "product_data.csv", "rental_data.csv"]
        test_import_result = [import_data("dat", file) for file in files]

        def cleanup():
            db.product_data.drop()
            db.customer_data.drop()
            db.rental_data.drop()

        request.addfinalizer(cleanup)
Beispiel #9
0
def test_connection():
    with pytest.raises(AttributeError):
        mongo_test = MongoDBConnection(host='')
        with mongo_test:
            db = mongo_test.connection.furniture