def test_update_filtered_positives_omitting_dart_outputs_success( mock_helper_imports, mock_filter_out_cherrypicked_samples, mock_update_positives, mock_helper_database_updates ): _, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock a successful update mock_get_positive_samples.return_value = [{"plate_barcode": "123"}, {"plate_barcode": "456"}] non_cp_samples = [{"plate_barcode": "123"}] mock_filter_out_cherrypicked_samples.return_value = non_cp_samples mock_update_mongo.return_value = True mock_update_mlwh.return_value = True mock_update_dart.return_value = True version = "v2.3" mock_pos_id = MagicMock() type(mock_pos_id).version = PropertyMock(return_value=version) with patch("migrations.update_filtered_positives.current_filtered_positive_identifier", return_value=mock_pos_id): with patch("migrations.update_filtered_positives.datetime") as mock_datetime: timestamp = datetime.utcnow() mock_datetime.utcnow.return_value = timestamp # call the migration update_filtered_positives.run("crawler.config.integration", True) # ensure expected database calls config, _ = get_config("crawler.config.integration") mock_update_mongo.assert_called_once() mock_update_mongo.assert_called_with(config, non_cp_samples, version, timestamp) mock_update_mlwh.assert_called_once() mock_update_mlwh.assert_called_with(config, non_cp_samples) mock_update_dart.assert_not_called()
def test_update_filtered_positives_catches_aborts_failing_updating_samples_in_dart( mock_helper_imports, mock_remove_cherrypicked, mock_update_positives, mock_helper_database_updates): mock_get_plate_barcodes, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock updating the samples in dart to fail mock_get_plate_barcodes.return_value = ["123", "456"] mock_get_positive_samples.return_value = [{ "plate_barcode": "123" }, { "plate_barcode": "456" }] mock_remove_cherrypicked.return_value = [{"plate_barcode": "123"}] mock_update_mongo.return_value = True mock_update_mlwh.return_value = True mock_update_dart.return_value = False # call the migration update_filtered_positives.run("crawler.config.integration") # ensure expected database calls mock_update_mongo.assert_called_once() mock_update_mlwh.assert_called_once() mock_update_dart.assert_called_once()
def test_update_filtered_positives_aborts_with_no_pending_plate_barcodes( mock_helper_imports, mock_helper_database_updates): mock_get_plate_barcodes, _ = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock to return no pending plate barcodes mock_get_plate_barcodes.return_value = [] # call the migration update_filtered_positives.run("crawler.config.integration") # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_catches_error_fetching_pending_plate_barcodes( mock_helper_imports, mock_helper_database_updates): mock_get_plate_barcodes, _ = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock fetching pending plate barcodes to throw mock_get_plate_barcodes.side_effect = ValueError("Boom!") # call the migration update_filtered_positives.run("crawler.config.integration") # ensure no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_omitting_dart_aborts_with_no_positive_samples_fetched_from_mongo( mock_helper_imports, mock_helper_database_updates): _, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock no positive samples mock_get_positive_samples.return_value = [] # call the migration update_filtered_positives.run("crawler.config.integration", True) # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_omitting_dart_catches_error_pending_positive_samples( mock_helper_imports, mock_helper_database_updates): _, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock getting positive samples to throw mock_get_positive_samples.side_effect = NotImplementedError("Boom!") # call the migration update_filtered_positives.run("crawler.config.integration", True) # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_catches_error_pending_positive_samples( mock_helper_imports, mock_helper_database_updates): mock_get_plate_barcodes, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock a pending plate, but getting associated positive samples to throw mock_get_plate_barcodes.return_value = ["ABC123"] mock_get_positive_samples.side_effect = NotImplementedError("Boom!") # call the migration update_filtered_positives.run("crawler.config.integration") # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_aborts_with_no_positive_samples_fetched_from_mongo( mock_helper_imports, mock_helper_database_updates): mock_get_plate_barcodes, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock a pending plate, but no associated positive samples mock_get_plate_barcodes.return_value = ["barcode with no matching sample"] mock_get_positive_samples.return_value = [] # call the migration update_filtered_positives.run("crawler.config.integration") # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_aborts_with_no_non_cherrypicked_samples( mock_helper_imports, mock_filter_out_cherrypicked_samples, mock_helper_database_updates ): mock_get_plate_barcodes, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock removing cherrypicked samples to throw mock_get_plate_barcodes.return_value = ["123", "456"] mock_get_positive_samples.return_value = [{"plate_barcode": "123"}, {"plate_barcode": "456"}] mock_filter_out_cherrypicked_samples.return_value = [] # call the migration update_filtered_positives.run("crawler.config.integration") # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_catches_error_updating_samples_in_mongo( mock_helper_imports, mock_filter_out_cherrypicked_samples, mock_update_positives, mock_helper_database_updates ): mock_get_plate_barcodes, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock updating the samples in mongo to throw mock_get_plate_barcodes.return_value = ["123", "456"] mock_get_positive_samples.return_value = [{"plate_barcode": "123"}, {"plate_barcode": "456"}] mock_filter_out_cherrypicked_samples.return_value = [{"plate_barcode": "123"}] mock_update_mongo.side_effect = NotImplementedError("Boom!") # call the migration update_filtered_positives.run("crawler.config.integration") # ensure expected database calls mock_update_mongo.assert_called_once() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def test_update_filtered_positives_catches_error_determining_filtered_positive_results( mock_helper_imports, mock_filter_out_cherrypicked_samples, mock_update_positives, mock_helper_database_updates ): mock_get_plate_barcodes, mock_get_positive_samples = mock_helper_imports mock_update_mongo, mock_update_mlwh, mock_update_dart = mock_helper_database_updates # mock determining the filtered positive fields to throw mock_get_plate_barcodes.return_value = ["123", "456"] mock_get_positive_samples.return_value = [{"plate_barcode": "123"}, {"plate_barcode": "456"}] mock_filter_out_cherrypicked_samples.return_value = [{"plate_barcode": "123"}] mock_update_positives.side_effect = NotImplementedError("Boom!") # call the migration update_filtered_positives.run("crawler.config.integration") # ensure that no databases are updated mock_update_mongo.assert_not_called() mock_update_mlwh.assert_not_called() mock_update_dart.assert_not_called()
def migration_update_filtered_positives(): print("Running update_filtered_positives migration") omit_dart = sys.argv[2] == "omit_dart" if 2 < len(sys.argv) else False update_filtered_positives.run(omit_dart=omit_dart)