Skip to content

Commit 281588f

Browse files
committed
feat: TestSCIMClient raise a UnexpectedContentFormat exception when response is not JSON
1 parent f6ecee2 commit 281588f

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

doc/changelog.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
[0.3.3] - Unreleased
5+
--------------------
6+
7+
Added
8+
^^^^^
9+
- :class:`~scim2_client.engines.werkzeug.TestSCIMClient` raise a
10+
:class:`~scim2_client.UnexpectedContentFormat` exception when response is not JSON.
11+
412
[0.3.2] - 2024-11-29
513
--------------------
614

@@ -32,12 +40,12 @@ Fixed
3240
Added
3341
^^^^^
3442
- The `Unknown resource type` request error keeps a reference to the faulty payload.
35-
- New `werkzeug` request engine for application development purpose.
36-
- New `AsyncSCIMClient` request engine. :issue:`1`
43+
- New :class:`~scim2_client.engines.werkzeug.TestSCIMClient` request engine for application development purpose.
44+
- New :class:`~scim2_client.engines.httpx.AsyncSCIMClient` request engine. :issue:`1`
3745

3846
Changed
3947
^^^^^^^
40-
- Separate httpx network code and SCIM code in separate file as a basis for async support (and maybe other request engines).
48+
- Separate httpx network code and SCIM code in separate file as a basis for async support (and other request engines).
4149

4250
[0.2.2] - 2024-11-12
4351
--------------------

scim2_client/engines/werkzeug.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from contextlib import contextmanager
23
from typing import Optional
34
from typing import Union
@@ -13,13 +14,17 @@
1314

1415
from scim2_client.client import BaseSyncSCIMClient
1516
from scim2_client.errors import SCIMClientError
17+
from scim2_client.errors import UnexpectedContentFormat
1618

1719

1820
@contextmanager
1921
def handle_response_error(response):
2022
try:
2123
yield
2224

25+
except json.decoder.JSONDecodeError as exc:
26+
raise UnexpectedContentFormat(source=response) from exc
27+
2328
except SCIMClientError as exc:
2429
exc.source = response
2530
raise exc

tests/engines/test_werkzeug.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
from scim2_models import ResourceType
33
from scim2_models import SearchRequest
44
from scim2_models import User
5+
from werkzeug.wrappers import Request
6+
from werkzeug.wrappers import Response
57

68
from scim2_client.engines.werkzeug import TestSCIMClient
79
from scim2_client.errors import SCIMResponseErrorObject
10+
from scim2_client.errors import UnexpectedContentFormat
811

912
scim2_server = pytest.importorskip("scim2_server")
1013
from scim2_server.backend import InMemoryBackend # noqa: E402
@@ -61,3 +64,15 @@ def test_werkzeug_engine(scim_client):
6164
scim_client.delete(User, response_user.id)
6265
with pytest.raises(SCIMResponseErrorObject):
6366
scim_client.query(User, response_user.id)
67+
68+
69+
def test_no_json():
70+
"""Test that pages that do not return JSON raise an UnexpectedContentFormat error."""
71+
72+
@Request.application
73+
def application(request):
74+
return Response("Hello, World!", content_type="application/scim+json")
75+
76+
client = TestSCIMClient(app=application, resource_models=(User,))
77+
with pytest.raises(UnexpectedContentFormat):
78+
client.query(url="/")

0 commit comments

Comments
 (0)