def test_source_plate_uuid_value(app, source_plates):
    with app.app_context():
        with raises(ValidationError):
            SourcePlateUUID(PlateBarcode({})).value
            SourcePlateUUID(PlateBarcode({"test": "another test"})).value

        with raises(Exception):
            SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "1234"})).value

        uuid = source_plates[0][FIELD_LH_SOURCE_PLATE_UUID]

        assert SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "plate_123"})).value == uuid
def test_samples_with_cog_uk_id_from_destination_add_to_warehouse(
    app,
    run_id,
    centres,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mlwh_samples_in_cherrytrack,
    mocked_responses,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
    baracoda_mock_barcodes_group,
    baracoda_mock_responses,
):
    with app.app_context():
        samples, _ = samples_from_cherrytrack_into_mongo
        instance = SamplesWithCogUkId(
            SamplesFromDestination(WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode})))
        )
        message = WarehouseMessage("mytype", "myuuid", "at some point")
        instance.add_to_warehouse_message(message)
        assert message._subjects == [
            {
                "friendly_name": "aRootSampleId1__DS000050001_A01__centre_1__Positive",
                "role_type": "sample",
                "subject_type": "sample",
                "uuid": "aLighthouseUUID1",
            },
            {
                "friendly_name": "aRootSampleId3__DS000050001_A03__centre_1__Positive",
                "role_type": "sample",
                "subject_type": "sample",
                "uuid": "aLighthouseUUID3",
            },
        ]
def test_all_samples_from_destination_value_fails_with_unknown_samples(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    cherrytrack_destination_plate_response,
    mocked_responses,
    cherrytrack_mock_destination_plate,
):
    with app.app_context():
        instance = SamplesFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        )
        assert instance.is_valid() is True
        assert instance.errors == []

        with pytest.raises(Exception):
            instance.value

        assert instance.is_valid() is False
        assert instance.errors == [
            (
                "Exception during retrieval: Some samples cannot be obtained because they are not present"
                " in Mongo. Please review: ['unknown']"
            )
        ]
def test_source_plates_from_destination_add_to_warehouse(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mocked_responses,
    source_plates,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
):
    with app.app_context():
        instance = SourcePlatesFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        )

        message = WarehouseMessage("mytype", "myuuid", "at some point")
        instance.add_to_warehouse_message(message)
        assert message._subjects == [
            {
                "role_type": "cherrypicking_source_labware",
                "subject_type": "plate",
                "friendly_name": "plate_123",
                "uuid": "a17c38cd-b2df-43a7-9896-582e7855b4cc",
            }
        ]
Example #5
0
    def initialize_event(self, params: Dict[str, str]) -> None:
        super().initialize_event(params=params)
        self._event_type = params["event_type"]

        self.properties["plate_barcode"] = PlateBarcode(params)
        self.properties["failure_type"] = FailureType(params)
        self.properties["user_id"] = UserID(params)

        for property_name in ["plate_barcode", "failure_type", "user_id"]:
            self.properties[property_name].is_valid()

        self.properties["destination_plate"] = self.properties["plate_barcode"]
        self.properties["wells"] = WellsFromDestination(
            self.properties["plate_barcode"])
        self.properties["source_plates"] = SourcePlatesFromDestination(
            self.properties["wells"])
        self.properties["samples"] = SamplesFromDestination(
            self.properties["wells"])
        self.properties["samples_with_cog_uk_id"] = SamplesWithCogUkId(
            self.properties["samples"])
        self.properties["controls"] = ControlsFromDestination(
            self.properties["wells"])

        self.properties["run_id"] = RunIDFromWells(self.properties["wells"])
        self.properties["run_info"] = RunInfo(self.properties["run_id"])
        self.properties["automation_system_name"] = AutomationSystemName(
            self.properties["run_info"])
        self.properties["robot_uuid"] = RobotUUID(
            self.properties["automation_system_name"])
