Exemplo n.º 1
0
def test_post_event_no_plate_map_data(
    app,
    client,
    biosero_auth_headers,
    clear_events,
    mocked_rabbit_channel,
    run_id,
    mocked_responses,
    cherrytrack_mock_run_info,
):
    with app.app_context():
        with patch("lighthouse.hooks.events.uuid4",
                   return_value=int_to_uuid(1)):
            with patch("lighthouse.classes.messages.warehouse_messages.uuid4",
                       side_effect=[int_to_uuid(2)]):
                with patch(
                        "lighthouse.classes.events.PlateEvent.message_timestamp",
                        "mytime",
                ):
                    response = client.post(
                        "/events",
                        data={
                            "automation_system_run_id": 3,
                            "barcode": "plate_123",
                            "event_type":
                            Biosero.EVENT_SOURCE_NO_PLATE_MAP_DATA,
                        },
                        headers=biosero_auth_headers,
                    )

                    # Test creates the event
                    assert response.status_code == HTTPStatus.CREATED

                    mocked_rabbit_channel.basic_publish.assert_called_with(
                        exchange="lighthouse.test.examples",
                        routing_key=
                        f"test.event.{ Biosero.EVENT_SOURCE_NO_PLATE_MAP_DATA }",
                        body='{"event": {"uuid": "' + int_to_uuid(1) +
                        ('", "event_type": "' +
                         Biosero.EVENT_SOURCE_NO_PLATE_MAP_DATA + '", '
                         '"occured_at": "mytime", "user_identifier": "user1", "subjects": '
                         '[{"role_type": "robot", "subject_type": "robot", "friendly_name": "CPA", '
                         '"uuid": "e465f4c6-aa4e-461b-95d6-c2eaab15e63f"}, '
                         '{"role_type": "run", "subject_type": "run", "friendly_name": 3, '
                         '"uuid": "' + int_to_uuid(2) + '"}], '
                         '"metadata": {"source_plate_barcode": "plate_123"}}, "lims": "LH_TEST"}'
                         ),
                    )

                    # The record is there
                    event = get_event_with_uuid(int_to_uuid(1))
                    assert event is not None

                    # And it does not have errors
                    assert event[FIELD_EVENT_ERRORS] is None
Exemplo n.º 2
0
def test_post_event_partially_completed_with_error_accessing_cherrytrack_for_samples_info(
    app,
    client,
    biosero_auth_headers,
    source_plates,
    run_id,
    clear_events,
    source_barcode,
    destination_barcode,
    mocked_rabbit_channel,
    mocked_responses,
    cherrytrack_mock_source_plates,
):
    with app.app_context():
        with patch(
                "lighthouse.hooks.events.uuid4",
                side_effect=[
                    int_to_uuid(1),
                    int_to_uuid(2),
                    int_to_uuid(3),
                    int_to_uuid(4)
                ],
        ):
            with patch(
                    "lighthouse.classes.events.PlateEvent.message_timestamp",
                    return_value="mytime",
            ):
                response = client.post(
                    "/events",
                    data={
                        "automation_system_run_id": run_id,
                        "barcode": source_barcode,
                        "event_type": Biosero.EVENT_SOURCE_COMPLETED,
                    },
                    headers=biosero_auth_headers,
                )

                # Test creates the event
                assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR

                # However the message is not published
                mocked_rabbit_channel.basic_publish.assert_not_called()

                # But the record is there
                event = get_event_with_uuid(int_to_uuid(1))
                assert event is not None

                # And it has errors
                assert event[FIELD_EVENT_ERRORS] == {
                    "base": [
                        "Response from Cherrytrack is not OK: One error,Another error"
                    ]
                }
Exemplo n.º 3
0
def test_set_errors_event_updates_correctly(app, plate_events):
    with app.app_context():
        plate_events, _ = plate_events
        errorObj = {
            FIELD_EVENT_USER_ID:
            ["The user does not exist", "The user id format is wrong"]
        }

        result = set_errors_to_event(plate_events[0][FIELD_EVENT_UUID],
                                     errorObj)
        assert result is True
        assert get_event_with_uuid(
            plate_events[0][FIELD_EVENT_UUID])[FIELD_EVENT_ERRORS] == errorObj
Exemplo n.º 4
0
def test_post_event_partially_completed_with_validation_error_after_storing_in_mongo(
        app, client, biosero_auth_headers, clear_events,
        mocked_rabbit_channel):
    with app.app_context():
        with patch(
                "lighthouse.hooks.events.uuid4",
                side_effect=[
                    int_to_uuid(1),
                    int_to_uuid(2),
                    int_to_uuid(3),
                    int_to_uuid(4)
                ],
        ):
            with patch(
                    "lighthouse.classes.events.PlateEvent.message_timestamp",
                    return_value="mytime",
            ):
                response = client.post(
                    "/events",
                    data={
                        "automation_system_run_id": 3,
                        "barcode": "a Barcode",
                        "event_type": Biosero.EVENT_SOURCE_COMPLETED,
                    },
                    headers=biosero_auth_headers,
                )

                # Test creates the event
                assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR

                # However the message is not published
                mocked_rabbit_channel.basic_publish.assert_not_called()

                # But the record is there
                event = get_event_with_uuid(int_to_uuid(1))
                assert event is not None

                # And it has errors
                assert event[FIELD_EVENT_ERRORS] == {
                    "plate_barcode":
                    ["'barcode' should not contain any whitespaces"],
                    "source_plate_uuid":
                    ["'barcode' should not contain any whitespaces"],
                    "samples_picked_from_source":
                    ["'barcode' should not contain any whitespaces"],
                }
Exemplo n.º 5
0
def test_post_event_partially_completed(
    app,
    client,
    biosero_auth_headers,
    clear_events,
    mocked_rabbit_channel,
    source_plates,
    run_id,
    mocked_responses,
    cherrytrack_mock_run_info,
    samples_from_cherrytrack_into_mongo,
    centres,
    destination_barcode,
    mlwh_samples_in_cherrytrack,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
    baracoda_mock_barcodes_group,
    baracoda_mock_responses,
):
    with app.app_context():
        with patch(
                "lighthouse.hooks.events.uuid4",
                side_effect=[int_to_uuid(1)],
        ):
            with patch(
                    "lighthouse.classes.messages.warehouse_messages.uuid4",
                    side_effect=[
                        int_to_uuid(2),
                        int_to_uuid(3),
                        int_to_uuid(4),
                        int_to_uuid(5)
                    ],
            ):
                with patch(
                        "lighthouse.classes.events.PlateEvent.message_timestamp",
                        "mytime",
                ):
                    mock_response_send_ss = MagicMock()
                    mock_response_send_ss.ok = True
                    with patch(
                            "lighthouse.classes.messages.sequencescape_messages.SequencescapeMessage._send_to_ss",
                            return_value=mock_response_send_ss,
                    ) as send_to_ss:

                        response = client.post(
                            "/events",
                            data={
                                "automation_system_run_id":
                                3,
                                "barcode":
                                "HT-1234",
                                "event_type":
                                Biosero.
                                EVENT_ERROR_RECOVERED_DESTINATION_COMPLETED,
                            },
                            headers=biosero_auth_headers,
                        )

                        # Test creates the event
                        assert response.status_code == HTTPStatus.CREATED

                        event_message = ('{"event": {"uuid": "' + int_to_uuid(
                            1
                        ) + (
                            '", "event_type": "' +
                            Biosero.EVENT_ERROR_RECOVERED_DESTINATION_COMPLETED
                            + '", '
                            '"occured_at": "mytime", "user_identifier": "user1", "subjects": '
                            '[{"role_type": "sample", "subject_type": "sample", "friendly_name": '
                            '"aRootSampleId1__plate_123_A01__centre_1__Positive", "uuid": "aLighthouseUUID1"}, '
                            '{"role_type": "sample", "subject_type": "sample", "friendly_name": '
                            '"aRootSampleId3__plate_123_A03__centre_1__Positive", "uuid": "aLighthouseUUID3"}, '
                            '{"role_type": "control", "subject_type": "sample", "friendly_name": '
                            '"positive control: DN1234_A1", '
                            '"uuid": "' + int_to_uuid(2) + '"}, '
                            '{"role_type": "control", "subject_type": "sample", "friendly_name": '
                            '"negative control: DN1234_A1", '
                            '"uuid": "' + int_to_uuid(3) + '"}, '
                            '{"role_type": "cherrypicking_source_labware", "subject_type": "plate", '
                            '"friendly_name": "plate_123", "uuid": "a17c38cd-b2df-43a7-9896-582e7855b4cc"}, '
                            '{"role_type": "cherrypicking_destination_labware", "subject_type": "plate", '
                            '"friendly_name": "HT-1234", "uuid": "' +
                            int_to_uuid(4) + '"}, '
                            '{"role_type": "robot", "subject_type": "robot", "friendly_name": "CPA", '
                            '"uuid": "e465f4c6-aa4e-461b-95d6-c2eaab15e63f"}, '
                            '{"role_type": "run", "subject_type": "run", "friendly_name": 3, '
                            '"uuid": "' + int_to_uuid(5) + '"}'
                            '], "metadata": {}}, "lims": "LH_TEST"}'))

                        mocked_rabbit_channel.basic_publish.assert_called_with(
                            exchange="lighthouse.test.examples",
                            routing_key=
                            f"test.event.{ Biosero.EVENT_ERROR_RECOVERED_DESTINATION_COMPLETED }",
                            body=event_message,
                        )

                        ss_message = (
                            '{"data": {"type": "plates", "attributes": {"barcode": "HT-1234", '
                            '"purpose_uuid": "ss_uuid_plate_purpose", '
                            '"study_uuid": "ss_uuid_study", "wells": '
                            '{"H08": {"content": {"name": "plate_123_A01", "sample_description": "aRootSampleId1", '
                            '"supplier_name": "COGUK1", "phenotype": "positive", "uuid": "aLighthouseUUID1"}}, '
                            '"H12": {"content": {"name": "plate_123_A03", "sample_description": "aRootSampleId3", '
                            '"supplier_name": "COGUK2", '
                            '"phenotype": "positive", "uuid": "aLighthouseUUID3"}}, '
                            '"E10": {"content": {"supplier_name": "positive control: DN1234_A1", "control": true, '
                            '"control_type": "positive"}}, '
                            '"E11": {"content": {"supplier_name": "negative control: DN1234_A1", "control": true, '
                            '"control_type": "negative"}}}, '
                            '"events": []}}}')

                        send_to_ss.assert_called_once_with(
                            ss_url=
                            f"{app.config['SS_URL']}/api/v2/heron/plates",
                            headers={
                                "X-Sequencescape-Client-Id":
                                app.config["SS_API_KEY"],
                                "Content-type":
                                "application/json",
                            },
                            data=ss_message,
                        )

                        # The record is there
                        event = get_event_with_uuid(int_to_uuid(1))
                        assert event is not None

                        # And it does not have errors
                        assert event[FIELD_EVENT_ERRORS] is None
