Skip to content

Commit cb5900e

Browse files
committed
chore: bump to scim2-client 0.1.6
1 parent b02e59f commit cb5900e

13 files changed

Lines changed: 184 additions & 303 deletions

poetry.lock

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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727
[tool.poetry.dependencies]
2828
python = "^3.10"
2929
click = "^8.1.7"
30-
scim2-client = "^0.1.4"
30+
scim2-client = "^0.1.6"
3131
sphinx-click-rst-to-ansi-formatter = "^0.1.0"
3232

3333
[tool.poetry.group.doc]

scim2_cli/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import click
44
from httpx import Client
55
from scim2_client import SCIMClient
6-
from scim2_models import EnterpriseUser
76
from scim2_models import Group
87
from scim2_models import User
98
from sphinx_click.rst_to_ansi_formatter import make_rst_to_ansi_formatter
@@ -25,9 +24,7 @@ def cli(ctx, url):
2524
ctx.ensure_object(dict)
2625
ctx.obj["URL"] = url
2726
client = Client(base_url=ctx.obj["URL"])
28-
ctx.obj["client"] = SCIMClient(
29-
client, resource_types=(User, User[EnterpriseUser], Group)
30-
)
27+
ctx.obj["client"] = SCIMClient(client, resource_types=(User, Group))
3128
ctx.obj["resource_types"] = {
3229
resource_type.__name__.lower(): resource_type
3330
for resource_type in ctx.obj["client"].resource_types

scim2_cli/create.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import sys
2+
13
import click
2-
import httpx
34
from click import ClickException
4-
from pydantic import ValidationError
55
from scim2_client import SCIMClientError
66
from sphinx_click.rst_to_ansi_formatter import make_rst_to_ansi_formatter
77

@@ -40,13 +40,14 @@ def create_cli(ctx, indent, headers):
4040
try:
4141
response = ctx.obj["client"].create(payload, headers=split_headers(headers))
4242

43-
except (httpx.HTTPError, SCIMClientError) as exc:
44-
raise ClickException(exc) from exc
45-
46-
except ValidationError as exc:
47-
payload = formatted_payload(exc.response_payload, indent)
48-
message = f"The server response is invalid:\n{payload}\n{exc}"
49-
raise ClickException(message) from exc
43+
except SCIMClientError as scim_exc:
44+
message = str(scim_exc)
45+
if sys.version_info >= (3, 11) and hasattr(
46+
scim_exc, "__notes__"
47+
): # pragma: no branch
48+
for note in scim_exc.__notes__:
49+
message = f"{message}\n{note}"
50+
raise ClickException(message) from scim_exc
5051

5152
payload = formatted_payload(response.model_dump(), indent)
5253
click.echo(payload)

scim2_cli/delete.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import sys
2+
13
import click
2-
import httpx
34
from click import ClickException
45
from scim2_client import SCIMClientError
56
from scim2_models import Message
@@ -45,8 +46,14 @@ def delete_cli(ctx, resource_type, id, headers, indent):
4546
resource_type, id, headers=split_headers(headers)
4647
)
4748

48-
except (httpx.HTTPError, SCIMClientError) as exc:
49-
raise ClickException(exc) from exc
49+
except SCIMClientError as scim_exc:
50+
message = str(scim_exc)
51+
if sys.version_info >= (3, 11) and hasattr(
52+
scim_exc, "__notes__"
53+
): # pragma: no branch
54+
for note in scim_exc.__notes__:
55+
message = f"{message}\n{note}"
56+
raise ClickException(message) from scim_exc
5057

