refactor: fix lint warnings and remove stale type: ignore comments
This commit is contained in:
parent
8c91edf137
commit
64f8c1936b
5 changed files with 34 additions and 28 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -11,3 +11,6 @@ wheels/
|
||||||
|
|
||||||
# Git worktrees
|
# Git worktrees
|
||||||
.worktrees/
|
.worktrees/
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
data/
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||||
|
|
||||||
def create_app(settings: Settings | None = None) -> FastAPI:
|
def create_app(settings: Settings | None = None) -> FastAPI:
|
||||||
if settings is None:
|
if settings is None:
|
||||||
settings = Settings() # type: ignore[call-arg]
|
settings = Settings()
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="Porchlight",
|
title="Porchlight",
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ def create_invite(
|
||||||
note: Annotated[str | None, typer.Option(help="Optional note stored with the link")] = None,
|
note: Annotated[str | None, typer.Option(help="Optional note stored with the link")] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Generate a magic link registration URL for a new user."""
|
"""Generate a magic link registration URL for a new user."""
|
||||||
settings = Settings() # type: ignore[call-arg]
|
settings = Settings()
|
||||||
effective_ttl = ttl if ttl is not None else settings.invite_ttl
|
effective_ttl = ttl if ttl is not None else settings.invite_ttl
|
||||||
url = asyncio.run(_create_invite(settings, username, effective_ttl, note))
|
url = asyncio.run(_create_invite(settings, username, effective_ttl, note))
|
||||||
typer.echo(url)
|
typer.echo(url)
|
||||||
|
|
@ -64,7 +64,7 @@ def initial_admin(
|
||||||
group: Annotated[list[str] | None, typer.Option(help="Groups to assign (repeatable)")] = None,
|
group: Annotated[list[str] | None, typer.Option(help="Groups to assign (repeatable)")] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Bootstrap the first admin user with a registration link."""
|
"""Bootstrap the first admin user with a registration link."""
|
||||||
settings = Settings() # type: ignore[call-arg]
|
settings = Settings()
|
||||||
groups = group if group is not None else ["admin", "users"]
|
groups = group if group is not None else ["admin", "users"]
|
||||||
url = asyncio.run(_initial_admin(settings, username, groups))
|
url = asyncio.run(_initial_admin(settings, username, groups))
|
||||||
typer.echo(url)
|
typer.echo(url)
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,13 @@ scope = ["openid", "profile"]
|
||||||
toml_file = tmp_path / "test.toml"
|
toml_file = tmp_path / "test.toml"
|
||||||
toml_file.write_text(toml_content)
|
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)
|
app = create_app(settings)
|
||||||
|
|
||||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
async with (
|
||||||
# Trigger lifespan
|
AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client,
|
||||||
async with app.router.lifespan_context(app):
|
app.router.lifespan_context(app),
|
||||||
|
):
|
||||||
response = await client.get("/health")
|
response = await client.get("/health")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
@ -43,8 +44,10 @@ async def test_manage_app_always_registered() -> None:
|
||||||
settings = Settings(issuer="https://test.example.com")
|
settings = Settings(issuer="https://test.example.com")
|
||||||
app = create_app(settings)
|
app = create_app(settings)
|
||||||
|
|
||||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
async with (
|
||||||
async with app.router.lifespan_context(app):
|
AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client,
|
||||||
|
app.router.lifespan_context(app),
|
||||||
|
):
|
||||||
response = await client.get("/health")
|
response = await client.get("/health")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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_ISSUER", "https://op.example.org")
|
||||||
monkeypatch.setenv("OIDC_OP_STORAGE_BACKEND", "mongodb")
|
monkeypatch.setenv("OIDC_OP_STORAGE_BACKEND", "mongodb")
|
||||||
monkeypatch.setenv("OIDC_OP_MONGODB_URI", "mongodb://remote:27017")
|
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.issuer == "https://op.example.org"
|
||||||
assert settings.storage_backend == StorageBackend.MONGODB
|
assert settings.storage_backend == StorageBackend.MONGODB
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ scope = ["openid", "profile"]
|
||||||
toml_file = tmp_path / "test.toml"
|
toml_file = tmp_path / "test.toml"
|
||||||
toml_file.write_text(toml_content)
|
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.issuer == "https://toml.example.com"
|
||||||
assert settings.debug is True
|
assert settings.debug is True
|
||||||
assert settings.sqlite_path == "custom/path.db"
|
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_ISSUER", "https://env.example.com")
|
||||||
monkeypatch.setenv("OIDC_OP_DEBUG", "true")
|
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.issuer == "https://env.example.com"
|
||||||
assert settings.debug is True
|
assert settings.debug is True
|
||||||
|
|
||||||
|
|
||||||
def test_missing_toml_file_uses_defaults() -> None:
|
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.issuer == "http://localhost:8000"
|
||||||
assert settings.clients == {}
|
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')
|
toml_file.write_text('issuer = "https://custom-path.example.com"\n')
|
||||||
|
|
||||||
monkeypatch.setenv("OIDC_OP_CONFIG_FILE", str(toml_file))
|
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"
|
assert settings.issuer == "https://custom-path.example.com"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue