Skip to content

Commit

Permalink
tests: verify deprecation message for GenericOAuthenticator.claim_gro…
Browse files Browse the repository at this point in the history
…ups_key
  • Loading branch information
consideRatio committed Sep 3, 2024
1 parent 3d79615 commit 79ef403
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions oauthenticator/tests/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import re
from functools import partial

Expand Down Expand Up @@ -502,3 +503,47 @@ async def test_check_allowed_no_auth_state(get_authenticator, name, allowed):
# these are previously-allowed users who should pass until subsequent
# this check is removed in JupyterHub 5
assert await authenticator.check_allowed(name, None)


@mark.parametrize(
"test_variation_id,class_config,expect_config,expect_loglevel,expect_message",
[
(
"claim_groups_key",
{"claim_groups_key": "groups", "manage_groups": True},
{"auth_state_groups_key": "oauth_user.groups"},
logging.WARNING,
"GenericOAuthenticator.claim_groups_key is deprecated since OAuthenticator 17.0, use GenericOAuthenticator.auth_state_groups_key instead",
),
],
)
async def test_deprecated_config(
caplog,
test_variation_id,
class_config,
expect_config,
expect_loglevel,
expect_message,
):
"""
Tests that a warning is emitted when using a deprecated config and that
configuring the old config ends up configuring the new config.
"""
print(f"Running test variation id {test_variation_id}")
c = Config()
c.GenericOAuthenticator = Config(class_config)

test_logger = logging.getLogger('testlog')
if expect_loglevel == logging.ERROR:
with raises(ValueError, match=expect_message):
GenericOAuthenticator(config=c, log=test_logger)
else:
authenticator = GenericOAuthenticator(config=c, log=test_logger)
for key, value in expect_config.items():
assert getattr(authenticator, key) == value

captured_log_tuples = caplog.record_tuples
print(captured_log_tuples)

expected_log_tuple = (test_logger.name, expect_loglevel, expect_message)
assert expected_log_tuple in captured_log_tuples

0 comments on commit 79ef403

Please sign in to comment.