Skip to content

Commit

Permalink
chore: add warning mypy takes a while, fix ruff, types
Browse files Browse the repository at this point in the history
  • Loading branch information
tiptenbrink committed Dec 21, 2023
1 parent df32be0 commit 45859a4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/src/apiserver/app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def dep_auth_context(request: Request) -> AuthContexts:

async def dep_header_token(
authorization: Authorization, dsrc: SourceDep, app_ctx: AppContext
) -> AccessToken:
) -> AccessToken:
try:
return await ctxlize(verify_token_header)(
app_ctx.authrz_ctx, authorization, dsrc
Expand Down
10 changes: 7 additions & 3 deletions backend/src/apiserver/app/ops/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@


class AuthBearerHeader(SecurityBase):
"""This allows using the OpenAPI docs (/docs) and enter the access token. Note that it already prepends 'Bearer'
"""This allows using the OpenAPI docs (/docs) and enter the access token. Note that it already prepends 'Bearer'
to the value, so that's not necessary to add when using the docs."""

scheme: Literal["bearer"] = "bearer"

def __init__(self):
self.model = HTTPBaseModel(scheme="bearer", description="Provide the access token like 'Bearer <encoded token>'.")
def __init__(self) -> None:
self.model = HTTPBaseModel(
scheme="bearer",
description="Provide the access token like 'Bearer <encoded token>'.",
)
self.scheme_name = "Bearer authorization scheme."

async def __call__(self, request: Request) -> str:
Expand Down
7 changes: 5 additions & 2 deletions backend/src/apiserver/app_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ async def validation_exception_handler(
def define_static_routes() -> list[Mount]:
static_credential_path = res_path.joinpath("static/credentials")
if not static_credential_path.exists():
raise AppEnvironmentError(f"Could not find the static HTML files at {static_credential_path}. Did you build " +
"the files for the authpage?")
raise AppEnvironmentError(
f"Could not find the static HTML files at {static_credential_path}. Did you"
" build "
+ "the files for the authpage?"
)

credential_mount = Mount(
"/credentials",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/apiserver/lib/resource/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def extract_token_and_kid(authorization: str) -> tuple[str, str]:
err_type="invalid_request",
err_desc="Authorization must follow 'Bearer' scheme",
)

token = authorization.removeprefix("Bearer ")

try:
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/query_test/data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def event_loop_policy():
return uvloop.EventLoopPolicy()



@pytest.fixture(scope="module")
def api_config() -> Fixture[Config]:
test_config_path = res_path.joinpath("querytestenv.toml")
Expand Down Expand Up @@ -84,6 +83,7 @@ async def new_db_store(api_config: Config, admin_engine: Engine):
drop_db = text(f"DROP DATABASE {db_name};")
conn.execute(drop_db)


@pytest.mark.asyncio
async def test_create_class(new_db_store: Store):
async with get_conn(new_db_store) as conn:
Expand Down
4 changes: 3 additions & 1 deletion backend/tests/query_test/store_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import os
from random import randint
from typing import LiteralString
Expand All @@ -23,15 +22,18 @@
"Skipping store_test as QUERY_TEST is not set.", allow_module_level=True
)


@pytest.fixture(scope="module")
def event_loop_policy():
return uvloop.EventLoopPolicy()


@pytest.fixture(scope="module")
def api_config() -> Fixture[Config]:
test_config_path = res_path.joinpath("querytestenv.toml")
yield load_config(test_config_path)


@pytest_asyncio.fixture(scope="module")
async def local_store(api_config: Config):
# each module makes its own database
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/utilities_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import pytest
from pytest_mock import MockerFixture

import apiserver.lib.utilities as util
import auth.core.util

Expand All @@ -13,8 +10,11 @@
# secrets_patch.side_effect = lambda b: bytes.fromhex("8ca96077b3191e3c")


HASH_LENGTH = 32


def test_hash_hex():
assert len(auth.core.util.random_time_hash_hex()) == 32
assert len(auth.core.util.random_time_hash_hex()) == HASH_LENGTH


def test_usp_hex():
Expand Down
1 change: 1 addition & 0 deletions test.nu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def check_backend [] {
cd $backend_dir
poetry run black src tests
poetry run ruff src tests
print "Running mypy, this could take a while..."
poetry run mypy
}

Expand Down

0 comments on commit 45859a4

Please sign in to comment.