add project structure
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.db import configure_database
|
||||
from app.main import create_app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path: Path):
|
||||
test_db_path = tmp_path / "test.db"
|
||||
database_url = f"sqlite:///{test_db_path}"
|
||||
|
||||
configure_database(database_url)
|
||||
app = create_app()
|
||||
|
||||
with TestClient(app) as test_client:
|
||||
yield test_client
|
||||
@@ -0,0 +1,31 @@
|
||||
from pathlib import Path
|
||||
|
||||
import app.db as db
|
||||
|
||||
|
||||
def test_app_starts(client):
|
||||
response = client.get("/boxes")
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_root_redirects_to_boxes(client):
|
||||
response = client.get("/", follow_redirects=False)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.headers["location"] == "/boxes"
|
||||
|
||||
|
||||
def test_boxes_page_returns_200(client):
|
||||
response = client.get("/boxes")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "Boxes page" in response.text
|
||||
|
||||
|
||||
def test_tests_use_isolated_sqlite_database(client):
|
||||
assert db.engine is not None
|
||||
|
||||
database_name = Path(db.engine.url.database)
|
||||
assert database_name.name == "test.db"
|
||||
assert "data/app.db" not in str(database_name)
|
||||
Reference in New Issue
Block a user