Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed Jun 18, 2024
1 parent 1792680 commit e062d75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions tad/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from fastapi.templating import Jinja2Templates
from jinja2 import Environment

from tad.core.config import get_settings
from tad.core.config import VERSION


def version_context_processor(request: Request):
return {"version": get_settings().VERSION}
return {"version": VERSION}


env = Environment(
autoescape=True,
)
templates = Jinja2Templates(directory="tad/site/templates/",context_processors=[version_context_processor], env=env)
templates = Jinja2Templates(directory="tad/site/templates/", context_processors=[version_context_processor], env=env)
13 changes: 7 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
from tests.database_test_utils import DatabaseTestUtils


def run_uvicorn(uvicorn: Any) -> None:
uvicorn_run(app, host=uvicorn["host"], port=uvicorn["port"])


@pytest.fixture(scope="module")
def run_server(request: pytest.FixtureRequest) -> Generator[Any, None, None]:
def run_uvicorn(uvicorn: Any) -> None:
uvicorn_run(app, host=uvicorn["host"], port=uvicorn["port"])

uvicorn_settings = request.config.uvicorn # type: ignore

process = Process(target=run_uvicorn, args=(uvicorn_settings,)) # type: ignore
Expand All @@ -42,7 +43,7 @@ def pytest_configure(config: pytest.Config) -> None:
os.environ["APP_DATABASE_SCHEME"] = "sqlite"

config.uvicorn = { # type: ignore
"host": "localhost",
"host": "127.0.0.1",
"port": 8756,
}

Expand Down Expand Up @@ -79,9 +80,9 @@ def browser(
context = browser.new_context(base_url=run_server)
page = context.new_page()

transport = httpx.HTTPTransport(retries=5)
transport = httpx.HTTPTransport(retries=5, local_address="127.0.0.1")
with httpx.Client(transport=transport, verify=False) as client: # noqa: S501
client.get(f"{run_server}/", timeout=0.3)
client.get(f"{run_server}/", timeout=0.8)

yield page
browser.close()
Expand Down
5 changes: 2 additions & 3 deletions tests/database_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ def __init__(self, session: Session) -> None:
self.models: list[BaseModel] = []

def __del__(self):
for model in self.models:
self.session.delete(model)
self.session.commit()
SQLModel.metadata.drop_all(get_engine())
SQLModel.metadata.create_all(get_engine())

def given(self, models: list[BaseModel]) -> None:
self.models.extend(models)
Expand Down

0 comments on commit e062d75

Please sign in to comment.