1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
import pytest
from globus_sdk import AuthAPIError
from globus_sdk.testing import construct_error
def test_auth_error_get_args_simple():
err = construct_error(
error_class=AuthAPIError,
http_status=404,
body={"detail": "simple auth error message"},
)
req = err._underlying_response.request
assert err._get_args() == [
req.method,
req.url,
None,
404,
None,
"simple auth error message",
]
def test_nested_auth_error_message_and_code():
err = construct_error(
error_class=AuthAPIError,
http_status=404,
body={
"errors": [
{"detail": "nested auth error message", "code": "Auth Error"},
{
"title": "some secondary error",
"code": "HiddenError",
},
]
},
)
assert err.message == "nested auth error message; some secondary error"
assert err.code is None
@pytest.mark.parametrize(
"error_body, expected_error_id",
(
(
{
"errors": [
{"id": "foo"},
]
},
"foo",
),
(
{
"errors": [
{"id": "foo"},
{"id": "bar"},
]
},
None,
),
(
{
"errors": [
{"id": "foo"},
{"id": "foo"},
]
},
"foo",
),
(
{"errors": [{"id": "foo"}, {"id": "foo"}, {}]},
"foo",
),
),
)
def test_auth_error_parses_error_id(error_body, expected_error_id):
err = construct_error(
error_class=AuthAPIError,
http_status=404,
body=error_body,
)
assert err.request_id == expected_error_id
|