Skip to content

Commit

Permalink
Add test for raising most specific error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwann committed Mar 18, 2022
1 parent 836cf68 commit 84c772b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/decorators/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pytest
import requests
from connexion.exceptions import (OAuthProblem, OAuthResponseProblem,
OAuthScopeProblem)
OAuthScopeProblem, BadRequestProblem,
ConnexionException)


def test_get_tokeninfo_url(monkeypatch, security_handler_factory):
Expand Down Expand Up @@ -220,3 +221,20 @@ def test_verify_security_oauthproblem(security_handler_factory):
secured_func(request)

assert str(exc_info.value) == '401 Unauthorized: No authorization token provided'

@pytest.mark.parametrize(
'errors, most_specific',
[
([OAuthProblem()], OAuthProblem),
([OAuthProblem(), OAuthScopeProblem([], [])], OAuthScopeProblem),
([OAuthProblem(), OAuthScopeProblem([], []), BadRequestProblem], OAuthScopeProblem),
([OAuthProblem(), OAuthScopeProblem([], []), BadRequestProblem, ConnexionException], OAuthScopeProblem),
([BadRequestProblem(), ConnexionException()], BadRequestProblem),
([ConnexionException()], ConnexionException),
]
)
def test_raise_most_specific(errors, most_specific, security_handler_factory):
"""Tests whether most specific exception is raised from a list."""

with pytest.raises(most_specific):
security_handler_factory._raise_most_specific(errors)

0 comments on commit 84c772b

Please sign in to comment.