Skip to content

Commit

Permalink
Issue #3: preserve UDM errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fbotner committed Oct 14, 2022
1 parent a65c2f7 commit 30e7e34
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

1.0.10 (2022-10-13)
-------------------

* Pass trough UDM REST API error in ``CreateError`` and ``ModifyError`` exceptions.

1.0.9 (2022-09-15)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
python_requires=">=3.6",
scripts=["update_openapi_client"],
url="https://github.com/univention/python-udm-rest-api-client",
version="1.0.9",
version="1.0.10",
zip_safe=False,
)
34 changes: 26 additions & 8 deletions tests/test_base_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,19 @@ async def test_saving_obj_with_bad_property_value(faker, user_created_via_http,

@pytest.mark.asyncio
@pytest.mark.parametrize(
"error", [
("password", "pass", '1 error(s) occurred:Request argument "password" Password policy error: The password is too short, at least 8 characters needed!'),
("birthday", "pass", '1 error(s) occurred:Request argument "birthday" The property birthday has an invalid value: Date does not match format "%Y-%m-%d".'),
]
"error",
[
(
"password",
"pass",
'1 error(s) occurred:Request argument "password" Password policy error: The password is too short, at least 8 characters needed!',
),
(
"birthday",
"pass",
'1 error(s) occurred:Request argument "birthday" The property birthday has an invalid value: Date does not match format "%Y-%m-%d".',
),
],
)
async def test_modify_error_exception(user_created_via_http, udm_kwargs, error):
dn, url, user = user_created_via_http()
Expand All @@ -724,10 +733,19 @@ async def test_modify_error_exception(user_created_via_http, udm_kwargs, error):

@pytest.mark.asyncio
@pytest.mark.parametrize(
"error", [
("e-mail", "pass", '1 error(s) occurred:Request argument "e-mail" The property e-mail has an invalid value: Value must be of type array not str.'),
("username", None, '1 error(s) occurred:Request argument "dn" Information provided is not sufficient. The following properties are missing:username'),
]
"error",
[
(
"e-mail",
"pass",
'1 error(s) occurred:Request argument "e-mail" The property e-mail has an invalid value: Value must be of type array not str.',
),
(
"username",
None,
'1 error(s) occurred:Request argument "dn" Information provided is not sufficient. The following properties are missing:username',
),
],
)
async def test_create_error_exception(udm_kwargs, error, faker):
attribute, value, msg = error
Expand Down
2 changes: 1 addition & 1 deletion udm_rest_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
]
__author__ = """Daniel Troeder"""
__email__ = "troeder@univention.de"
__version__ = "1.0.9"
__version__ = "1.0.10"
2 changes: 1 addition & 1 deletion udm_rest_client/base_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ async def call_openapi( # noqa: C901
with contextlib.suppress(KeyError, ValueError):
resp_obj = json.loads(exc.body)
msg = resp_obj["error"]["message"].replace("\n", "")
error = resp_obj['error']['error']
error = resp_obj["error"]["error"]
if exc.status == 422 and operation == "create":
raise CreateError(msg, reason=reason, error=error, dn=dn, status=exc.status) from exc
if exc.status == 422 and operation == "update":
Expand Down

0 comments on commit 30e7e34

Please sign in to comment.