Skip to content

Commit

Permalink
Merge pull request #48 from sanger/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
emrojo authored Oct 4, 2023
2 parents 3594ee2 + 734f3e2 commit c21ca5f
Show file tree
Hide file tree
Showing 40 changed files with 1,577 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .release-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.3.0
37 changes: 37 additions & 0 deletions schemas/create-labware/1-create-labware.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,43 @@
{
"name": "accessionNumber", "type": "string",
"doc": "Accession number for publication in ENA/EBI"
},
{
"name": "shearedFemtoFragmentSize", "type": "string",
"doc": "Sheared Femto Fragment Size (bp)"
},
{
"name": "postSPRIConcentration", "type": "string",
"doc": "Post SPRI Concentration (ng/ul)"
},
{
"name": "postSPRIVolume", "type": "string",
"doc": "Post SPRI Volume (ul)"
},
{
"name": "finalNanoDrop280", "type": "string",
"doc": "Final NanoDrop 260/280"
},
{
"name": "finalNanoDrop230", "type": "string",
"doc": "Final NanoDrop 260/230"
},
{
"name": "finalNanoDrop", "type": "string",
"doc": "Final NanoDrop ng/ul"
},
{
"name": "shearingAndQCComments", "type": "string",
"doc": "Shearing & QC comments"
},
{
"name": "dateSubmittedUTC",
"doc": "Date submitted in UTC format.",
"type": { "type": "long", "logicalType": "timestamp-millis" }
},
{
"name": "priorityLevel", "type": "string",
"doc": "Priority level (if High or Medium)"
}
]
}
Expand Down
55 changes: 47 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import pytest
import logging
import logging.config
from tol_lab_share.helpers import get_config
from lab_share_lib.processing.rabbit_message import RabbitMessage
from lab_share_lib.constants import (
RABBITMQ_HEADER_KEY_SUBJECT,
RABBITMQ_HEADER_KEY_VERSION,
)
from datetime import datetime
from unittest.mock import MagicMock

import pytest
from data.examples_create_labware_messages import TEST_CREATE_LABWARE_MSG_OBJECT, TEST_INVALID_CREATE_LABWARE_MSG_OBJECT
from lab_share_lib.constants import RABBITMQ_HEADER_KEY_SUBJECT, RABBITMQ_HEADER_KEY_VERSION
from lab_share_lib.processing.rabbit_message import RabbitMessage

from unittest.mock import MagicMock
from tol_lab_share.helpers import get_config
from tol_lab_share.messages.output_feedback_message import OutputFeedbackMessage

CONFIG = get_config("tol_lab_share.config.test")
logging.config.dictConfig(CONFIG.LOGGING)
Expand Down Expand Up @@ -78,6 +77,28 @@ def traction_success_creation_response():
}


@pytest.fixture()
def traction_qc_success_response():
return {
"data": {
"id": "10",
"type": "qc_receptions",
"links": {"self": "http://localhost:3000/v1/qc_receptions/10"},
"attributes": {"source": "tol-lab-share.tol"},
}
}


@pytest.fixture()
def valid_feedback_message():
instance = OutputFeedbackMessage()
instance.count_of_total_samples = 0
instance.count_of_valid_samples = 0
instance.source_message_uuid = b"b01aa0ad-7b19-4f94-87e9-70d74fb8783c"
instance.operation_was_error_free = True
return instance


@pytest.fixture
def taxonomy_record():
return {
Expand Down Expand Up @@ -119,6 +140,15 @@ def valid_sample():
"accessionNumber": "EE1234",
"sampleCollectionDateUtc": datetime.now(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "8",
"postSPRIConcentration": "9",
"postSPRIVolume": "10",
"finalNanoDrop280": "200",
"finalNanoDrop230": "200",
"finalNanoDrop": "150",
"shearingAndQCComments": "",
"dateSubmittedUTC": datetime.now(),
"priorityLevel": "Medium",
}


Expand All @@ -142,6 +172,15 @@ def invalid_sample():
"accessionNumber": "EE1234",
"costCode": 1234,
"sampleCollectionDateUtc": datetime.now(),
"shearedFemtoFragmentSize": "8",
"postSPRIConcentration": "9",
"postSPRIVolume": "10",
"finalNanoDrop280": 200,
"finalNanoDrop230": 200,
"finalNanoDrop": "150",
"shearingAndQCComments": "",
"dateSubmittedUTC": datetime.now(),
"priorityLevel": "Medium",
}


