Skip to content

Commit 84c772b

Browse files
committed
Add test for raising most specific error
1 parent 836cf68 commit 84c772b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/decorators/test_security.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import pytest
55
import requests
66
from connexion.exceptions import (OAuthProblem, OAuthResponseProblem,
7-
OAuthScopeProblem)
7+
OAuthScopeProblem, BadRequestProblem,
8+
ConnexionException)
89

910

1011
def test_get_tokeninfo_url(monkeypatch, security_handler_factory):
@@ -220,3 +221,20 @@ def test_verify_security_oauthproblem(security_handler_factory):
220221
secured_func(request)
221222

222223
assert str(exc_info.value) == '401 Unauthorized: No authorization token provided'
224+
225+
@pytest.mark.parametrize(
226+
'errors, most_specific',
227+
[
228+
([OAuthProblem()], OAuthProblem),
229+
([OAuthProblem(), OAuthScopeProblem([], [])], OAuthScopeProblem),
230+
([OAuthProblem(), OAuthScopeProblem([], []), BadRequestProblem], OAuthScopeProblem),
231+
([OAuthProblem(), OAuthScopeProblem([], []), BadRequestProblem, ConnexionException], OAuthScopeProblem),
232+
([BadRequestProblem(), ConnexionException()], BadRequestProblem),
233+
([ConnexionException()], ConnexionException),
234+
]
235+
)
236+
def test_raise_most_specific(errors, most_specific, security_handler_factory):
237+
"""Tests whether most specific exception is raised from a list."""
238+
239+
with pytest.raises(most_specific):
240+
security_handler_factory._raise_most_specific(errors)

0 commit comments

Comments
 (0)