refactor: avoid to directly use the 'configuration' fixture in tests

This commit is contained in:
Éloi Rivard 2023-12-19 18:22:31 +01:00
parent bf8d62e08f
commit 52fc93a481
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
6 changed files with 20 additions and 21 deletions

View file

@ -26,7 +26,7 @@ def default_fields():
read = set()
write = set()
for acl in current_app.config.get("ACL", {}).values():
if "FILTER" not in acl:
if not acl.get("FILTER"):
read |= set(acl.get("READ", []))
write |= set(acl.get("WRITE", []))

View file

@ -88,16 +88,16 @@ def validate(config, validate_remote=False):
def validate_keypair(config):
if (
"OIDC" in config
and "JWT" in config["OIDC"]
config.get("OIDC")
and config["OIDC"].get("JWT")
and not config["OIDC"]["JWT"].get("PUBLIC_KEY")
and not current_app.debug
):
raise ConfigurationException("No public key has been set")
if (
"OIDC" in config
and "JWT" in config["OIDC"]
config.get("OIDC")
and config["OIDC"].get("JWT")
and not config["OIDC"]["JWT"].get("PRIVATE_KEY")
and not current_app.debug
):

View file

@ -132,7 +132,7 @@ def generate_user_info(user, scope):
def generate_user_claims(user, claims, jwt_mapping_config=None):
jwt_mapping_config = {
**DEFAULT_JWT_MAPPING,
**current_app.config["OIDC"]["JWT"].get("MAPPING", {}),
**(current_app.config["OIDC"]["JWT"].get("MAPPING") or {}),
**(jwt_mapping_config or {}),
}
@ -357,8 +357,9 @@ class ClientManagementMixin:
return None
bearer_token = auth_header.split()[1]
if bearer_token not in current_app.config.get("OIDC", {}).get(
"DYNAMIC_CLIENT_REGISTRATION_TOKENS", []
if bearer_token not in (
current_app.config.get("OIDC", {}).get("DYNAMIC_CLIENT_REGISTRATION_TOKENS")
or []
):
return None

View file

@ -186,9 +186,9 @@ def test_datetime_utc_field_invalid_timezone(testclient):
)
def test_fieldlist_add_readonly(testclient, logged_user, configuration):
configuration["ACL"]["DEFAULT"]["WRITE"].remove("phone_numbers")
configuration["ACL"]["DEFAULT"]["READ"].append("phone_numbers")
def test_fieldlist_add_readonly(testclient, logged_user):
testclient.app.config["ACL"]["DEFAULT"]["WRITE"].remove("phone_numbers")
testclient.app.config["ACL"]["DEFAULT"]["READ"].append("phone_numbers")
logged_user.reload()
res = testclient.get("/profile/user")
@ -205,9 +205,9 @@ def test_fieldlist_add_readonly(testclient, logged_user, configuration):
testclient.post("/profile/user", data, status=403)
def test_fieldlist_remove_readonly(testclient, logged_user, configuration):
configuration["ACL"]["DEFAULT"]["WRITE"].remove("phone_numbers")
configuration["ACL"]["DEFAULT"]["READ"].append("phone_numbers")
def test_fieldlist_remove_readonly(testclient, logged_user):
testclient.app.config["ACL"]["DEFAULT"]["WRITE"].remove("phone_numbers")
testclient.app.config["ACL"]["DEFAULT"]["READ"].append("phone_numbers")
logged_user.reload()
logged_user.phone_numbers = ["555-555-000", "555-555-111"]

View file

@ -384,12 +384,10 @@ def test_inline_validation(testclient, logged_admin, user):
res.mustcontain("The email 'john@doe.com' is already used")
def test_inline_validation_keep_indicators(
configuration, testclient, logged_admin, user
):
configuration["ACL"]["DEFAULT"]["WRITE"].remove("display_name")
configuration["ACL"]["DEFAULT"]["READ"].append("display_name")
configuration["ACL"]["ADMIN"]["WRITE"].append("display_name")
def test_inline_validation_keep_indicators(testclient, logged_admin, user):
testclient.app.config["ACL"]["DEFAULT"]["WRITE"].remove("display_name")
testclient.app.config["ACL"]["DEFAULT"]["READ"].append("display_name")
testclient.app.config["ACL"]["ADMIN"]["WRITE"].append("display_name")
logged_admin.reload()
user.reload()

View file

@ -29,7 +29,7 @@ def test_registration_without_email_validation(testclient, backend):
def test_registration_with_email_validation(testclient, backend, smtpd):
"""
Tests a nominal registration without email validation.
Tests a nominal registration with email validation.
"""
testclient.app.config["ENABLE_REGISTRATION"] = True