diff --git a/README.md b/README.md index 62c8210..3c3363c 100644 --- a/README.md +++ b/README.md @@ -126,10 +126,10 @@ Then manually run the [release GitHub action](https://github.com/novonordisk-research/OptiHPLCHandler/actions/workflows/release.yml) by clicking `Run workflow`. Select what type of release it is by typing in `--patch`, `--minor`, or `--major` in `The type of release to perform`, and then click `Run workflow`. -Fetch the new branch `release`. Make sure there isn't a `dist` folder in -your project folder (or delete it), and run the commands +Fetch the new branch `release`. Run the commands ``` +rm -r -fo dist py -m build py -m twine upload dist/* ``` diff --git a/pyproject.toml b/pyproject.toml index 50f1343..801ebb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "Opti_HPLC_Handler" -version = "0.2.6" +version = "0.2.7" description = "Simplified proxy API for interacting with the Waters Empower Web API." readme = "README.md" requires-python = ">=3.8" @@ -85,7 +85,7 @@ pythonpath = [ ] [tool.bumpver] -current_version = "0.2.6" +current_version = "0.2.7" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "bump version {old_version} -> {new_version}" tag_message = "{new_version}" diff --git a/src/OptiHPLCHandler/__init__.py b/src/OptiHPLCHandler/__init__.py index d71e8f6..7afb0fe 100644 --- a/src/OptiHPLCHandler/__init__.py +++ b/src/OptiHPLCHandler/__init__.py @@ -2,6 +2,6 @@ from .empower_api_core import EmpowerConnection from .empower_handler import EmpowerHandler -__version__ = "0.2.6" +__version__ = "0.2.7" __all__ = ["DataField", "EmpowerConnection", "EmpowerHandler", "HPLCSetup", "Sample"] diff --git a/src/OptiHPLCHandler/empower_handler.py b/src/OptiHPLCHandler/empower_handler.py index 1990d61..2f42807 100644 --- a/src/OptiHPLCHandler/empower_handler.py +++ b/src/OptiHPLCHandler/empower_handler.py @@ -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( + "Could not post sample set method. Resource not found." + ) raise ValueError( f"Could not post sample set method. Response: {response.text}" ) diff --git a/tests/test_proxy_api.py b/tests/test_proxy_api.py index 07d5760..45be83f 100644 --- a/tests/test_proxy_api.py +++ b/tests/test_proxy_api.py @@ -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 @@ -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(