Skip to content

Commit 8abe7c4

Browse files
committed
update error handling in tests
1 parent 63d9fc6 commit 8abe7c4

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

mergin/test/test_client.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,26 +2885,29 @@ def test_mc_without_login():
28852885
assert config["server_configured"]
28862886

28872887
# without login should not be able to access workspaces
2888-
with pytest.raises(ClientError, match="Authentication information is missing or invalid."):
2888+
with pytest.raises(ClientError) as e:
28892889
mc.workspaces_list()
28902890

2891+
assert e.value.http_error == 401
2892+
assert e.value.detail == '"Authentication information is missing or invalid."\n'
2893+
28912894

28922895
def test_do_request_error_handling(mc: MerginClient):
28932896

2894-
try:
2897+
with pytest.raises(ClientError) as e:
28952898
mc.get("/v2/sso/[email protected]")
2896-
except ClientError as e:
2897-
assert e.http_error == 404
2898-
assert (
2899-
e.detail
2900-
== "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
2901-
)
2902-
assert ": 404," in e.server_response
2899+
2900+
assert e.value.http_error == 404
2901+
assert (
2902+
e.value.detail
2903+
== "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."
2904+
)
2905+
assert ": 404," in e.value.server_response
29032906

29042907
workspaces = mc.workspaces_list()
29052908

2906-
try:
2909+
with pytest.raises(ClientError) as e:
29072910
mc.create_user("[email protected]", "123", workspace_id=workspaces[0]["id"], workspace_role=WorkspaceRole.GUEST)
2908-
except ClientError as e:
2909-
assert e.http_error == 400
2910-
assert "Passwords must be at least 8 characters long." in e.detail
2911+
2912+
assert e.value.http_error == 400
2913+
assert "Passwords must be at least 8 characters long." in e.value.detail

0 commit comments

Comments
 (0)