Skip to content

Commit e4fd30c

Browse files
committed
fix: give the HTTP status of failures without a SCIM error
1 parent 1515013 commit e4fd30c

10 files changed

Lines changed: 41 additions & 13 deletions

File tree

‎doc/changelog.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Changed
2323

2424
Fixed
2525
^^^^^
26+
- A failure the server answers without a SCIM error, such as an HTML page or a ``404`` without
27+
body, gives its HTTP status: ``Error: The server answered 404 without a SCIM error``.
28+
A ``404`` without body used to exit with the code 0.
29+
scim2-client 0.13.2 is now the minimum supported version. :issue:`12`
2630
- The help of ``query``, ``search``, ``delete``, ``modify``, ``bulk`` and ``test`` is displayed
2731
without a server URL and without contacting the server.
2832

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727
requires-python = ">= 3.11"
2828
dependencies = [
2929
"click>=8.5.0",
30-
"scim2-client[httpx2]>=0.13.0",
30+
"scim2-client[httpx2]>=0.13.2",
3131
"scim2-tester>=0.5.1",
3232
"sphinx-click-rst-to-ansi-formatter>=0.2.0",
3333
"pydanclick>=0.5.0",

‎tests/test_create.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_no_command_scimclient_error(runner, httpserver, simple_user_payload):
9393
catch_exceptions=False,
9494
)
9595
assert result.exit_code == 1, result.output
96-
assert "Unexpected response status code: 999" in result.output
96+
assert "Error: The server answered 999 without a SCIM error" in result.output
9797

9898

9999
def test_no_command_validation_error(runner, httpserver, simple_user_payload):

‎tests/test_delete.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_scimclient_error(runner, httpserver):
5151
catch_exceptions=False,
5252
)
5353
assert result.exit_code == 1, result.output
54-
assert "Unexpected response status code: 999" in result.output
54+
assert "Error: The server answered 999 without a SCIM error" in result.output
5555

5656

5757
def test_bad_resource_type(runner, httpserver):

‎tests/test_errors.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,27 @@ def test_success_does_not_fail_the_command(runner, httpserver, simple_user_paylo
7171

7272
assert result.exit_code == 0, result.output
7373
assert result.stderr == ""
74+
75+
76+
@pytest.mark.parametrize(
77+
("status", "content_type", "body"),
78+
[
79+
(404, "text/html", "<html>Not Found</html>"),
80+
(403, "text/plain", "Forbidden"),
81+
(404, "application/scim+json", ""),
82+
(401, "application/json", '{"error": "unauthorized"}'),
83+
(502, "text/html", "<html>Bad Gateway</html>"),
84+
],
85+
)
86+
def test_failure_without_scim_error(runner, httpserver, status, content_type, body):
87+
"""A failure without a SCIM error reports its HTTP status and fails the command."""
88+
httpserver.expect_oneshot_request("/Users/1").respond_with_data(
89+
body, status=status, content_type=content_type
90+
)
91+
92+
result = runner.invoke(
93+
cli, ["--url", httpserver.url_for("/"), "query", "user", "1"]
94+
)
95+
96+
assert result.exit_code == 1, result.output
97+
assert f"Error: The server answered {status} without a SCIM error" in result.output

‎tests/test_modify.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ def test_error_response(invoke, httpserver):
324324

325325

326326
def test_unexpected_response(invoke, httpserver):
327-
"""A response that is not a SCIM message is reported."""
327+
"""A failure that is not a SCIM message reports its status."""
328328
httpserver.expect_oneshot_request("/Users/1", method="PATCH").respond_with_data(
329329
"<html>Internal Server Error</html>", status=500, content_type="text/html"
330330
)
331331

332332
result = invoke("modify", "user", "1", "remove", "nickName")
333333

334334
assert result.exit_code == 1, result.output
335-
assert "Error: Unexpected response content format" in result.output
335+
assert "Error: The server answered 500 without a SCIM error" in result.output
336336

337337

338338
def test_me(invoke, httpserver, simple_user_payload):

‎tests/test_query.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_scimclient_error(runner, httpserver, simple_user_payload):
323323
catch_exceptions=False,
324324
)
325325
assert result.exit_code == 1, result.output
326-
assert "Unexpected response status code: 999" in result.output
326+
assert "Error: The server answered 999 without a SCIM error" in result.output
327327

328328

329329
def test_validation_error(runner, httpserver, simple_user_payload):

‎tests/test_replace.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_no_command_scimclient_error(runner, httpserver, simple_user_payload):
117117
catch_exceptions=False,
118118
)
119119
assert result.exit_code == 1, result.output
120-
assert "Unexpected response status code: 999" in result.output
120+
assert "Error: The server answered 999 without a SCIM error" in result.output
121121

122122

123123
def test_no_command_validation_error(runner, httpserver, simple_user_payload):
@@ -272,7 +272,7 @@ def test_command_scimclient_error(runner, httpserver, simple_user_payload):
272272
catch_exceptions=False,
273273
)
274274
assert result.exit_code == 1, result.output
275-
assert "Unexpected response status code: 999" in result.output
275+
assert "Error: The server answered 999 without a SCIM error" in result.output
276276

277277

278278
def test_command_validation_error(runner, httpserver, simple_user_payload):

‎tests/test_search.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_scimclient_error(runner, httpserver, simple_user_payload):
105105
catch_exceptions=False,
106106
)
107107
assert result.exit_code == 1, result.output
108-
assert "Unexpected response status code: 666" in result.output
108+
assert "Error: The server answered 666 without a SCIM error" in result.output
109109

110110

111111
def test_search_a_resource_type(runner, httpserver, simple_user_payload):

‎uv.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)