def test_positive_result_samples_from_mongo_throws_for_error_creating_db( config): with patch( "migrations.helpers.update_filtered_positives_helper.get_mongo_db" ) as mongo_db: mongo_db.side_effect = NotImplementedError("Boom!") with pytest.raises(NotImplementedError): positive_result_samples_from_mongo(config, [])
def test_positive_result_samples_from_mongo_returns_expected_samples( config, testing_samples): plate_barcodes = ["123"] expected_samples = testing_samples[: 1] # only the first sample is positive, with matching plate barcode result = positive_result_samples_from_mongo(config, plate_barcodes) assert result == expected_samples
def run(settings_module: str = "", omit_dart: bool = False) -> None: """Updates filtered positive values for all positive samples in pending plates Arguments: settings_module {str} -- settings module from which to generate the app config omit_dart {bool} -- whether to omit DART queries/updates from the process """ config, settings_module = get_config(settings_module) logging.config.dictConfig(config.LOGGING) logger.info("-" * 80) logger.info("STARTING FILTERED POSITIVES UPDATE") logger.info(f"Time start: {datetime.now()}") num_pending_plates = 0 num_pos_samples = 0 num_non_cp_pos_samples = 0 mongo_updated = False mlwh_updated = False dart_updated = False try: samples = [] if omit_dart: # Get positive result samples from Mongo logger.warning("Omitting DART from this update") samples = positive_result_samples_from_mongo(config) else: # Get barcodes of pending plates in DART logger.info("Selecting pending plates from DART...") pending_plate_barcodes = pending_plate_barcodes_from_dart(config) if num_pending_plates := len(pending_plate_barcodes): logger.info( f"{num_pending_plates} pending plates found in DART") # Get positive result samples from Mongo in these pending plates logger.info( "Selecting postive samples in pending plates from Mongo..." ) samples = positive_result_samples_from_mongo( config, pending_plate_barcodes) else:
def test_positive_result_samples_from_mongo_returns_expected_samples_no_plate_barcodes(config, testing_samples): expected_samples = [testing_samples[0], testing_samples[-1]] # only the first and last samples are positive result = positive_result_samples_from_mongo(config) assert result == expected_samples
def test_positive_result_samples_from_mongo_throws_for_error_finding_samples(config, mock_mongo_collection): mock_mongo_collection().aggregate.side_effect = Exception("Boom!") with pytest.raises(Exception): positive_result_samples_from_mongo(config, [])
def test_positive_result_samples_from_mongo_throws_for_error_getting_collection(config, mock_mongo_collection): mock_mongo_collection.side_effect = ValueError("Boom!") with pytest.raises(ValueError): positive_result_samples_from_mongo(config, [])
def test_positive_result_samples_from_mongo_throws_for_errors_creating_client(config, mock_mongo_client): mock_mongo_client.side_effect = Exception("Boom!") with pytest.raises(Exception): positive_result_samples_from_mongo(config, [])