Skip to content

Commit

Permalink
Merge pull request #2048 from camptocamp/backport/2046-to-6.0
Browse files Browse the repository at this point in the history
[Backport 6.0] Add patch method in acceptance connection
  • Loading branch information
ger-benjamin authored Nov 29, 2023
2 parents a86848d + e4fee61 commit 2f2b74c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
8 changes: 7 additions & 1 deletion acceptance_tests/app/c2cwsgiutils_app/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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

Expand Down
4 changes: 4 additions & 0 deletions acceptance_tests/tests/tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,2 +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
3 changes: 3 additions & 0 deletions acceptance_tests/tests/tests/test_db_maintenance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

import pytest

LOG = logging.getLogger(__name__)


Expand All @@ -16,6 +18,7 @@ def _query(app_connection, params, expected=None):
assert response == all_expected


@pytest.mark.skip(reason="Too many false positives")
def test_api(app_connection):
# _query(app_connection, {}, {"current_readonly": None})
_query(app_connection, {"readonly": "true"})
Expand Down
19 changes: 18 additions & 1 deletion c2cwsgiutils/acceptance/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,29 @@ 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,
Expand Down

0 comments on commit 2f2b74c

Please sign in to comment.