From 79ef40367bafdd3299d3a53410e1fba488fa4cda Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 3 Sep 2024 11:23:17 +0200 Subject: [PATCH] tests: verify deprecation message for GenericOAuthenticator.claim_groups_key --- oauthenticator/tests/test_generic.py | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/oauthenticator/tests/test_generic.py b/oauthenticator/tests/test_generic.py index 222f3225..e3225039 100644 --- a/oauthenticator/tests/test_generic.py +++ b/oauthenticator/tests/test_generic.py @@ -1,4 +1,5 @@ import json +import logging import re from functools import partial @@ -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