Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty value keys from object before sending to traction #46

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions tests/messages/test_traction_qc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
import requests_mock

from tol_lab_share.messages.traction_qc_message import TractionQcMessage
from tol_lab_share.messages.traction_qc_message import TractionQcMessage, QcRequestSerializer, TractionQcMessageRequest

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,7 +41,7 @@ def valid_traction_qc_message(self):
traction_qc_message.requests(1).final_nano_drop_280 = "180"
traction_qc_message.requests(1).final_nano_drop_230 = "130"
traction_qc_message.requests(1).final_nano_drop = "100"
traction_qc_message.requests(1).shearing_qc_comments = "Some comments"
traction_qc_message.requests(1).shearing_qc_comments = ""
traction_qc_message.requests(1).date_submitted_utc = datetime.now().timestamp() * 1000

return traction_qc_message
Expand Down Expand Up @@ -88,7 +88,6 @@ def test_can_generate_correct_payload(self, valid_traction_qc_message):
"post_spri_concentration": "10",
"post_spri_volume": "30",
"sheared_femto_fragment_size": "9",
"shearing_qc_comments": "Some comments",
"date_submitted": datetime.now().timestamp() * 1000,
"labware_barcode": "FD20706501",
"sample_external_id": "supplier_sample_name_DDD2",
Expand Down Expand Up @@ -119,3 +118,15 @@ def test_can_add_to_feedback_message_when_errors(self, invalid_traction_qc_messa
invalid_traction_qc_message.add_to_feedback_message(feedback)
assert len(feedback.errors) > 0
assert not feedback.operation_was_error_free

def test_qc_request_serializer_request_with_empty_strings(self):
request = TractionQcMessageRequest()
serial = QcRequestSerializer(request)
request.final_nano_drop_280 = "1234"
request.container_barcode = ""
assert serial.payload() == {"final_nano_drop_280": "1234"}

def test_qc_request_serializer_clear_empty_value_keys(self):
request = TractionQcMessageRequest()
serial = QcRequestSerializer(request)
assert serial.clear_empty_value_keys({"asdf": "1234", "bcde": ""}) == {"asdf": "1234"}
6 changes: 5 additions & 1 deletion tol_lab_share/messages/traction_qc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def payload(self) -> Dict[str, Any]:
Returns:
Dic[str,str] with all the required payload information for Traction
"""
return {
obj = {
"sheared_femto_fragment_size": self.instance.sheared_femto_fragment_size,
"post_spri_concentration": self.instance.post_spri_concentration,
"post_spri_volume": self.instance.post_spri_volume,
Expand All @@ -170,6 +170,10 @@ def payload(self) -> Dict[str, Any]:
"labware_barcode": self.instance.container_barcode,
"date_submitted": self.instance.date_submitted_utc,
}
return self.clear_empty_value_keys(obj)

def clear_empty_value_keys(self, obj: Dict[str, Any]) -> Dict[str, Any]:
return {k: v for k, v in obj.items() if v}


class TractionQcMessage(MessageProperty, TractionQcMessageInterface):
Expand Down