refactor: fix lint warnings and remove stale type: ignore comments

This commit is contained in:
Johan Lundberg 2026-02-18 13:08:03 +01:00
parent 8c91edf137
commit 64f8c1936b
No known key found for this signature in database
GPG key ID: A6C152738D03C7D1
5 changed files with 34 additions and 28 deletions

View file

@ -19,23 +19,24 @@ scope = ["openid", "profile"]
toml_file = tmp_path / "test.toml"
toml_file.write_text(toml_content)
settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg]
settings = Settings(_toml_file=str(toml_file))
app = create_app(settings)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
# Trigger lifespan
async with app.router.lifespan_context(app):
response = await client.get("/health")
assert response.status_code == 200
async with (
AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client,
app.router.lifespan_context(app),
):
response = await client.get("/health")
assert response.status_code == 200
oidc_server = app.state.oidc_server
assert "test-rp" in oidc_server.context.cdb
cdb_entry = oidc_server.context.cdb["test-rp"]
assert cdb_entry["client_id"] == "test-rp"
assert cdb_entry["client_secret"] == "test-secret-0123456789abcdef"
assert ("https://app.example.com/callback", {}) in cdb_entry["redirect_uris"]
assert cdb_entry["scope"] == ["openid", "profile"]
assert cdb_entry["allowed_scopes"] == ["openid", "profile"]
oidc_server = app.state.oidc_server
assert "test-rp" in oidc_server.context.cdb
cdb_entry = oidc_server.context.cdb["test-rp"]
assert cdb_entry["client_id"] == "test-rp"
assert cdb_entry["client_secret"] == "test-secret-0123456789abcdef"
assert ("https://app.example.com/callback", {}) in cdb_entry["redirect_uris"]
assert cdb_entry["scope"] == ["openid", "profile"]
assert cdb_entry["allowed_scopes"] == ["openid", "profile"]
async def test_manage_app_always_registered() -> None:
@ -43,10 +44,12 @@ async def test_manage_app_always_registered() -> None:
settings = Settings(issuer="https://test.example.com")
app = create_app(settings)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
async with app.router.lifespan_context(app):
response = await client.get("/health")
assert response.status_code == 200
async with (
AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client,
app.router.lifespan_context(app),
):
response = await client.get("/health")
assert response.status_code == 200
oidc_server = app.state.oidc_server
assert "manage-app" in oidc_server.context.cdb
oidc_server = app.state.oidc_server
assert "manage-app" in oidc_server.context.cdb

View file

@ -39,7 +39,7 @@ def test_settings_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OIDC_OP_ISSUER", "https://op.example.org")
monkeypatch.setenv("OIDC_OP_STORAGE_BACKEND", "mongodb")
monkeypatch.setenv("OIDC_OP_MONGODB_URI", "mongodb://remote:27017")
settings = Settings() # type: ignore[call-arg]
settings = Settings()
assert settings.issuer == "https://op.example.org"
assert settings.storage_backend == StorageBackend.MONGODB
@ -58,7 +58,7 @@ scope = ["openid", "profile"]
toml_file = tmp_path / "test.toml"
toml_file.write_text(toml_content)
settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg]
settings = Settings(_toml_file=str(toml_file))
assert settings.issuer == "https://toml.example.com"
assert settings.debug is True
assert settings.sqlite_path == "custom/path.db"
@ -80,13 +80,13 @@ debug = false
monkeypatch.setenv("OIDC_OP_ISSUER", "https://env.example.com")
monkeypatch.setenv("OIDC_OP_DEBUG", "true")
settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg]
settings = Settings(_toml_file=str(toml_file))
assert settings.issuer == "https://env.example.com"
assert settings.debug is True
def test_missing_toml_file_uses_defaults() -> None:
settings = Settings(issuer="http://localhost:8000", _toml_file="/nonexistent/path.toml") # type: ignore[call-arg]
settings = Settings(issuer="http://localhost:8000", _toml_file="/nonexistent/path.toml")
assert settings.issuer == "http://localhost:8000"
assert settings.clients == {}
@ -96,5 +96,5 @@ def test_config_file_env_var_override(tmp_path: Path, monkeypatch: pytest.Monkey
toml_file.write_text('issuer = "https://custom-path.example.com"\n')
monkeypatch.setenv("OIDC_OP_CONFIG_FILE", str(toml_file))
settings = Settings() # type: ignore[call-arg]
settings = Settings()
assert settings.issuer == "https://custom-path.example.com"