Skip to content

Commit

Permalink
fix: Posting samplesets with audit trail comments
Browse files Browse the repository at this point in the history
Also better response when posting to the srong resource (error 404)

Also testing for errors when post samplesets.
  • Loading branch information
SRFU-NN committed Aug 10, 2023
1 parent 8e0e4a3 commit c94e358
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/OptiHPLCHandler/empower_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ def PostExperiment(
endpoint = "project/methods/sample-set-method"
if audit_trail_message:
logger.debug("Adding audit trail message to endpoint")
endpoint += f"&auditTrailComment={audit_trail_message}"
endpoint += f"?auditTrailComment={audit_trail_message}"
response = self.connection.post(endpoint=endpoint, body=sampleset_object)
if response.status_code != 201:
if response.status_code == 404:
raise ValueError(
f"Could not post sample set method. Resource not found."
)
raise ValueError(
f"Could not post sample set method. Response: {response.text}"
)
Expand Down
27 changes: 26 additions & 1 deletion tests/test_proxy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_empower_handler_post_sample_list(self, mock_requests):
assert "test_sampleset_name" == mock_requests.method_calls[0][2]["json"]["name"]
# Testing that the name is correct in the request
assert (
"auditTrailComment=test_audit_trail_message"
"?auditTrailComment=test_audit_trail_message"
in mock_requests.method_calls[0][1][0]
)
# Testing that the audit trail message is correct
Expand Down Expand Up @@ -135,6 +135,31 @@ def test_empower_handler_post_sample_list(self, mock_requests):
assert all([dict_type == "Enumerator" for dict_type in dict_type_list])
# Testing that all dictionary values are strings

@patch("OptiHPLCHandler.empower_api_core.requests")
def test_empower_handler_post_sample_list_error(self, mock_requests):
mock_response = MagicMock()
mock_response.json.return_value = {"results": "mock_results"}
mock_response.status_code = 404
mock_requests.post.return_value = mock_response
with self.assertRaises(ValueError) as context:
self.handler.PostExperiment(
sample_set_method_name="test_sampleset_name",
sample_list=[],
plate_list=[],
audit_trail_message="test_audit_trail_message",
)
assert "Resource not found" in context.exception.args[0]
mock_response.status_code = 400
mock_response.text = "mock_error_message"
with self.assertRaises(ValueError) as context:
self.handler.PostExperiment(
sample_set_method_name="test_sampleset_name",
sample_list=[],
plate_list=[],
audit_trail_message="test_audit_trail_message",
)
assert "Response: mock_error_message" in context.exception.args[0]

def test_empower_handler_add_method(self):
with self.assertRaises(NotImplementedError):
self.handler.AddMethod(
Expand Down

0 comments on commit c94e358

Please sign in to comment.