Skip to content

Commit

Permalink
Fixed eol_version for a deprecation message, and caught warnings on t…
Browse files Browse the repository at this point in the history
…he legacy AuthenticatorConverter test.
  • Loading branch information
airstandley committed Sep 17, 2019
1 parent c097bb9 commit a063130
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion flask_rebar/swagger_generation/generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def format_path_for_swagger(path):
return subbed_path, args


@deprecated(eol_version="2,0")
@deprecated(eol_version="2.0")
def convert_header_api_key_authenticator(authenticator):
"""
Converts a HeaderApiKeyAuthenticator object to a Swagger definition.
Expand Down
56 changes: 30 additions & 26 deletions tests/swagger_generation/test_generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:license: MIT, see LICENSE for details.
"""
import unittest
import warnings

from flask_rebar.swagger_generation.generator_utils import PathArgument
from flask_rebar.swagger_generation.generator_utils import flatten
Expand Down Expand Up @@ -197,30 +198,33 @@ class TestAuthenticatorConverter(unittest.TestCase):
def test_legacy_behaviour(self):
"""Check that the AuthenticatorConverter maintains backward compatibility with functions as the converters
"""

converter = AuthenticatorConverter(
{HeaderApiKeyAuthenticator: convert_header_api_key_authenticator}
)
converter.register(MyCustomAuthenticator, convert_my_customer_authenticator)

auth_1 = HeaderApiKeyAuthenticator("X-Test-Header")
auth_2 = MyCustomAuthenticator()

registry = HandlerRegistry(default_authenticators=[auth_1, auth_2])

self.assertEqual(
converter.get_security_requirement(auth_1), [{"sharedSecret": []}]
)
self.assertEqual(converter.get_security_requirement(auth_2), [{"myAuth": []}])

self.assertEqual(
converter.get_security_schemes(registry),
{
"sharedSecret": {
"type": "apiKey",
"in": "header",
"name": "X-Test-Header",
with warnings.catch_warnings(record=True) as caught_warnings:
converter = AuthenticatorConverter(
{HeaderApiKeyAuthenticator: convert_header_api_key_authenticator}
)
converter.register(MyCustomAuthenticator, convert_my_customer_authenticator)

auth_1 = HeaderApiKeyAuthenticator("X-Test-Header")
auth_2 = MyCustomAuthenticator()

registry = HandlerRegistry(default_authenticators=[auth_1, auth_2])

self.assertEqual(
converter.get_security_requirement(auth_1), [{"sharedSecret": []}]
)
self.assertEqual(
converter.get_security_requirement(auth_2), [{"myAuth": []}]
)

self.assertEqual(
converter.get_security_schemes(registry),
{
"sharedSecret": {
"type": "apiKey",
"in": "header",
"name": "X-Test-Header",
},
"myAuth": {"type": "basic"},
},
"myAuth": {"type": "basic"},
},
)
)
self.assertTrue(caught_warnings)

0 comments on commit a063130

Please sign in to comment.