feat: add support for --runas CLI param, to set versioning authorship
only relevant if Wutta-Continuum is enabled
This commit is contained in:
parent
c6d1822f3b
commit
6ee008e169
8 changed files with 103 additions and 21 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import inspect
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, Mock
|
||||
|
||||
from wuttasync.cli import base as mod
|
||||
from wuttjamaican.testing import DataTestCase
|
||||
|
|
@ -44,12 +44,20 @@ class TestImportCommandHandler(DataTestCase):
|
|||
)
|
||||
|
||||
with patch.object(handler, "list_models") as list_models:
|
||||
handler.run({"list_models": True})
|
||||
list_models.assert_called_once_with({"list_models": True})
|
||||
ctx = Mock(params={"list_models": True})
|
||||
handler.run(ctx)
|
||||
list_models.assert_called_once_with(ctx.params)
|
||||
|
||||
class Object:
|
||||
def __init__(self, **kw):
|
||||
self.__dict__.update(kw)
|
||||
|
||||
with patch.object(handler, "import_handler") as import_handler:
|
||||
handler.run({"models": []})
|
||||
import_handler.process_data.assert_called_once_with()
|
||||
parent = Mock(params={"runas_username": "fred"})
|
||||
# TODO: why can't we just use Mock here? the parent attr is problematic
|
||||
ctx = Object(params={"models": []}, parent=parent)
|
||||
handler.run(ctx)
|
||||
import_handler.process_data.assert_called_once_with(runas_username="fred")
|
||||
|
||||
def test_list_models(self):
|
||||
handler = self.make_handler(
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@ class TestImportCsv(TestCase):
|
|||
ctx = MagicMock(params=params)
|
||||
with patch.object(ImportCommandHandler, "run") as run:
|
||||
mod.import_csv(ctx)
|
||||
run.assert_called_once_with(params)
|
||||
run.assert_called_once_with(ctx)
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@ class TestImportCsv(TestCase):
|
|||
ctx = MagicMock(params=params)
|
||||
with patch.object(ImportCommandHandler, "run") as run:
|
||||
mod.import_versions(ctx)
|
||||
run.assert_called_once_with(params)
|
||||
run.assert_called_once_with(ctx)
|
||||
|
|
|
|||
|
|
@ -190,6 +190,14 @@ class TestImportHandler(DataTestCase):
|
|||
self.assertNotIn("warnings_max_diffs", kw)
|
||||
self.assertEqual(handler.warnings_max_diffs, 30)
|
||||
|
||||
# runas_username (consumed)
|
||||
self.assertIsNone(handler.runas_username)
|
||||
kw["runas_username"] = "fred"
|
||||
result = handler.consume_kwargs(kw)
|
||||
self.assertIs(result, kw)
|
||||
self.assertNotIn("runas_username", kw)
|
||||
self.assertEqual(handler.runas_username, "fred")
|
||||
|
||||
def test_define_importers(self):
|
||||
handler = self.make_handler()
|
||||
importers = handler.define_importers()
|
||||
|
|
@ -490,11 +498,41 @@ class TestToWuttaHandler(DataTestCase):
|
|||
self.assertEqual(handler.get_target_title(), "what_about_this")
|
||||
|
||||
def test_make_target_session(self):
|
||||
model = self.app.model
|
||||
handler = self.make_handler()
|
||||
|
||||
# makes "new" (mocked in our case) app session
|
||||
fred = model.User(username="fred")
|
||||
self.session.add(fred)
|
||||
self.session.commit()
|
||||
|
||||
# makes "new" (mocked in our case) app session, with no runas
|
||||
# username set by default
|
||||
with patch.object(self.app, "make_session") as make_session:
|
||||
make_session.return_value = self.session
|
||||
session = handler.make_target_session()
|
||||
make_session.assert_called_once_with()
|
||||
self.assertIs(session, self.session)
|
||||
self.assertNotIn("continuum_user_id", session.info)
|
||||
self.assertNotIn("continuum_user_id", self.session.info)
|
||||
|
||||
# runas user also should not be set, if username is not valid
|
||||
handler.runas_username = "freddie"
|
||||
with patch.object(self.app, "make_session") as make_session:
|
||||
make_session.return_value = self.session
|
||||
session = handler.make_target_session()
|
||||
make_session.assert_called_once_with()
|
||||
self.assertIs(session, self.session)
|
||||
self.assertNotIn("continuum_user_id", session.info)
|
||||
self.assertNotIn("continuum_user_id", self.session.info)
|
||||
|
||||
# this time we should have runas user properly set
|
||||
handler.runas_username = "fred"
|
||||
with patch.object(self.app, "make_session") as make_session:
|
||||
make_session.return_value = self.session
|
||||
session = handler.make_target_session()
|
||||
make_session.assert_called_once_with()
|
||||
self.assertIs(session, self.session)
|
||||
self.assertIn("continuum_user_id", session.info)
|
||||
self.assertEqual(session.info["continuum_user_id"], fred.uuid)
|
||||
self.assertIn("continuum_user_id", self.session.info)
|
||||
self.assertEqual(self.session.info["continuum_user_id"], fred.uuid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue