move real testing code to separate 'tlib' module
This commit is contained in:
parent
dba278fc02
commit
4066720486
4 changed files with 78 additions and 62 deletions
|
@ -12,13 +12,13 @@ keywords = ["scopes"]
|
||||||
authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}]
|
authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}]
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"SQLAlchemy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
postgres = [
|
postgres = [
|
||||||
"transaction",
|
|
||||||
"psycopg[binary]",
|
"psycopg[binary]",
|
||||||
"SQLAlchemy",
|
"transaction",
|
||||||
"zope.sqlalchemy",
|
"zope.sqlalchemy",
|
||||||
]
|
]
|
||||||
app = ["python-dotenv", "zope.publisher", "zope.traversing"]
|
app = ["python-dotenv", "zope.publisher", "zope.traversing"]
|
||||||
|
|
|
@ -22,6 +22,7 @@ def getEngine(dbtype, dbname, user, pw, host='localhost', port=5432, **kw):
|
||||||
def commit(conn):
|
def commit(conn):
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
|
|
||||||
|
# patch `common` module
|
||||||
import scopes.storage.common
|
import scopes.storage.common
|
||||||
scopes.storage.common.IdType = BigInteger
|
scopes.storage.common.IdType = BigInteger
|
||||||
scopes.storage.common.JsonType = JSONB
|
scopes.storage.common.JsonType = JSONB
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
import config
|
import config
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import transaction
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import scopes.storage.common
|
import scopes.storage.common
|
||||||
|
@ -19,72 +18,16 @@ scopes.storage.common.Session = sessionFactory(engine)
|
||||||
|
|
||||||
storage = Storage(schema=config.dbschema)
|
storage = Storage(schema=config.dbschema)
|
||||||
|
|
||||||
|
import tlib
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
"Basic tests for the cco.storage package."
|
"Basic tests for the cco.storage package."
|
||||||
|
|
||||||
def test_001_tracking(self):
|
def test_001_tracking(self):
|
||||||
storage.dropTable('tracks')
|
tlib.test_tracking(self, storage)
|
||||||
tracks = storage.create(tracking.Container)
|
|
||||||
|
|
||||||
tr01 = tracking.Track('t01', 'john')
|
|
||||||
tr01.update(dict(activity='testing'))
|
|
||||||
self.assertEqual(tr01.head, {'taskId': 't01', 'userName': 'john'})
|
|
||||||
self.assertEqual(tr01.taskId, 't01')
|
|
||||||
self.assertEqual(tr01.userName, 'john')
|
|
||||||
|
|
||||||
self.assertTrue(tracks.getTable() is not None)
|
|
||||||
|
|
||||||
trid01 = tracks.save(tr01)
|
|
||||||
self.assertTrue(trid01 > 0)
|
|
||||||
|
|
||||||
tr01a = tracks.get(trid01)
|
|
||||||
self.assertEqual(tr01a.head, tr01.head)
|
|
||||||
self.assertEqual(tr01a.trackId, trid01)
|
|
||||||
self.assertEqual(tr01a.data.get('activity'), 'testing')
|
|
||||||
|
|
||||||
tr01a.update(dict(text='Set up unit tests.'))
|
|
||||||
tr01a.timeStamp = None
|
|
||||||
self.assertTrue(tracks.save(tr01a) > 0)
|
|
||||||
|
|
||||||
tr01b = tracks.queryLast(taskId='t01')
|
|
||||||
self.assertEqual(tr01b.head, tr01.head)
|
|
||||||
self.assertNotEqual(tr01b.trackId, trid01)
|
|
||||||
self.assertEqual(tr01b.data.get('activity'), 'testing')
|
|
||||||
|
|
||||||
tr02 = tracking.Track('t02', 'jim', trackId=31, timeStamp=datetime(2023, 11, 30),
|
|
||||||
data=dict(activity='concept'))
|
|
||||||
trid02 = tracks.upsert(tr02)
|
|
||||||
self.assertEqual(trid02, 31)
|
|
||||||
self.assertEqual(tr02.uid, 'rec-31')
|
|
||||||
tr02.trackId = trid01
|
|
||||||
trid021 = tracks.upsert(tr02)
|
|
||||||
self.assertEqual(trid021, trid01)
|
|
||||||
self.assertEqual(tr02.uid, 'rec-' + str(trid01))
|
|
||||||
|
|
||||||
tr03 = storage.getItem('rec-31')
|
|
||||||
self.assertEqual(tr03.trackId, 31)
|
|
||||||
|
|
||||||
n = tracks.remove(31)
|
|
||||||
self.assertEqual(n, 1)
|
|
||||||
self.assertEqual(tracks.get(31), None)
|
|
||||||
|
|
||||||
commit(storage.session)
|
|
||||||
|
|
||||||
def test_002_folder(self):
|
def test_002_folder(self):
|
||||||
storage.dropTable('folders')
|
tlib.test_folder(self, storage)
|
||||||
root = folder.Root(storage)
|
|
||||||
self.assertEqual(list(root.keys()), [])
|
|
||||||
root['top'] = folder.Folder()
|
|
||||||
self.assertEqual(list(root.keys()), ['top'])
|
|
||||||
top = root['top']
|
|
||||||
top['child1'] = folder.Folder(data=dict(title='First Child'))
|
|
||||||
self.assertEqual(list(top.keys()), ['child1'])
|
|
||||||
ch1 = top['child1']
|
|
||||||
self.assertEqual(ch1.parent, top.rid)
|
|
||||||
assert list(top.keys()) == ['child1']
|
|
||||||
|
|
||||||
commit(storage.session)
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
return unittest.TestSuite((
|
return unittest.TestSuite((
|
||||||
|
|
72
tests/tlib.py
Normal file
72
tests/tlib.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
"""The real test implementations"""
|
||||||
|
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from scopes.storage import folder, tracking
|
||||||
|
from scopes.storage.common import commit
|
||||||
|
|
||||||
|
|
||||||
|
def test_tracking(self, storage):
|
||||||
|
storage.dropTable('tracks')
|
||||||
|
tracks = storage.create(tracking.Container)
|
||||||
|
|
||||||
|
tr01 = tracking.Track('t01', 'john')
|
||||||
|
tr01.update(dict(activity='testing'))
|
||||||
|
self.assertEqual(tr01.head, {'taskId': 't01', 'userName': 'john'})
|
||||||
|
self.assertEqual(tr01.taskId, 't01')
|
||||||
|
self.assertEqual(tr01.userName, 'john')
|
||||||
|
|
||||||
|
self.assertTrue(tracks.getTable() is not None)
|
||||||
|
|
||||||
|
trid01 = tracks.save(tr01)
|
||||||
|
self.assertTrue(trid01 > 0)
|
||||||
|
|
||||||
|
tr01a = tracks.get(trid01)
|
||||||
|
self.assertEqual(tr01a.head, tr01.head)
|
||||||
|
self.assertEqual(tr01a.trackId, trid01)
|
||||||
|
self.assertEqual(tr01a.data.get('activity'), 'testing')
|
||||||
|
|
||||||
|
tr01a.update(dict(text='Set up unit tests.'))
|
||||||
|
tr01a.timeStamp = None
|
||||||
|
self.assertTrue(tracks.save(tr01a) > 0)
|
||||||
|
|
||||||
|
tr01b = tracks.queryLast(taskId='t01')
|
||||||
|
self.assertEqual(tr01b.head, tr01.head)
|
||||||
|
self.assertNotEqual(tr01b.trackId, trid01)
|
||||||
|
self.assertEqual(tr01b.data.get('activity'), 'testing')
|
||||||
|
|
||||||
|
tr02 = tracking.Track('t02', 'jim', trackId=31, timeStamp=datetime(2023, 11, 30),
|
||||||
|
data=dict(activity='concept'))
|
||||||
|
trid02 = tracks.upsert(tr02)
|
||||||
|
self.assertEqual(trid02, 31)
|
||||||
|
self.assertEqual(tr02.uid, 'rec-31')
|
||||||
|
tr02.trackId = trid01
|
||||||
|
trid021 = tracks.upsert(tr02)
|
||||||
|
self.assertEqual(trid021, trid01)
|
||||||
|
self.assertEqual(tr02.uid, 'rec-' + str(trid01))
|
||||||
|
|
||||||
|
tr03 = storage.getItem('rec-31')
|
||||||
|
self.assertEqual(tr03.trackId, 31)
|
||||||
|
|
||||||
|
n = tracks.remove(31)
|
||||||
|
self.assertEqual(n, 1)
|
||||||
|
self.assertEqual(tracks.get(31), None)
|
||||||
|
|
||||||
|
commit(storage.session)
|
||||||
|
|
||||||
|
|
||||||
|
def test_folder(self, storage):
|
||||||
|
storage.dropTable('folders')
|
||||||
|
root = folder.Root(storage)
|
||||||
|
self.assertEqual(list(root.keys()), [])
|
||||||
|
root['top'] = folder.Folder()
|
||||||
|
self.assertEqual(list(root.keys()), ['top'])
|
||||||
|
top = root['top']
|
||||||
|
top['child1'] = folder.Folder(data=dict(title='First Child'))
|
||||||
|
self.assertEqual(list(top.keys()), ['child1'])
|
||||||
|
ch1 = top['child1']
|
||||||
|
self.assertEqual(ch1.parent, top.rid)
|
||||||
|
self.assertEqual(list(top.keys()), ['child1'])
|
||||||
|
|
||||||
|
commit(storage.session)
|
||||||
|
|
Loading…
Add table
Reference in a new issue