apitest: include storage (postgres DB, tracking) setup

This commit is contained in:
Helmut Merz 2026-09-16 18:54:25 +02:00
parent 37d7a31650
commit 635b18bd08

View file

@ -2,8 +2,20 @@
"""Tests for the fastapi- (and asyncio-) based stuff."""
import sys
print('***', sys.path)
import os, sys
sys.path = [os.path.dirname(__file__)] + sys.path
import config
from scopes.storage.db.postgres import StorageFactory
from scopes.storage import concept, folder, message, topic, tracking
import transaction
config.dbengine = 'postgresql+psycopg'
config.dbname = 'testdb'
config.dbuser = 'testuser'
config.dbpassword = 'secret'
config.dbschema = 'testing'
config.storageFactory = StorageFactory(config)
import pytest
from fastapi.testclient import TestClient
@ -11,6 +23,16 @@ from httpx2 import ASGITransport, AsyncClient
from scopes.api.main import app
def setup():
storage = config.storageFactory(config.dbschema)
storage.dropTable('tracks')
tracks = storage.create(tracking.Container)
tr01 = tracking.Track('t01', 'john')
tr01.update(dict(activity='testing'))
trid01 = tracks.save(tr01)
transaction.commit()
return storage
def async_client():
return AsyncClient(transport=ASGITransport(app=app), base_url='http://test')
@ -20,6 +42,7 @@ def async_client():
#response = await clt.get('/')
def test_root():
storage = setup()
with TestClient(app) as clt:
response = clt.get('/')
assert response.status_code == 200