From d8546b4a92cf386b2be4513034a4d3b166ba30e1 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 28 Oct 2026 23:13:27 +0100 Subject: [PATCH] storage testing, work in progress: use pytest, with postgres only --- scopes/org/task.py | 1 - scopes/tests/config.py | 10 ++--- scopes/tests/test_postgres.py | 8 +++- .../{test_standard.py => xx_test_standard.py} | 0 tests/test_storage.py | 40 +++++++++++++++++++ 5 files changed, 52 insertions(+), 7 deletions(-) rename scopes/tests/{test_standard.py => xx_test_standard.py} (100%) create mode 100644 tests/test_storage.py diff --git a/scopes/org/task.py b/scopes/org/task.py index 1e02ac1..da17940 100644 --- a/scopes/org/task.py +++ b/scopes/org/task.py @@ -8,6 +8,5 @@ from scopes.storage.concept import Concept class Task(Concept): - headFields = ['name'] prefix = 'tsk' diff --git a/scopes/tests/config.py b/scopes/tests/config.py index ff4f320..44c3180 100644 --- a/scopes/tests/config.py +++ b/scopes/tests/config.py @@ -14,11 +14,11 @@ class Settings(BaseSettings): log_dateformat: str = '%Y-%m-%dT%H:%M:%S' - dbengine: str = 'sqlite' - dbname: str = 'var/test.db' - dbuser: str | None = None - dbpassword: str | None = None - dbschema: str | None = None + dbengine: str = 'postgresql+psycopg' + dbname: str = 'testdb' + dbuser: str = 'testuser' + dbpassword: str = 'secret' + dbschema: str = 'testing' settings = Settings() diff --git a/scopes/tests/test_postgres.py b/scopes/tests/test_postgres.py index 59fd47c..5179f9e 100644 --- a/scopes/tests/test_postgres.py +++ b/scopes/tests/test_postgres.py @@ -6,7 +6,7 @@ import os, sys sys.path = [os.path.dirname(__file__)] + sys.path import unittest -from scopes.tests import tlib_storage +from scopes.tests import tlib_storage, tlib_web from scopes.tests.util import setup_logging from scopes.storage.db.postgres import StorageFactory @@ -38,6 +38,12 @@ class Test(unittest.TestCase): def test_005_message(self): tlib_storage.test_message(self, config) + def test_013_web(self): + tlib_web.test_app(self, config) + tlib_web.test_auth(self, config) + tlib_web.test_user_data(self, config) + + def test_suite(): return unittest.TestSuite(( unittest.TestLoader().loadTestsFromTestCase(Test), diff --git a/scopes/tests/test_standard.py b/scopes/tests/xx_test_standard.py similarity index 100% rename from scopes/tests/test_standard.py rename to scopes/tests/xx_test_standard.py diff --git a/tests/test_storage.py b/tests/test_storage.py new file mode 100644 index 0000000..3dc64f7 --- /dev/null +++ b/tests/test_storage.py @@ -0,0 +1,40 @@ +# py-scopes: tests.test_storage + +""" Tests for the (PostgreSQL) storage-related functionalities""" + +from scopes import testing +import config + +from datetime import datetime +import pytest + +from scopes.api import main +from scopes.storage import concept, folder, message, topic, tracking +from scopes.util import keywords as k + +# predefined keywords used as domain, action, class head values in messages +k('session system') + +@pytest.fixture(scope='module') +def storage(): + #storage = config.StorageFactory(config)(config.dbschema) + storage = main.storage() + storage.dropTable('tracks') + storage.dropTable('folders') + storage.dropTable('types') + storage.dropTable('preds') + storage.dropTable('rels') + storage.dropTable('topics') + storage.dropTable('messages') + storage.commit() + return storage + +def test_tracking(storage, caplog): + tracks = storage.create(tracking.Container) + tr01 = tracking.Track('t01', 'john') + tr01.update(dict(activity='testing')) + assert tr01.head == {'taskId': 't01', 'userName': 'john'} + trid01 = tracks.save(tr01) + assert trid01 == 1 + storage.commit() +