From ef9c94cc0b10c8f478a8d9fc4703de05bd63e8d0 Mon Sep 17 00:00:00 2001 From: Michael Moen Allport Date: Thu, 23 May 2024 10:25:58 +0200 Subject: [PATCH] Send native JSON-objects instead of JSON-string. Add streaming (#397) * Send native JSON-objects instead of JSON-string. Add streaming * bump version * fix tests * remove streaming as default for field-based --- pyproject.toml | 2 +- src/dapla_pseudo/v1/baseclasses.py | 1 - src/dapla_pseudo/v1/client.py | 6 +++--- tests/v1/unit/test_client.py | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8ae2580c..9fb1f557 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dapla-toolbelt-pseudo" -version = "2.0.2" +version = "2.0.3" description = "Pseudonymization extensions for Dapla" authors = ["Dapla Developers "] license = "MIT" diff --git a/src/dapla_pseudo/v1/baseclasses.py b/src/dapla_pseudo/v1/baseclasses.py index c241de4d..bfb4c8f9 100644 --- a/src/dapla_pseudo/v1/baseclasses.py +++ b/src/dapla_pseudo/v1/baseclasses.py @@ -194,7 +194,6 @@ def _pseudonymize_file( path=f"{self._pseudo_operation.value}/file", request_spec=request_spec, data_spec=data_spec, - stream=True, timeout=timeout, ) file_handle.close() diff --git a/src/dapla_pseudo/v1/client.py b/src/dapla_pseudo/v1/client.py index b54b2c81..bfa572b7 100644 --- a/src/dapla_pseudo/v1/client.py +++ b/src/dapla_pseudo/v1/client.py @@ -71,8 +71,8 @@ def _post_to_file_endpoint( path: str, request_spec: FileSpecDecl, data_spec: FileSpecDecl, - stream: bool, timeout: int, + stream: bool = True, ) -> requests.Response: """POST to a file endpoint in the Pseudo Service. @@ -111,7 +111,7 @@ def _post_to_field_endpoint( "Content-Type": Mimetypes.JSON.value, "X-Correlation-Id": PseudoClient._generate_new_correlation_id(), }, - json={"request": pseudo_field_request.model_dump_json(by_alias=True)}, + json={"request": pseudo_field_request.model_dump(by_alias=True)}, stream=stream, timeout=timeout, ) @@ -124,7 +124,7 @@ def _post_to_sid_endpoint( path: str, values: list[str], sid_snapshot_date: date | None = None, - stream: bool = False, + stream: bool = True, ) -> requests.Response: request: dict[str, t.Collection[str]] = {"fnrList": values} response = requests.post( diff --git a/tests/v1/unit/test_client.py b/tests/v1/unit/test_client.py index 44bab8cb..b19da61d 100644 --- a/tests/v1/unit/test_client.py +++ b/tests/v1/unit/test_client.py @@ -91,7 +91,7 @@ def test_post_to_field_endpoint_serialization( pseudo_field_request=pseudo_field_request, timeout=TIMEOUT_DEFAULT, ) - expected_json = {"request": pseudo_field_request.model_dump_json(by_alias=True)} + expected_json = {"request": pseudo_field_request.model_dump(by_alias=True)} _mock_post.assert_called_once_with( url="https://mocked.dapla-pseudo-service/test_path", @@ -130,6 +130,6 @@ def test_successful_post_to_sid_endpoint( "X-Correlation-Id": ANY, }, json=expected_json, - stream=False, + stream=True, timeout=TIMEOUT_DEFAULT, )