Exemplo n.º 6
0
def test_post_event_partially_completed(
    app,
    client,
    lighthouse_ui_auth_headers,
    clear_events,
    mocked_rabbit_channel,
    source_plates,
    run_id,
    mocked_responses,
    cherrytrack_mock_run_info,
    samples_from_cherrytrack_into_mongo,
    centres,
    destination_barcode,
    mlwh_samples_in_cherrytrack,
    cherrytrack_mock_destination_plate,
    cherrytrack_destination_plate_response,
    baracoda_mock_barcodes_group,
    baracoda_mock_responses,
):
    with app.app_context():
        with patch(
                "lighthouse.hooks.events.uuid4",
                side_effect=[int_to_uuid(1)],
        ):
            with patch(
                    "lighthouse.classes.messages.warehouse_messages.uuid4",
                    side_effect=[
                        int_to_uuid(2),
                        int_to_uuid(3),
                        int_to_uuid(4),
                        int_to_uuid(5)
                    ],
            ):
                with patch(
                        "lighthouse.classes.events.PlateEvent.message_timestamp",
                        "mytime",
                ):
                    failure_type = Beckman.get_failure_types()[0].get("type")
                    assert failure_type is not None

                    response = client.post(
                        "/events",
                        data={
                            "barcode": "HT-1234",
                            "event_type": Biosero.EVENT_DESTINATION_FAILED,
                            "failure_type": failure_type,
                            "user_id": "user1",
                        },
                        headers=lighthouse_ui_auth_headers,
                    )

                    # Test creates the event
                    assert response.status_code == HTTPStatus.CREATED

                    event_message = ('{"event": {"uuid": "' + int_to_uuid(1) + (
                        '", "event_type": "' +
                        Biosero.EVENT_DESTINATION_FAILED + '", '
                        '"occured_at": "mytime", "user_identifier": "user1", "subjects": '
                        '[{"role_type": "sample", "subject_type": "sample", "friendly_name": '
                        '"aRootSampleId1__plate_123_A01__centre_1__Positive", "uuid": "aLighthouseUUID1"}, '
                        '{"role_type": "sample", "subject_type": "sample", "friendly_name": '
                        '"aRootSampleId3__plate_123_A03__centre_1__Positive", "uuid": "aLighthouseUUID3"}, '
                        '{"role_type": "control", "subject_type": "sample", "friendly_name": '
                        '"positive control: DN1234_A1", '
                        '"uuid": "' + int_to_uuid(2) + '"}, '
                        '{"role_type": "control", "subject_type": "sample", "friendly_name": '
                        '"negative control: DN1234_A1", '
                        '"uuid": "' + int_to_uuid(3) + '"}, '
                        '{"role_type": "cherrypicking_source_labware", "subject_type": "plate", '
                        '"friendly_name": "plate_123", "uuid": "a17c38cd-b2df-43a7-9896-582e7855b4cc"}, '
                        '{"role_type": "cherrypicking_destination_labware", "subject_type": "plate", '
                        '"friendly_name": "HT-1234", "uuid": "' +
                        int_to_uuid(4) + '"}, '
                        '{"role_type": "robot", "subject_type": "robot", "friendly_name": "CPA", '
                        '"uuid": "e465f4c6-aa4e-461b-95d6-c2eaab15e63f"}, '
                        '{"role_type": "run", "subject_type": "run", "friendly_name": 3, '
                        '"uuid": "' + int_to_uuid(5) + '"}'
                        '], "metadata": {"failure_type": "' + failure_type +
                        '"}}, "lims": "LH_TEST"}'))

                    mocked_rabbit_channel.basic_publish.assert_called_with(
                        exchange="lighthouse.test.examples",
                        routing_key=
                        f"test.event.{ Biosero.EVENT_DESTINATION_FAILED }",
                        body=event_message,
                    )

                    # The record is there
                    event = get_event_with_uuid(int_to_uuid(1))
                    assert event is not None

                    # And it does not have errors
                    assert event[FIELD_EVENT_ERRORS] is None
Exemplo n.º 7
0
def test_post_event_partially_completed(
    app,
    client,
    biosero_auth_headers,
    clear_events,
    mocked_rabbit_channel,
    source_plates,
    run_id,
    source_barcode,
    destination_barcode,
    mocked_responses,
    cherrytrack_mock_run_info,
    cherrytrack_mock_source_plates,
    samples_from_cherrytrack_into_mongo,
):
    with app.app_context():
        with patch(
                "lighthouse.hooks.events.uuid4",
                side_effect=[int_to_uuid(1)],
        ):
            with patch("lighthouse.classes.messages.warehouse_messages.uuid4",
                       side_effect=[int_to_uuid(2)]):
                with patch(
                        "lighthouse.classes.events.PlateEvent.message_timestamp",
                        "mytime",
                ):
                    with patch(
                            "lighthouse.classes.services.labwhere.set_locations_in_labwhere"
                    ) as mocked_labwhere:

                        response = client.post(
                            "/events",
                            data={
                                "automation_system_run_id": run_id,
                                "barcode": source_barcode,
                                "event_type": Biosero.EVENT_SOURCE_COMPLETED,
                            },
                            headers=biosero_auth_headers,
                        )

                        # Test creates the event
                        assert response.status_code == HTTPStatus.CREATED

                        mocked_rabbit_channel.basic_publish.assert_called_with(
                            exchange="lighthouse.test.examples",
                            routing_key=
                            f"test.event.{ Biosero.EVENT_SOURCE_COMPLETED }",
                            body='{"event": {"uuid": "' + int_to_uuid(1) +
                            ('", "event_type": "' +
                             Biosero.EVENT_SOURCE_COMPLETED + '", '
                             '"occured_at": "mytime", "user_identifier": "user1", "subjects": '
                             '[{"role_type": "sample", "subject_type": "sample", "friendly_name": '
                             '"aRootSampleId1__plate_123_A01__centre_1__Positive", "uuid": "aLighthouseUUID1"}, '
                             '{"role_type": "sample", "subject_type": "sample", "friendly_name": '
                             '"aRootSampleId3__plate_123_A03__centre_1__Positive", "uuid": "aLighthouseUUID3"}, '
                             '{"role_type": "cherrypicking_source_labware", "subject_type": "plate", '
                             '"friendly_name": "plate_123", "uuid": "a17c38cd-b2df-43a7-9896-582e7855b4cc"}, '
                             '{"role_type": "robot", "subject_type": "robot", "friendly_name": "CPA", '
                             '"uuid": "e465f4c6-aa4e-461b-95d6-c2eaab15e63f"}, '
                             '{"role_type": "run", "subject_type": "run", "friendly_name": 3, '
                             '"uuid": "' + int_to_uuid(2) + '"}'
                             '], "metadata": {}}, "lims": "LH_TEST"}'),
                        )

                        mocked_labwhere.assert_called_once_with(
                            labware_barcodes=[source_barcode],
                            location_barcode=app.
                            config["LABWHERE_DESTROYED_BARCODE"],
                            user_barcode="CPA",
                        )

                        # The record is there
                        event = get_event_with_uuid(int_to_uuid(1))
                        assert event is not None

                        # And it does not have errors
                        assert event[FIELD_EVENT_ERRORS] is None
Exemplo n.º 8
0
def get_event_wih_uuid_finds_none_event(app, plate_events):
    with app.app_context():
        plate_events, _ = plate_events
        assert get_event_with_uuid("11111") is None
Exemplo n.º 9
0
def get_event_with_uuid_finds_event(app, plate_events):
    with app.app_context():
        plate_events, _ = plate_events

        assert get_event_with_uuid(
            plate_events[0][FIELD_EVENT_UUID]) == plate_events[0]