5158
if response:
5259
payload = (

scim2_cli/query.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import sys
12
from typing import List
23
from typing import Optional
34

45
import click
5-
import httpx
66
from click import ClickException
7-
from pydantic import ValidationError
87
from scim2_client import SCIMClientError
98
from scim2_models import SearchRequest
109
from sphinx_click.rst_to_ansi_formatter import make_rst_to_ansi_formatter
@@ -112,29 +111,22 @@ def query_cli(
112111
)
113112

114113
try:
115-
if resource_type:
116-
response = ctx.obj["client"].query(
117-
resource_type,
118-
id,
119-
search_request=payload,
120-
check_request_payload=check_request_payload,
121-
headers=split_headers(headers),
122-
)
123-
124-
else:
125-
response = ctx.obj["client"].query_all(
126-
search_request=payload,
127-
check_request_payload=check_request_payload,
128-
headers=split_headers(headers),
129-
)
130-
131-
except (httpx.HTTPError, SCIMClientError) as exc:
132-
raise ClickException(exc) from exc
114+
response = ctx.obj["client"].query(
115+
resource_type,
116+
id,
117+
search_request=payload,
118+
check_request_payload=check_request_payload,
119+
headers=split_headers(headers),
120+
)
133121

134-
except ValidationError as exc:
135-
payload = formatted_payload(exc.response_payload, indent)
136-
message = f"The server response is invalid:\n{payload}\n{exc}"
137-
raise ClickException(message) from exc
122+
except SCIMClientError as scim_exc:
123+
message = str(scim_exc)
124+
if sys.version_info >= (3, 11) and hasattr(
125+
scim_exc, "__notes__"
126+
): # pragma: no branch
127+
for note in scim_exc.__notes__:
128+
message = f"{message}\n{note}"
129+
raise ClickException(message) from scim_exc
138130

139131
payload = formatted_payload(response.model_dump(), indent)
140132
click.echo(payload)

scim2_cli/replace.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import sys
2+
13
import click
2-
import httpx
34
from click import ClickException
4-
from pydantic import ValidationError
55
from scim2_client import SCIMClientError
66
from sphinx_click.rst_to_ansi_formatter import make_rst_to_ansi_formatter
77

@@ -40,13 +40,14 @@ def replace_cli(ctx, headers, indent):
4040
try:
4141
response = ctx.obj["client"].replace(payload, headers=split_headers(headers))
4242

43-
except (httpx.HTTPError, SCIMClientError) as exc:
44-
raise ClickException(exc) from exc
45-
46-
except ValidationError as exc:
47-
payload = formatted_payload(exc.response_payload, indent)
48-
message = f"The server response is invalid:\n{payload}\n{exc}"
49-
raise ClickException(message) from exc
43+
except SCIMClientError as scim_exc:
44+
message = str(scim_exc)
45+
if sys.version_info >= (3, 11) and hasattr(
46+
scim_exc, "__notes__"
47+
): # pragma: no branch
48+
for note in scim_exc.__notes__:
49+
message = f"{message}\n{note}"
50+
raise ClickException(message) from scim_exc
5051

5152
payload = formatted_payload(response.model_dump(), indent)
5253
click.echo(payload)

scim2_cli/search.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import sys
12
from typing import List
23

34
import click
4-
import httpx
55
from click import ClickException
6-
from pydantic import ValidationError
76
from scim2_client import SCIMClientError
87
from scim2_models import SearchRequest
98
from sphinx_click.rst_to_ansi_formatter import make_rst_to_ansi_formatter
@@ -100,13 +99,14 @@ def search_cli(
10099
headers=split_headers(headers),
101100
)
102101

103-
except (httpx.HTTPError, SCIMClientError) as exc:
104-
raise ClickException(exc) from exc
105-
106-
except ValidationError as exc:
107-
payload = formatted_payload(exc.response_payload, indent)
108-
message = f"The server response is invalid:\n{payload}\n{exc}"
109-
raise ClickException(message) from exc
102+
except SCIMClientError as scim_exc:
103+
message = str(scim_exc)
104+
if sys.version_info >= (3, 11) and hasattr(
105+
scim_exc, "__notes__"
106+
): # pragma: no branch
107+
for note in scim_exc.__notes__:
108+
message = f"{message}\n{note}"
109+
raise ClickException(message) from scim_exc
110110

111111
payload = formatted_payload(response.model_dump(), indent)
112112
click.echo(payload)

tests/test_create.py

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
def test_stdin(runner, httpserver, simple_user_payload):
77
"""Test that JSON stdin is passed in the POST request."""
88

9-
httpserver.expect_request(
10-
"/Users",
11-
method="POST",
12-
).respond_with_json(
13-
simple_user_payload("new-user"),
9+
response_payload = simple_user_payload("new-user")
10+
httpserver.expect_request("/Users", method="POST").respond_with_json(
11+
response_payload,
1412
status=201,
1513
content_type="application/scim+json",
1614
)
@@ -31,22 +29,7 @@ def test_stdin(runner, httpserver, simple_user_payload):
3129
assert result.exit_code == 0, result.stdout
3230
json_output = json.loads(result.output)
3331

34-
# TODO: actually, there should not be the enterpriseuser schema unless some attributes of the extension are filled
35-
assert json_output == {
36-
"schemas": [
37-
"urn:ietf:params:scim:schemas:core:2.0:User",
38-
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
39-
],
40-
"meta": {
41-
"created": "2010-01-23T04:56:22Z",
42-
"lastModified": "2011-05-13T04:42:34Z",
43-
"location": f"http://localhost:{httpserver.port}/Users/new-user",
44-
"resourceType": "User",
45-
"version": 'W\\/"3694e05e9dff590"',
46-
},
47-
"id": "new-user",
48-
"userName": "new-user@example.com",
49-
}
32+
assert json_output == response_payload
5033

5134

5235
def test_no_stdin(runner, httpserver, simple_user_payload):
@@ -61,29 +44,6 @@ def test_no_stdin(runner, httpserver, simple_user_payload):
6144
assert "Input data is missing" in result.stdout
6245

6346

64-
def test_network_error(runner):
65-
"""Test httpx errors handling."""
66-
67-
payload = {
68-
"schemas": [
69-
"urn:ietf:params:scim:schemas:core:2.0:User",
70-
],
71-
"userName": "new-user@example.com",
72-
}
73-
74-
result = runner.invoke(
75-
cli,
76-
[
77-
"http://invalid.test",
78-
"create",
79-
],
80-
catch_exceptions=False,
81-
input=json.dumps(payload),
82-
)
83-
assert result.exit_code == 1, result.stdout
84-
assert "Name or service not known" in result.stdout
85-
86-
8747
def test_scimclient_error(runner, httpserver, simple_user_payload):
8848
"""Test scim2_client errors handling."""
8949

@@ -145,4 +105,4 @@ def test_validation_error(runner, httpserver, simple_user_payload):
145105
input=json.dumps(payload),
146106
)
147107
assert result.exit_code == 1, result.stdout
148-
assert "The server response is invalid" in result.stdout
108+
assert "Expected type User but got undefined object with no schema" in result.stdout

tests/test_delete.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,6 @@ def test_nominal_case(runner, httpserver):
2828
assert result.exit_code == 0, result.stdout
2929

3030

31-
def test_network_error(runner):
32-
"""Test httpx errors handling."""
33-
34-
result = runner.invoke(
35-
cli,
36-
[
37-
"http://invalid.test",
38-
"delete",
39-
"user",
40-
"dummy-id",
41-
],
42-
catch_exceptions=False,
43-
)
44-
assert result.exit_code == 1, result.stdout
45-
assert "Name or service not known" in result.stdout
46-
47-
4831
def test_scimclient_error(runner, httpserver):
4932
"""Test scim2_client errors handling."""
5033

0 commit comments

Comments
 (0)