Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 5.2] Add patch method in acceptance connection #2047

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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

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
19 changes: 18 additions & 1 deletion c2cwsgiutils/acceptance/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,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
Loading