def test_source_plate_uuid_errors(app, source_plates):
    with app.app_context():
        # After success
        source_plate_property = SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "plate_123"}))
        source_plate_property.value
        assert len(source_plate_property.errors) == 0

        # After is_valid false
        source_plate_property = SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "plate _123"}))
        source_plate_property.is_valid()
        assert len(source_plate_property.errors) > 0

        # After retrieval error
        source_plate_property = SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "1234"}))
        with raises(Exception):
            source_plate_property.value

        assert len(source_plate_property.errors) > 0
def test_samples_picked_from_source_valid(app):
    assert (
        SamplesPickedFromSource(
            PlateBarcode({FIELD_EVENT_BARCODE: "aBarcode"}), RunID({FIELD_EVENT_RUN_ID: "5"})
        ).is_valid()
        is True
    )
    assert (
        SamplesPickedFromSource(
            PlateBarcode(
                {
                    "missing_barcode_field": "aBarcode",
                }
            ),
            RunID({FIELD_EVENT_RUN_ID: "5"}),
        ).is_valid()
        is False
    )
def test_wells_from_destination_value_gets_value(
    app,
    run_id,
    destination_barcode,
    mocked_responses,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
):
    with app.app_context():
        val = WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode})).value
        assert val == cherrytrack_destination_plate_response["data"]["wells"]
def test_samples_picked_from_source_no_lh_sample_uuids(
    app, run_id, source_barcode, mocked_responses, cherrytrack_mock_source_plates
):
    with app.app_context():
        with patch("lighthouse.classes.services.mongo.app.data.driver.db.samples") as samples_collection:
            val = SamplesPickedFromSource(
                PlateBarcode({FIELD_EVENT_BARCODE: source_barcode}), RunID({FIELD_EVENT_RUN_ID: run_id})
            ).value

            samples_collection.find.assert_not_called()
            assert val == []
            assert len(val) == 0
def test_samples_picked_from_source_value_unsuccessful(
    app, run_id, source_barcode, mocked_responses, cherrytrack_mock_source_plates
):
    with app.app_context():
        myExc = None
        with raises(Exception) as exc:
            myExc = exc
            SamplesPickedFromSource(
                PlateBarcode({FIELD_EVENT_BARCODE: source_barcode}), RunID({FIELD_EVENT_RUN_ID: run_id})
            ).value

        assert "Response from Cherrytrack is not OK: Failed to get samples for the given source plate barcode." == str(
            myExc.value  # type: ignore
        )
def test_run_id_from_wells_value(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mocked_responses,
    source_plates,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
):
    with app.app_context():
        val = RunIDFromWells(WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))).value

        assert val == 5
def test_all_controls_from_destination_value_gets_value(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mocked_responses,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
):
    with app.app_context():
        wells = cherrytrack_destination_plate_response["data"]["wells"]
        val = ControlsFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        ).value

        assert val == {"E10": wells[2], "E11": wells[3]}
def test_all_samples_successful(
    app,
    source_barcode,
    samples_from_cherrytrack_into_mongo,
):
    with app.app_context():
        val = SamplesFromSource(PlateBarcode({FIELD_EVENT_BARCODE: source_barcode})).value
        samples, _ = samples_from_cherrytrack_into_mongo

        for elem in val:
            del elem["_id"]
            del elem["Date Tested"]
        for elem in samples:
            del elem["_id"]
            del elem["Date Tested"]

        assert val == samples
    def initialize_event(self, params: Dict[str, str]) -> None:
        super().initialize_event(params=params)

        self._event_type = params["event_type"]

        self.properties["plate_barcode"] = PlateBarcode(params)
        self.properties["run_id"] = RunID(params)

        for property_name in ["plate_barcode", "run_id"]:
            self.properties[property_name].is_valid()

        self.properties["run_info"] = RunInfo(self.properties["run_id"])
        self.properties["source_plate_uuid"] = SourcePlateUUID(self.properties["plate_barcode"])
        self.properties["user_id"] = UserID(self.properties["run_info"])
        self.properties["automation_system_name"] = AutomationSystemName(self.properties["run_info"])
        self.properties["robot_uuid"] = RobotUUID(self.properties["automation_system_name"])
        self.properties["all_samples"] = SamplesFromSource(self.properties["plate_barcode"])
