diff --git a/mozilla_django_oidc_db/setup_configuration/models.py b/mozilla_django_oidc_db/setup_configuration/models.py index 048f417..84f71f9 100644 --- a/mozilla_django_oidc_db/setup_configuration/models.py +++ b/mozilla_django_oidc_db/setup_configuration/models.py @@ -49,23 +49,21 @@ def get_endpoint_endpoint_model(endpoint_data): class AdminOIDCConfigurationModel(ConfigurationModel): # Change default to True - enabled: bool | None = DjangoModelRef(OpenIDConnectConfig, "enabled", default=True) + enabled: bool = DjangoModelRef(OpenIDConnectConfig, "enabled", default=True) # Json - claim_mapping: dict | None = DjangoModelRef(OpenIDConnectConfig, "claim_mapping") + claim_mapping: dict = DjangoModelRef(OpenIDConnectConfig, "claim_mapping") # Arrays are overridden to make the typing simpler (the underlying Django field is an ArrayField, which is non-standard) - username_claim: list[str] | None = DjangoModelRef( - OpenIDConnectConfig, "username_claim" - ) - groups_claim: list[str] | None = DjangoModelRef(OpenIDConnectConfig, "groups_claim") - superuser_group_names: list[str] | None = DjangoModelRef( + username_claim: list[str] = DjangoModelRef(OpenIDConnectConfig, "username_claim") + groups_claim: list[str] = DjangoModelRef(OpenIDConnectConfig, "groups_claim") + superuser_group_names: list[str] = DjangoModelRef( OpenIDConnectConfig, "superuser_group_names" ) - default_groups: list[str] | None = DjangoModelRef( + default_groups: list[str] = DjangoModelRef( OpenIDConnectConfig, "superuser_group_names" ) - oidc_rp_scopes_list: list[str] | None = DjangoModelRef( + oidc_rp_scopes_list: list[str] = DjangoModelRef( OpenIDConnectConfig, "oidc_rp_scopes_list" ) diff --git a/tests/setupconfig/test_steps.py b/tests/setupconfig/test_steps.py index 6314fdb..bd97540 100644 --- a/tests/setupconfig/test_steps.py +++ b/tests/setupconfig/test_steps.py @@ -148,25 +148,36 @@ def test_configure_use_discovery_endpoint(discovery_endpoint_config_yml): @pytest.mark.django_db -def test_configure_discovery_failure(requests_mock, discovery_endpoint_config_yml): - mock_kwargs = ( +@pytest.mark.parametrize( + "mock_kwargs", + ( {"exc": requests.ConnectTimeout}, {"exc": requests.ConnectionError}, {"status_code": 404}, {"status_code": 403}, {"status_code": 500}, + ), + ids=[ + "Connection Timeout", + "Connection Error", + "Status 404", + "Status 403", + "Status 500", + ], +) +def test_configure_discovery_failure( + requests_mock, discovery_endpoint_config_yml, mock_kwargs +): + requests_mock.get( + f"{KEYCLOAK_BASE_URL}.well-known/openid-configuration", + **mock_kwargs, ) - for mock_config in mock_kwargs: - requests_mock.get( - f"{KEYCLOAK_BASE_URL}.well-known/openid-configuration", - **mock_config, - ) - with pytest.raises(ConfigurationRunFailed): - execute_single_step( - AdminOIDCConfigurationStep, yaml_source=discovery_endpoint_config_yml - ) + with pytest.raises(ConfigurationRunFailed): + execute_single_step( + AdminOIDCConfigurationStep, yaml_source=discovery_endpoint_config_yml + ) - config = OpenIDConnectConfig.get_solo() - assert not config.enabled - assert config.oidc_op_discovery_endpoint == "" + config = OpenIDConnectConfig.get_solo() + assert not config.enabled + assert config.oidc_op_discovery_endpoint == ""