Beispiel #1
0
def test_remove_cherrypicked_samples_returns_input_samples_with_none_cp_samples_df(
        config, testing_samples):
    with patch(
            "migrations.helpers.update_filtered_positives_helper.get_cherrypicked_samples",
            return_value=None):
        with pytest.raises(Exception):
            remove_cherrypicked_samples(config, testing_samples)
Beispiel #2
0
def test_remove_cherrypicked_samples_throws_for_error_getting_cherrypicked_samples(
        config, testing_samples):
    with patch(
            "migrations.helpers.update_filtered_positives_helper.get_cherrypicked_samples",
            side_effect=Exception("Boom!")):
        with pytest.raises(Exception):
            remove_cherrypicked_samples(config, testing_samples)
Beispiel #3
0
def test_remove_cherrypicked_samples_throws_for_error_removing_cp_samples(
        config, testing_samples):
    cp_samples_df = MagicMock()
    type(cp_samples_df).empty = PropertyMock(return_value=False)
    with patch(
            "migrations.helpers.update_filtered_positives_helper.get_cherrypicked_samples",
            return_value=cp_samples_df):
        with patch(
                "migrations.helpers.update_filtered_positives_helper.remove_cp_samples",
                side_effect=Exception("Boom!")):
            with pytest.raises(Exception):
                remove_cherrypicked_samples(config, testing_samples)
Beispiel #4
0
def test_remove_cherrypicked_samples_returns_input_samples_with_empty_cp_samples_df(
        config, testing_samples):
    cp_samples_df = MagicMock()
    type(cp_samples_df).empty = PropertyMock(return_value=True)
    with patch(
            "migrations.helpers.update_filtered_positives_helper.get_cherrypicked_samples",
            return_value=cp_samples_df):
        result = remove_cherrypicked_samples(config, testing_samples)
        assert result == testing_samples
                # 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:
                logger.warning("No pending plates found in DART")

        if num_pos_samples := len(samples):
            logger.info(
                f"{num_pos_samples} matching positive samples found in Mongo")

            # Filter out cherrypicked samples
            logger.info("Filtering out cherrypicked samples...")
            non_cp_pos_pending_samples = remove_cherrypicked_samples(
                config, samples)

            if num_non_cp_pos_samples := len(non_cp_pos_pending_samples):
                logger.info(
                    f"{num_non_cp_pos_samples} non-cherrypicked matching positive samples found"
                )
                filtered_positive_identifier = current_filtered_positive_identifier(
                )
                version = filtered_positive_identifier.version
                update_timestamp = datetime.utcnow()
                logger.info("Updating filtered positives...")
                update_filtered_positive_fields(
                    filtered_positive_identifier,
                    non_cp_pos_pending_samples,
                    version,
                    update_timestamp,