Example #15
0
    def initialize_event(self, params: Dict[str, str]) -> None:
        super().initialize_event(params=params)

        self._event_type = params["event_type"]

        self.properties["plate_barcode"] = PlateBarcode(params)
        self.properties["user_id"] = UserID(params)
        self.properties["robot_serial_number"] = RobotSerialNumber(params)
        self.properties["robot_uuid"] = RobotUUID(self.properties["robot_serial_number"])

        for property_name in ["plate_barcode", "user_id", "robot_serial_number"]:
            self.properties[property_name].is_valid()

        self.properties["source_plate_uuid"] = SourcePlateUUID(self.properties["plate_barcode"])
        self.properties["positive_samples_from_source"] = PositiveSamplesFromSource(
            self.properties["source_plate_uuid"]
        )
    def initialize_event(self, params: Dict[str, str]) -> None:
        super().initialize_event(params=params)

        self._event_type = params["event_type"]

        self.properties["plate_barcode"] = PlateBarcode(params)
        self.properties["user_id"] = UserID(params)
        self.properties["robot_serial_number"] = RobotSerialNumber(params)
        self.properties["robot_uuid"] = RobotUUID(
            self.properties["robot_serial_number"])

        for property_name in [
                "plate_barcode", "user_id", "robot_serial_number"
        ]:
            self.properties[property_name].is_valid()

        self.properties["barcode_no_plate_map_data"] = BarcodeNoPlateMapData(
            params)
    def initialize_event(self, params: Dict[str, str]) -> None:
        super().initialize_event(params=params)

        self._event_type = params["event_type"]

        self.properties["plate_barcode"] = PlateBarcode(params)
        self.properties["run_id"] = RunID(params)

        for property_name in ["plate_barcode", "run_id"]:
            self.properties[property_name].is_valid()

        self.properties["run_info"] = RunInfo(self.properties["run_id"])
        self.properties["user_id"] = UserID(self.properties["run_info"])
        self.properties["automation_system_name"] = AutomationSystemName(
            self.properties["run_info"])
        self.properties["robot_uuid"] = RobotUUID(
            self.properties["automation_system_name"])
        self.properties["barcode_no_plate_map_data"] = BarcodeNoPlateMapData(
            params)
def test_all_controls_from_destination_value_fails_with_missing_controls(
    app,
    destination_barcode,
    mocked_responses,
    cherrytrack_mock_destination_plate,
):
    with app.app_context():
        instance = ControlsFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        )
        assert instance.is_valid() is True
        assert instance.errors == []

        with pytest.raises(Exception):
            instance.value

        assert instance.is_valid() is False
        assert instance.errors == [
            ("Exception during retrieval: We were expecting one positive and one negative control to be present.")
        ]
def test_wells_from_destination_value_fails_with_duplicated_wells(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    cherrytrack_destination_plate_response,
    mocked_responses,
    cherrytrack_mock_destination_plate,
):
    with app.app_context():
        instance = WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        assert instance.is_valid() is True
        assert instance.errors == []

        with pytest.raises(Exception):
            instance.value

        assert instance.is_valid() is False
        assert instance.errors == [
            "Exception during retrieval: Some coordinates have clashing samples/controls: {'H1'}"
        ]
def test_source_plates_from_destination_value_gets_value(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mocked_responses,
    source_plates,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
):
    with app.app_context():
        val = SourcePlatesFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        ).value

        for elem in val:
            del elem["_id"]

        assert val == [
            {"Lab ID": "lab_1", "barcode": "plate_123", "lh_source_plate_uuid": "a17c38cd-b2df-43a7-9896-582e7855b4cc"}
        ]
