def test_mongodb_all_reports(database): """ Test create/save/read all kind of reports """ all_reports = [(HWPCModel(), gen_hwpc_report), (PowerModel(), gen_power_report)] for model, generator in all_reports: # Load DB mongodb = MongoDB(URI, "test_reports" + model.get_type().__name__, "test_reports" + model.get_type().__name__) mongodb.connect() # Create report report = generator() # Save report mongodb.save(report, model) # Read report mongodb_iter = mongodb.iter(model, False) read_report = next(mongodb_iter) # Compare assert read_report == report
def test_mongodb_read_capped_db(mongo_database): """ Test read mongodb capped collection """ # Load DB mongodb = MongoDB(HWPCReport, MONGO_URI, MONGO_DATABASE_NAME, MONGO_INPUT_COLLECTION_NAME) # Check if we can read one time mongodb.connect() mongodb_iter = mongodb.iter(False) report = None for _ in range(mongodb.collection.count_documents({})): report = next(mongodb_iter) assert report is not None # Check if there is nothing after with pytest.raises(StopIteration) as pytest_wrapped: next(mongodb_iter) assert pytest_wrapped.type == StopIteration # Add data in the collection for _ in range(1): mongodb.save(report) # Check if there is nothing after with pytest.raises(StopIteration) as pytest_wrapped: next(mongodb_iter) assert pytest_wrapped.type == StopIteration
def test_mongodb_read_capped_db(database): """ Test read mongodb capped collection """ # Load DB mongodb = MongoDB(URI, "test_mongodb", "test_mongodb2") # Check if we can read one time mongodb.connect() mongodb_iter = mongodb.iter(HWPCModel(), False) report = None for _ in range(mongodb.collection.count_documents({})): report = next(mongodb_iter) assert report is not None # Check if there is nothing after with pytest.raises(StopIteration) as pytest_wrapped: next(mongodb_iter) assert pytest_wrapped.type == StopIteration # Add data in the collection for _ in range(1): mongodb.save(report, HWPCModel()) # Check if there is nothing after with pytest.raises(StopIteration) as pytest_wrapped: next(mongodb_iter) assert pytest_wrapped.type == StopIteration
def test_mongodb_save_basic_db(database): """ Test save mongodb collection """ # Load DB mongodb = MongoDB(URI, "test_mongodb", "test_mongodb3") mongodb.connect() # Check if save work basic_count = mongodb.collection.count_documents({}) for _ in range(2): mongodb.save(gen_hwpc_report(), HWPCModel()) assert mongodb.collection.count_documents({}) == basic_count + 2
def test_mongodb_save_basic_db(mongo_database): """ Test save mongodb collection """ # Load DB mongodb = MongoDB(HWPCReport, MONGO_URI, MONGO_DATABASE_NAME, MONGO_INPUT_COLLECTION_NAME) mongodb.connect() # Check if save work basic_count = mongodb.collection.count_documents({}) for report in gen_HWPCReports(2): mongodb.save(report) assert mongodb.collection.count_documents({}) == basic_count + 2