fix: add util module, w/ model_transaction_query()
just a basic implementation, will have to improve later
This commit is contained in:
parent
0e25cca0ba
commit
4db3fa5962
9 changed files with 281 additions and 13 deletions
|
|
@ -4,33 +4,45 @@ import socket
|
|||
|
||||
from unittest.mock import patch
|
||||
|
||||
from wuttjamaican.testing import DataTestCase
|
||||
from wuttjamaican.testing import ConfigTestCase, DataTestCase
|
||||
|
||||
from wutta_continuum import conf as mod
|
||||
|
||||
|
||||
class TestWuttaContinuumConfigExtension(DataTestCase):
|
||||
class TestWuttaContinuumConfigExtension(ConfigTestCase):
|
||||
|
||||
def make_extension(self):
|
||||
return mod.WuttaContinuumConfigExtension()
|
||||
|
||||
def test_startup(self):
|
||||
def test_startup_without_versioning(self):
|
||||
ext = self.make_extension()
|
||||
|
||||
with patch.object(mod, "make_versioned") as make_versioned:
|
||||
with patch.object(mod, "configure_mappers") as configure_mappers:
|
||||
|
||||
# nothing happens by default
|
||||
ext.startup(self.config)
|
||||
make_versioned.assert_not_called()
|
||||
configure_mappers.assert_not_called()
|
||||
|
||||
# but will if we enable it in config
|
||||
def test_startup_with_versioning(self):
|
||||
ext = self.make_extension()
|
||||
with patch.object(mod, "make_versioned") as make_versioned:
|
||||
with patch.object(mod, "configure_mappers") as configure_mappers:
|
||||
self.config.setdefault("wutta_continuum.enable_versioning", "true")
|
||||
ext.startup(self.config)
|
||||
make_versioned.assert_called_once()
|
||||
configure_mappers.assert_called_once_with()
|
||||
|
||||
def test_startup_with_error(self):
|
||||
ext = self.make_extension()
|
||||
with patch.object(mod, "make_versioned") as make_versioned:
|
||||
with patch.object(mod, "configure_mappers") as configure_mappers:
|
||||
self.config.setdefault("wutta_continuum.enable_versioning", "true")
|
||||
# nb. it is an error for the model to be loaded prior to
|
||||
# calling make_versioned() for sqlalchemy-continuum
|
||||
self.app.get_model()
|
||||
self.assertRaises(RuntimeError, ext.startup, self.config)
|
||||
make_versioned.assert_not_called()
|
||||
configure_mappers.assert_not_called()
|
||||
|
||||
|
||||
class TestWuttaContinuumPlugin(DataTestCase):
|
||||
|
||||
|
|
|
|||
40
tests/test_util.py
Normal file
40
tests/test_util.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
import sqlalchemy_continuum as continuum
|
||||
|
||||
from wutta_continuum import util as mod
|
||||
from wutta_continuum.testing import VersionTestCase
|
||||
|
||||
|
||||
class TestRenderOperationType(TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
self.assertEqual(
|
||||
mod.render_operation_type(continuum.Operation.INSERT), "INSERT"
|
||||
)
|
||||
self.assertEqual(
|
||||
mod.render_operation_type(continuum.Operation.UPDATE), "UPDATE"
|
||||
)
|
||||
self.assertEqual(
|
||||
mod.render_operation_type(continuum.Operation.DELETE), "DELETE"
|
||||
)
|
||||
|
||||
|
||||
class TestModelTransactionQuery(VersionTestCase):
|
||||
|
||||
def test_basic(self):
|
||||
model = self.app.model
|
||||
|
||||
user = model.User(username="fred")
|
||||
self.session.add(user)
|
||||
self.session.commit()
|
||||
|
||||
query = mod.model_transaction_query(user)
|
||||
self.assertEqual(query.count(), 1)
|
||||
txn = query.one()
|
||||
|
||||
UserVersion = continuum.version_class(model.User)
|
||||
version = self.session.query(UserVersion).one()
|
||||
self.assertIs(version.transaction, txn)
|
||||
Loading…
Add table
Add a link
Reference in a new issue