Expand Down
38 changes: 37 additions & 1 deletion tests/data/examples_create_labware_messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Dict, Any
from typing import Any, Dict

TEST_CREATE_LABWARE_MSG_OBJECT: Dict[str, Any] = {
"messageUuid": "b01aa0ad-7b19-4f94-87e9-70d74fb8783c".encode(),
Expand All @@ -26,6 +26,15 @@
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
"postSPRIVolume": "20",
"finalNanoDrop280": "5",
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"priorityLevel": "Medium",
},
{
"sampleUuid": "dd490ee5-fd1d-456d-99fd-eb9d3861e0f7".encode(),
Expand All @@ -45,6 +54,15 @@
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
"postSPRIVolume": "20",
"finalNanoDrop280": "5",
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"priorityLevel": "Medium",
},
],
},
Expand Down Expand Up @@ -76,6 +94,15 @@
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
"postSPRIVolume": "20",
"finalNanoDrop280": "5",
"finalNanoDrop230": "6",
"finalNanoDrop": 7,
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"priorityLevel": "Medium",
},
{
"sampleUuid": "dd490ee5-fd1d-456d-99fd-eb9d3861e0f7".encode(),
Expand All @@ -95,6 +122,15 @@
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
"postSPRIVolume": 20,
"finalNanoDrop280": "5",
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"priorityLevel": "Medium",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def test_CountryOfOrigin_check_CountryOfOrigin_is_valid():
assert instance.validate() is False
assert len(instance.errors) > 0

instance = CountryOfOrigin(Input("United Kingdom"))
instance = CountryOfOrigin(Input("UNITED KINGDOM"))
assert instance.validate() is True
assert len(instance.errors) == 0
38 changes: 35 additions & 3 deletions tests/message_properties/definitions/test_labware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from tol_lab_share.message_properties.definitions.input import Input
from tol_lab_share.message_properties.definitions.labware import Labware
from tol_lab_share.message_properties.definitions.location import Location
from tol_lab_share.message_properties.definitions.input import Input
from tol_lab_share.messages.output_traction_message import OutputTractionMessage
from tol_lab_share.messages.traction_qc_message import TractionQcMessage


def test_labware_is_valid():
Expand Down Expand Up @@ -114,7 +115,9 @@ def test_labware_add_to_traction_message_wells(valid_sample):
instance.add_to_traction_message(traction_message)

assert traction_message.requests(0).study_uuid == "dd490ee5-fd1d-456d-99fd-eb9d3861e014"
assert traction_message.requests(0).sample_name == "SamplePublicName1"
assert traction_message.requests(0).sample_name == "cichlid_pacbio8196429"
assert traction_message.requests(0).public_name == "SamplePublicName1"
assert traction_message.requests(0).sanger_sample_id == "cichlid_pacbio8196429"
assert traction_message.requests(0).sample_uuid == "dd490ee5-fd1d-456d-99fd-eb9d3861e0f6"
assert traction_message.requests(0).library_type == "Library1"
assert traction_message.requests(0).species == "Mus musculus"
Expand All @@ -137,7 +140,9 @@ def test_labware_add_to_traction_message_tubes(valid_sample):
instance.add_to_traction_message(traction_message)

assert traction_message.requests(0).study_uuid == "dd490ee5-fd1d-456d-99fd-eb9d3861e014"
assert traction_message.requests(0).sample_name == "SamplePublicName1"
assert traction_message.requests(0).sample_name == "cichlid_pacbio8196429"
assert traction_message.requests(0).sanger_sample_id == "cichlid_pacbio8196429"
assert traction_message.requests(0).public_name == "SamplePublicName1"
assert traction_message.requests(0).sample_uuid == "dd490ee5-fd1d-456d-99fd-eb9d3861e0f6"
assert traction_message.requests(0).library_type == "Library1"
assert traction_message.requests(0).species == "Mus musculus"
Expand All @@ -159,3 +164,30 @@ def test_labware_add_to_traction_message_uses_unpadded_location(valid_sample):
traction_message = OutputTractionMessage()
instance.add_to_traction_message(traction_message)
assert traction_message.requests(0).container_location == "B1"


def test_add_to_traction_qc_message(valid_sample):
data = {
"labwareType": "Plate12x8",
"labwareUuid": "dd490ee5-fd1d-456d-99fd-eb9d3861e0f9".encode(),
"barcode": "BARCODE001",
"samples": [valid_sample],
}
instance = Labware(Input(data))
assert instance.validate()

traction_message = OutputTractionMessage()
instance.add_to_traction_message(traction_message)

traction_qc_message = TractionQcMessage()
instance.add_to_traction_qc_message(traction_qc_message)

assert traction_qc_message.requests(0).supplier_sample_name == "SampleSupplied1"
assert traction_qc_message.requests(0).container_barcode == "BARCODE001"
assert traction_qc_message.requests(0).sheared_femto_fragment_size == "8"
assert traction_qc_message.requests(0).post_spri_concentration == "9"
assert traction_qc_message.requests(0).post_spri_volume == "10"
assert traction_qc_message.requests(0).final_nano_drop_280 == "200"
assert traction_qc_message.requests(0).final_nano_drop_230 == "200"
assert traction_qc_message.requests(0).final_nano_drop == "150"
assert traction_qc_message.requests(0).shearing_qc_comments == ""
15 changes: 8 additions & 7 deletions tests/message_properties/definitions/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from tol_lab_share.message_properties.definitions.sample import Sample
from tol_lab_share.message_properties.definitions.labware_type import LabwareType
from tol_lab_share.message_properties.definitions.labware import Labware
from tol_lab_share.message_properties.definitions.input import Input
from tol_lab_share import error_codes
from tol_lab_share.message_properties.definitions.input import Input
from tol_lab_share.message_properties.definitions.labware import Labware
from tol_lab_share.message_properties.definitions.labware_type import LabwareType
from tol_lab_share.message_properties.definitions.sample import Sample


def build_sample(sample_data):
Expand Down Expand Up @@ -39,17 +39,18 @@ def test_sample_is_invalid(invalid_sample):

instance = build_sample(invalid_sample)
assert instance.validate() is False

check_presence_error(instance.errors, error_codes.ERROR_1_UUID_NOT_BINARY, "study_uuid")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "study_uuid")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "common_name")
check_presence_error(instance.errors, error_codes.ERROR_20_INPUT_IS_NOT_VALID_FLOAT_STRING, "concentration")
check_presence_error(instance.errors, error_codes.ERROR_20_INPUT_IS_NOT_VALID_FLOAT_STRING, "volume")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "country_of_origin")
check_presence_error(instance.errors, error_codes.ERROR_4_NOT_VALID_COUNTRY_INSDC, "country_of_origin")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "donor_id")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "library_type")
check_presence_error(instance.errors, error_codes.ERROR_7_INVALID_LOCATION, "location")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "sanger_sample_id")
check_presence_error(instance.errors, error_codes.ERROR_9_INVALID_INPUT, "scientific_name")

check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "cost_code")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "final_nano_drop_280")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "final_nano_drop_230")
assert len(instance.errors) == 13
2 changes: 1 addition & 1 deletion tests/messages/test_input_create_labware_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_input_create_labware_message_can_validate_when_valid(valid_create_labwa
def test_input_create_labware_message_can_validate_when_invalid(invalid_create_labware_message):
instance = InputCreateLabwareMessage(invalid_create_labware_message)
assert instance.validate() is False
assert len(instance.errors) == 9
assert len(instance.errors) == 5


def test_input_create_labware_message_can_add_to_feedback_message_if_invalid(invalid_create_labware_message):
Expand Down
Loading

0 comments on commit c21ca5f

Please sign in to comment.