|
1 | 1 | from unittest import mock |
2 | 2 |
|
3 | 3 | import pytest |
4 | | -from django.conf import settings |
5 | 4 | from django.db import connection |
6 | 5 |
|
7 | 6 | from ansible_base.authentication.models import AuthenticatorMap, AuthenticatorUser |
@@ -418,15 +417,23 @@ def test_create_claims_revoke(local_authenticator_map, process_function, trigger |
418 | 417 | ], |
419 | 418 | ) |
420 | 419 | @pytest.mark.django_db |
421 | | -def test_process_groups(trigger_condition, groups, case_insensitive, has_access, settings_override_mutable): |
| 420 | +def test_process_groups(trigger_condition, groups, case_insensitive, has_access): |
422 | 421 | """ |
423 | 422 | Test the process_groups function. |
424 | 423 | """ |
425 | | - with settings_override_mutable("FLAGS"): |
426 | | - settings.FLAGS["FEATURE_CASE_INSENSITIVE_AUTH_MAPS"][0]["value"] = case_insensitive |
427 | | - res = claims.process_groups(trigger_condition, groups, map_id=1, tracking_id="xxx") |
| 424 | + from flags.state import disable_flag, enable_flag |
| 425 | + |
| 426 | + if case_insensitive: |
| 427 | + enable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
| 428 | + else: |
| 429 | + disable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
428 | 430 |
|
429 | | - assert res is has_access |
| 431 | + try: |
| 432 | + res = claims.process_groups(trigger_condition, groups, map_id=1, tracking_id="xxx") |
| 433 | + assert res is has_access |
| 434 | + finally: |
| 435 | + # Clean up: disable the flag after test |
| 436 | + disable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
430 | 437 |
|
431 | 438 |
|
432 | 439 | @pytest.mark.parametrize( |
@@ -914,12 +921,20 @@ def test_has_access_with_join(current_access, new_access, condition, expected): |
914 | 921 | ], |
915 | 922 | ) |
916 | 923 | @pytest.mark.django_db |
917 | | -def test_process_user_attributes(trigger_condition, attributes, expected, case_insensitive, settings_override_mutable): |
918 | | - with settings_override_mutable("FLAGS"): |
919 | | - settings.FLAGS["FEATURE_CASE_INSENSITIVE_AUTH_MAPS"][0]["value"] = case_insensitive |
920 | | - res = claims.process_user_attributes(trigger_condition, attributes, map_id=1, tracking_id="xxx") |
| 924 | +def test_process_user_attributes(trigger_condition, attributes, expected, case_insensitive): |
| 925 | + from flags.state import disable_flag, enable_flag |
921 | 926 |
|
922 | | - assert res is expected |
| 927 | + if case_insensitive: |
| 928 | + enable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
| 929 | + else: |
| 930 | + disable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
| 931 | + |
| 932 | + try: |
| 933 | + res = claims.process_user_attributes(trigger_condition, attributes, map_id=1, tracking_id="xxx") |
| 934 | + assert res is expected |
| 935 | + finally: |
| 936 | + # Clean up: disable the flag after test |
| 937 | + disable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
923 | 938 |
|
924 | 939 |
|
925 | 940 | def test_update_user_claims_extra_data(user, local_authenticator_map): |
@@ -2207,17 +2222,22 @@ def test_validate_attribute_conditions(self, condition, expected_result, expecte |
2207 | 2222 | ), |
2208 | 2223 | ], |
2209 | 2224 | ) |
2210 | | - def test_prepare_case_insensitive_data( |
2211 | | - self, case_insensitive_enabled, trigger_condition, attributes, expected_trigger, expected_attrs, settings_override_mutable |
2212 | | - ): |
| 2225 | + def test_prepare_case_insensitive_data(self, case_insensitive_enabled, trigger_condition, attributes, expected_trigger, expected_attrs): |
2213 | 2226 | """Test _prepare_case_insensitive_data with case insensitivity enabled/disabled""" |
2214 | | - with settings_override_mutable("FLAGS"): |
2215 | | - settings.FLAGS["FEATURE_CASE_INSENSITIVE_AUTH_MAPS"][0]["value"] = case_insensitive_enabled |
| 2227 | + from flags.state import disable_flag, enable_flag |
2216 | 2228 |
|
2217 | | - result_trigger, result_attrs = claims._prepare_case_insensitive_data(trigger_condition, attributes, 1, "test-id") |
| 2229 | + if case_insensitive_enabled: |
| 2230 | + enable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
| 2231 | + else: |
| 2232 | + disable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
2218 | 2233 |
|
| 2234 | + try: |
| 2235 | + result_trigger, result_attrs = claims._prepare_case_insensitive_data(trigger_condition, attributes, 1, "test-id") |
2219 | 2236 | assert result_trigger == expected_trigger |
2220 | 2237 | assert result_attrs == expected_attrs |
| 2238 | + finally: |
| 2239 | + # Clean up: disable the flag after test |
| 2240 | + disable_flag("FEATURE_CASE_INSENSITIVE_AUTH_MAPS_ENABLED") |
2221 | 2241 |
|
2222 | 2242 | @pytest.mark.parametrize( |
2223 | 2243 | "user_value, expected", |
|
0 commit comments