Skip to content

Commit

Permalink
Merge pull request #65 from sanger/dpl-952-remaining-fixes
Browse files Browse the repository at this point in the history
DPL-952: Remaining Fixes
  • Loading branch information
sdjmchattie authored Feb 15, 2024
2 parents d7e226f + d6c81b1 commit 0c040f5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 72 deletions.
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def valid_sample():
"countryOfOrigin": "United Kingdom",
"genomeSize": "14",
"accessionNumber": "EE1234",
"sampleCollectionDateUtc": datetime.now(),
"sampleCollectionDateUtc": datetime.utcnow(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "8",
"postSPRIConcentration": "9",
Expand All @@ -147,7 +147,7 @@ def valid_sample():
"finalNanoDrop230": "200",
"finalNanoDrop": "150",
"shearingAndQCComments": "",
"dateSubmittedUTC": datetime.now(),
"dateSubmittedUTC": datetime.utcnow(),
"priorityLevel": "Medium",
}

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

Expand Down
20 changes: 10 additions & 10 deletions tests/data/examples_create_labware_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

TEST_CREATE_LABWARE_MSG_OBJECT: dict[str, Any] = {
"messageUuid": "b01aa0ad-7b19-4f94-87e9-70d74fb8783c".encode(),
"messageCreateDateUtc": datetime.now(),
"messageCreateDateUtc": datetime.utcnow(),
"labware": {
"labwareType": "Plate12x8",
"barcode": "BARCODE001",
Expand All @@ -24,7 +24,7 @@
"countryOfOrigin": "United Kingdom",
"genomeSize": "14",
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"sampleCollectionDateUtc": datetime.utcnow(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
Expand All @@ -33,7 +33,7 @@
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"dateSubmittedUTC": datetime.utcnow(),
"priorityLevel": "Medium",
},
{
Expand All @@ -52,7 +52,7 @@
"countryOfOrigin": "United Kingdom",
"genomeSize": "14",
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"sampleCollectionDateUtc": datetime.utcnow(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
Expand All @@ -61,7 +61,7 @@
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"dateSubmittedUTC": datetime.utcnow(),
"priorityLevel": "Medium",
},
],
Expand All @@ -71,7 +71,7 @@

TEST_INVALID_CREATE_LABWARE_MSG_OBJECT: dict[str, Any] = {
"messageUuid": "b01aa0ad7b19-4f94-87e9-70d74fb8783c".encode(),
"messageCreateDateUtc": datetime.now(),
"messageCreateDateUtc": datetime.utcnow(),
"labware": {
"labwareType": "Plate12x8",
"barcode": "BARCODE001",
Expand All @@ -92,7 +92,7 @@
"countryOfOrigin": "United Kingdom",
"genomeSize": "14",
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"sampleCollectionDateUtc": datetime.utcnow(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
Expand All @@ -101,7 +101,7 @@
"finalNanoDrop230": "6",
"finalNanoDrop": 7,
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"dateSubmittedUTC": datetime.utcnow(),
"priorityLevel": "Medium",
},
{
Expand All @@ -120,7 +120,7 @@
"countryOfOrigin": "United Kingdom",
"genomeSize": "14",
"accessionNumber": "EE3383",
"sampleCollectionDateUtc": datetime.now(),
"sampleCollectionDateUtc": datetime.utcnow(),
"costCode": "S1234",
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
Expand All @@ -129,7 +129,7 @@
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now(),
"dateSubmittedUTC": datetime.utcnow(),
"priorityLevel": "Medium",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_message_property_check_is_date_utc():
instance = MessageProperty(Input(None))
assert instance.check_is_date_utc() is False

instance = MessageProperty(Input(datetime.now()))
instance = MessageProperty(Input(datetime.utcnow()))
assert instance.check_is_date_utc() is True

instance = MessageProperty(Input({}))
Expand Down
10 changes: 5 additions & 5 deletions tests/messages/test_output_traction_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_output_traction_message_can_validate():


def test_output_traction_message_can_generate_payload_for_plates():
my_date = datetime.now()
my_date = datetime.utcnow()
instance = OutputTractionMessage()

request = instance.create_request()
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_output_traction_message_can_generate_payload_for_plates():


def test_output_traction_message_can_generate_payload_for_multiple_plates():
my_date = datetime.now()
my_date = datetime.utcnow()
instance = OutputTractionMessage()

# Mix the order of the requests to ensure the grouping for plates works.
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_output_traction_message_can_generate_payload_for_multiple_plates():


def test_output_traction_message_can_generate_payload_for_ont_library_types():
my_date = datetime.now()
my_date = datetime.utcnow()
instance = OutputTractionMessage()

request = instance.create_request()
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_output_traction_message_can_generate_payload_for_ont_library_types():


def test_output_traction_message_can_generate_payload_for_tubes():
my_date = datetime.now()
my_date = datetime.utcnow()
instance = OutputTractionMessage()

request = instance.create_request()
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_output_traction_message_can_generate_payload_for_tubes():


def test_output_traction_message_can_generate_payload_for_mix_of_plate_and_tubes():
my_date = datetime.now()
my_date = datetime.utcnow()
instance = OutputTractionMessage()

request = instance.create_request()
Expand Down
21 changes: 6 additions & 15 deletions tests/messages/test_traction_qc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,9 @@
logger = logging.getLogger(__name__)


class FreezeDate(datetime):
@classmethod
def now(cls):
return cls(2023, 7, 11, 12, 29, 11, 564246)


datetime = FreezeDate # type: ignore


class TestTractionQcMessage:
@pytest.fixture()
def valid_traction_qc_message(self):
def valid_traction_qc_message(self, freezer):
traction_qc_message = TractionQcMessage()

request = traction_qc_message.create_request()
Expand All @@ -33,7 +24,7 @@ def valid_traction_qc_message(self):
request.final_nano_drop_230 = "230"
request.final_nano_drop = "200"
request.shearing_qc_comments = "Comments"
request.date_submitted_utc = datetime.now().timestamp() * 1000
request.date_submitted_utc = datetime.utcnow().timestamp() * 1000

request = traction_qc_message.create_request()
request.sanger_sample_id = "sanger_sample_id_DDD2"
Expand All @@ -45,7 +36,7 @@ def valid_traction_qc_message(self):
request.final_nano_drop_230 = "130"
request.final_nano_drop = "100"
request.shearing_qc_comments = ""
request.date_submitted_utc = datetime.now().timestamp() * 1000
request.date_submitted_utc = datetime.utcnow().timestamp() * 1000

return traction_qc_message

Expand All @@ -66,7 +57,7 @@ def test_validate_traction_qc_message(self, valid_traction_qc_message, invalid_t
assert not invalid_traction_qc_message.validate()
assert valid_traction_qc_message.validate()

def test_can_generate_correct_payload(self, valid_traction_qc_message):
def test_can_generate_correct_payload(self, valid_traction_qc_message, freezer):
payload = valid_traction_qc_message.payload()

expected_payload = {
Expand All @@ -81,7 +72,7 @@ def test_can_generate_correct_payload(self, valid_traction_qc_message):
"post_spri_volume": "20",
"sheared_femto_fragment_size": "5",
"shearing_qc_comments": "Comments",
"date_submitted": datetime.now().timestamp() * 1000,
"date_submitted": datetime.utcnow().timestamp() * 1000,
"labware_barcode": "FD20706500",
"sample_external_id": "sanger_sample_id_DDD",
},
Expand All @@ -92,7 +83,7 @@ def test_can_generate_correct_payload(self, valid_traction_qc_message):
"post_spri_concentration": "10",
"post_spri_volume": "30",
"sheared_femto_fragment_size": "9",
"date_submitted": datetime.now().timestamp() * 1000,
"date_submitted": datetime.utcnow().timestamp() * 1000,
"labware_barcode": "FD20706501",
"sample_external_id": "sanger_sample_id_DDD2",
},
Expand Down
39 changes: 9 additions & 30 deletions tol_lab_share/message_properties/definitions/labware_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import string
from .message_property import MessageProperty
from tol_lab_share import error_codes
import logging
Expand Down Expand Up @@ -31,39 +32,17 @@ def check_labware_type(self):
self.trigger_error(error_codes.ERROR_6_LABWARE_TYPE, text=f"input: {self._input.value}")
return result

def pad_number(self, number: int) -> str:
"""Given a number, it generates a string of size 2 padded with zeros at the left representing
the same value. Eg: 3 would be converted to '03', while 12 would be converted to '12'.
Parameters:
number (int) value we want to convert
Returns:
str with the padded value
"""
padded_number = str(number)
if len(padded_number) == 1:
padded_number = f"0{padded_number}"
return padded_number

def _locations_for_plate12x8_column_order(self) -> list[str]:
"""It generates the list of all valid locations for a labware type following column
order. Eg: ['A01', 'B01', 'C01', .... 'H12']
Returns:
list[str] with al the valid locations
"""
locations = []
for number in range(12):
for letter_ord in range(ord("A"), ord("H") + 1):
locations.append(f"{chr(letter_ord)}{self.pad_number(number+1)}")
return locations

def valid_locations(self) -> list[str]:
"""It returns the list of valid locations for the labware type. If the labware type is
a tube, it returns ane empty list. If it is a plate 12x8 it returns all locations in
column order.
"""It returns the list of valid locations for the labware type.
If the labware type is a tube, it returns ane empty list.
If it is a plate 12x8 it returns all locations in column order. i.e. ['A01', 'B01', 'C01', .... 'H12']
Returns:
list[str] with all the valid locations
list[str]: A list with all the valid locations.
"""
if self.value == "Plate12x8":
return self._locations_for_plate12x8_column_order()
return [
f"{letter}{str(number).zfill(2)}" for number in range(1, 13) for letter in string.ascii_uppercase[:8]
]
else:
return []
14 changes: 7 additions & 7 deletions tools/demo/testing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def build_create_labware_96_msg(unique_id, num_msg):
unique_id_lab = f"TOLTESTING-PLATE-{unique_id}-{num_msg}"
return {
"messageUuid": str(uuid4()).encode(),
"messageCreateDateUtc": datetime.now().timestamp() * 1000,
"messageCreateDateUtc": datetime.utcnow().timestamp() * 1000,
"labware": {
"labwareType": "Plate12x8",
"barcode": barcode_for_unique_id("PLATE", unique_id, num_msg),
Expand All @@ -42,15 +42,15 @@ def build_create_labware_96_msg(unique_id, num_msg):
"genomeSize": "1",
"accessionNumber": "A1234",
"costCode": "S1234",
"sampleCollectionDateUtc": datetime.now().timestamp() * 1000,
"sampleCollectionDateUtc": datetime.utcnow().timestamp() * 1000,
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
"postSPRIVolume": "20",
"finalNanoDrop280": "5",
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now().timestamp() * 1000,
"dateSubmittedUTC": datetime.utcnow().timestamp() * 1000,
"priorityLevel": "Medium",
}
for letter in range(ord("A"), ord("H") + 1)
Expand All @@ -64,7 +64,7 @@ def build_create_tube_msg(unique_id, num_msg):
unique_id_lab = f"TOLTESTING-TUBE-{unique_id}-{num_msg}"
return {
"messageUuid": str(uuid4()).encode(),
"messageCreateDateUtc": datetime.now().timestamp() * 1000,
"messageCreateDateUtc": datetime.utcnow().timestamp() * 1000,
"labware": {
"labwareType": "Tube",
"barcode": barcode_for_unique_id("TUBE", unique_id, num_msg),
Expand All @@ -86,15 +86,15 @@ def build_create_tube_msg(unique_id, num_msg):
"genomeSize": "1",
"accessionNumber": "A1234",
"costCode": "S1234",
"sampleCollectionDateUtc": datetime.now().timestamp() * 1000,
"sampleCollectionDateUtc": datetime.utcnow().timestamp() * 1000,
"shearedFemtoFragmentSize": "5",
"postSPRIConcentration": "10",
"postSPRIVolume": "20",
"finalNanoDrop280": "5",
"finalNanoDrop230": "6",
"finalNanoDrop": "7",
"shearingAndQCComments": "Comments",
"dateSubmittedUTC": datetime.now().timestamp() * 1000,
"dateSubmittedUTC": datetime.utcnow().timestamp() * 1000,
"priorityLevel": "Medium",
}
],
Expand All @@ -105,7 +105,7 @@ def build_create_tube_msg(unique_id, num_msg):
def build_update_labware_msg(sample_msg):
return {
"messageUuid": str(uuid4()).encode(),
"messageCreateDateUtc": datetime.now().timestamp() * 1000,
"messageCreateDateUtc": datetime.utcnow().timestamp() * 1000,
"sampleUpdates": [
{
"sampleUuid": sample_msg["labware"]["samples"][3]["sampleUuid"],
Expand Down

0 comments on commit 0c040f5

Please sign in to comment.