def test_samples_with_cog_uk_ids_from_destination_add_to_sequencescape(
    app,
    run_id,
    centres,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mlwh_samples_in_cherrytrack,
    mocked_responses,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
    baracoda_mock_barcodes_group,
    baracoda_mock_responses,
):
    with app.app_context():
        samples, _ = samples_from_cherrytrack_into_mongo
        instance = SamplesWithCogUkId(
            SamplesFromDestination(WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode})))
        )
        message = SequencescapeMessage()
        instance.add_to_sequencescape_message(message)
        assert message._contents == {
            "H08": {
                "content": {
                    "name": "DS000050001_A01",
                    "phenotype": "positive",
                    "sample_description": "aRootSampleId1",
                    "supplier_name": "COGUK1",
                    "uuid": "aLighthouseUUID1",
                }
            },
            "H12": {
                "content": {
                    "name": "DS000050001_A03",
                    "phenotype": "positive",
                    "sample_description": "aRootSampleId3",
                    "supplier_name": "COGUK2",
                    "uuid": "aLighthouseUUID3",
                }
            },
        }
def test_all_samples_from_destination_value_gets_value(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    mocked_responses,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
):
    with app.app_context():
        val = SamplesFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        ).value
        samples, _ = samples_from_cherrytrack_into_mongo

        for sample in val.values():
            del sample["_id"]
            del sample["Date Tested"]
        for sample in samples:
            del sample["_id"]
            del sample["Date Tested"]
        assert val == {"H08": samples[0], "H12": samples[2]}
def test_all_samples_from_destination_value_fails_with_duplicated_samples(
    app,
    run_id,
    destination_barcode,
    samples_from_cherrytrack_into_mongo,
    cherrytrack_destination_plate_response,
    mocked_responses,
    cherrytrack_mock_destination_plate,
):
    with app.app_context():
        instance = SamplesFromDestination(
            WellsFromDestination(PlateBarcode({FIELD_EVENT_BARCODE: destination_barcode}))
        )
        assert instance.is_valid() is True
        assert instance.errors == []

        with pytest.raises(Exception):
            instance.value

        assert instance.is_valid() is False
        assert instance.errors == [
            ("Exception during retrieval: There is duplication in the lh sample uuids provided: ['uuid1']")
        ]
def test_samples_picked_from_source_value_successful(
    app,
    run_id,
    source_barcode,
    destination_barcode,
    cherrytrack_source_plates_response,
    mocked_responses,
    cherrytrack_mock_source_plates,
    samples_from_cherrytrack_into_mongo,
):
    with app.app_context():
        val = SamplesPickedFromSource(
            PlateBarcode({FIELD_EVENT_BARCODE: source_barcode}), RunID({FIELD_EVENT_RUN_ID: run_id})
        ).value
        samples, _ = samples_from_cherrytrack_into_mongo

        for elem in val:
            del elem["_id"]
            del elem["Date Tested"]
        for elem in samples:
            del elem["_id"]
            del elem["Date Tested"]
        assert val == [samples[0], samples[2]]
        assert len(val) == 2
def test_source_plate_uuid_new(app, source_plates):
    assert SourcePlateUUID(PlateBarcode({})) is not None
    assert SourcePlateUUID(PlateBarcode({"test": "a test"})) is not None
    assert SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "plate_123"})) is not None
def test_source_plate_uuid_is_valid(app, source_plates):
    assert SourcePlateUUID(PlateBarcode({})).is_valid() is False
    assert SourcePlateUUID(PlateBarcode({"test": "another test"})).is_valid() is False
    assert SourcePlateUUID(PlateBarcode({FIELD_EVENT_BARCODE: "plate_123"})).is_valid() is True