From 6d005605a9da5d63696b4daee2df0e765e97cbb2 Mon Sep 17 00:00:00 2001 From: Benjamin Gerber Date: Wed, 29 Nov 2023 10:03:21 +0100 Subject: [PATCH 1/2] Add patch method in acceptance connection --- .../app/c2cwsgiutils_app/services.py | 8 +++++++- acceptance_tests/tests/tests/test_connection.py | 3 +++ c2cwsgiutils/acceptance/connection.py | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/acceptance_tests/app/c2cwsgiutils_app/services.py b/acceptance_tests/app/c2cwsgiutils_app/services.py index f4b1edd2a..c3589aa0a 100644 --- a/acceptance_tests/app/c2cwsgiutils_app/services.py +++ b/acceptance_tests/app/c2cwsgiutils_app/services.py @@ -98,7 +98,13 @@ def tracking(request): @empty_service.put() -def empty(request): +def empty_put(request): + request.response.status_code = 204 + return request.response + + +@empty_service.patch() +def empty_patch(request): request.response.status_code = 204 return request.response diff --git a/acceptance_tests/tests/tests/test_connection.py b/acceptance_tests/tests/tests/test_connection.py index 6e3864ebe..ea1fb342c 100644 --- a/acceptance_tests/tests/tests/test_connection.py +++ b/acceptance_tests/tests/tests/test_connection.py @@ -1,2 +1,5 @@ def test_empty_response(app_connection): assert app_connection.put_json("empty", expected_status=204) is None + +def test_empty_response(app_connection): + assert app_connection.patch_json("empty", expected_status=204) is None diff --git a/c2cwsgiutils/acceptance/connection.py b/c2cwsgiutils/acceptance/connection.py index 51aa538e3..65d9f735b 100644 --- a/c2cwsgiutils/acceptance/connection.py +++ b/c2cwsgiutils/acceptance/connection.py @@ -159,12 +159,27 @@ def put_json( cache_expected: CacheExpected = CacheExpected.NO, **kwargs: Any, ) -> Any: - """POST the given URL (relative to the root of API).""" + """PUT the given URL (relative to the root of API).""" with self.session.put(self.base_url + url, headers=self._merge_headers(headers, cors), **kwargs) as r: check_response(r, expected_status, cache_expected) self._check_cors(cors, r) return _get_json(r) + def patch_json( + self, + url: str, + expected_status: int = 200, + headers: Optional[Mapping[str, str]] = None, + cors: bool = True, + cache_expected: CacheExpected = CacheExpected.NO, + **kwargs: Any, + ) -> Any: + """PATCH the given URL (relative to the root of API).""" + with self.session.patch(self.base_url + url, headers=self._merge_headers(headers, cors), **kwargs) as r: + check_response(r, expected_status, cache_expected) + self._check_cors(cors, r) + return _get_json(r) + def delete( self, url: str, From d0e740acd69b5e841d003aadc9de705855447597 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:21:55 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- acceptance_tests/tests/tests/test_connection.py | 1 + c2cwsgiutils/acceptance/connection.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/acceptance_tests/tests/tests/test_connection.py b/acceptance_tests/tests/tests/test_connection.py index ea1fb342c..f2cb6aa51 100644 --- a/acceptance_tests/tests/tests/test_connection.py +++ b/acceptance_tests/tests/tests/test_connection.py @@ -1,5 +1,6 @@ def test_empty_response(app_connection): assert app_connection.put_json("empty", expected_status=204) is None + def test_empty_response(app_connection): assert app_connection.patch_json("empty", expected_status=204) is None diff --git a/c2cwsgiutils/acceptance/connection.py b/c2cwsgiutils/acceptance/connection.py index 65d9f735b..eb5a3b226 100644 --- a/c2cwsgiutils/acceptance/connection.py +++ b/c2cwsgiutils/acceptance/connection.py @@ -175,7 +175,9 @@ def patch_json( **kwargs: Any, ) -> Any: """PATCH the given URL (relative to the root of API).""" - with self.session.patch(self.base_url + url, headers=self._merge_headers(headers, cors), **kwargs) as r: + with self.session.patch( + self.base_url + url, headers=self._merge_headers(headers, cors), **kwargs + ) as r: check_response(r, expected_status, cache_expected) self._check_cors(cors, r) return _get_json(r)