Fix validation issues and test setup
This commit is contained in:
21
test_main.py
21
test_main.py
@@ -1,16 +1,27 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app, init_db
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def setup_module(module):
|
||||
# Use an in-memory database for tests
|
||||
os.environ["DB_PATH"] = ":memory:"
|
||||
fd, path = tempfile.mkstemp(suffix=".db")
|
||||
os.close(fd)
|
||||
module.TEST_DB_PATH = path
|
||||
os.environ["DB_PATH"] = path
|
||||
init_db()
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
path = getattr(module, "TEST_DB_PATH", None)
|
||||
if path and os.path.exists(path):
|
||||
os.remove(path)
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_root():
|
||||
r = client.get("/")
|
||||
assert r.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user