apitest: include storage (postgres DB, tracking) setup
This commit is contained in:
parent
37d7a31650
commit
635b18bd08
1 changed files with 25 additions and 2 deletions
|
|
@ -2,8 +2,20 @@
|
||||||
|
|
||||||
"""Tests for the fastapi- (and asyncio-) based stuff."""
|
"""Tests for the fastapi- (and asyncio-) based stuff."""
|
||||||
|
|
||||||
import sys
|
import os, sys
|
||||||
print('***', sys.path)
|
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
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
@ -11,6 +23,16 @@ from httpx2 import ASGITransport, AsyncClient
|
||||||
|
|
||||||
from scopes.api.main import app
|
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():
|
def async_client():
|
||||||
return AsyncClient(transport=ASGITransport(app=app), base_url='http://test')
|
return AsyncClient(transport=ASGITransport(app=app), base_url='http://test')
|
||||||
|
|
||||||
|
|
@ -20,6 +42,7 @@ def async_client():
|
||||||
#response = await clt.get('/')
|
#response = await clt.get('/')
|
||||||
|
|
||||||
def test_root():
|
def test_root():
|
||||||
|
storage = setup()
|
||||||
with TestClient(app) as clt:
|
with TestClient(app) as clt:
|
||||||
response = clt.get('/')
|
response = clt.get('/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue