feat: add concept of (non-)default importers for handler
i.e. when telling handler to "import all" which should be included vs. excluded by default?
This commit is contained in:
parent
ae282ab468
commit
d7d0768a9c
7 changed files with 148 additions and 15 deletions
|
|
@ -3,7 +3,7 @@
|
|||
import inspect
|
||||
import sys
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch, Mock
|
||||
from unittest.mock import patch, Mock, call
|
||||
|
||||
from wuttasync.cli import base as mod
|
||||
from wuttjamaican.testing import DataTestCase
|
||||
|
|
@ -169,22 +169,60 @@ class TestImportCommandHandler(DataTestCase):
|
|||
params={},
|
||||
),
|
||||
)
|
||||
# self.assertRaises(FileNotFoundError, handler.run, ctx)
|
||||
handler.run(ctx)
|
||||
exit_.assert_not_called()
|
||||
|
||||
def test_list_models(self):
|
||||
|
||||
# CSV -> Wutta (all importers are default)
|
||||
handler = self.make_handler(
|
||||
import_handler="wuttasync.importing.csv:FromCsvToWutta"
|
||||
)
|
||||
|
||||
with patch.object(mod, "sys") as sys:
|
||||
handler.list_models({})
|
||||
# just test a few random things we expect to see
|
||||
self.assertTrue(sys.stdout.write.has_call("ALL MODELS:\n"))
|
||||
self.assertTrue(sys.stdout.write.has_call("Person"))
|
||||
self.assertTrue(sys.stdout.write.has_call("User"))
|
||||
self.assertTrue(sys.stdout.write.has_call("Upgrade"))
|
||||
sys.stdout.write.assert_has_calls(
|
||||
[
|
||||
call("==============================\n"),
|
||||
call(" EXTRA MODELS:\n"),
|
||||
call("==============================\n"),
|
||||
call("(none)\n"),
|
||||
call("==============================\n"),
|
||||
]
|
||||
)
|
||||
|
||||
# Wutta -> Wutta (only Person importer is default)
|
||||
handler = self.make_handler(
|
||||
import_handler="wuttasync.importing.wutta:FromWuttaToWuttaImport"
|
||||
)
|
||||
with patch.object(mod, "sys") as sys:
|
||||
handler.list_models({})
|
||||
sys.stdout.write.assert_has_calls(
|
||||
[
|
||||
call("==============================\n"),
|
||||
call(" DEFAULT MODELS:\n"),
|
||||
call("==============================\n"),
|
||||
call("Person\n"),
|
||||
call("==============================\n"),
|
||||
call(" EXTRA MODELS:\n"),
|
||||
call("==============================\n"),
|
||||
]
|
||||
)
|
||||
|
||||
# again, but pretend there are no default importers
|
||||
with patch.object(handler.import_handler, "is_default", return_value=False):
|
||||
with patch.object(mod, "sys") as sys:
|
||||
handler.list_models({})
|
||||
sys.stdout.write.assert_has_calls(
|
||||
[
|
||||
call("==============================\n"),
|
||||
call(" DEFAULT MODELS:\n"),
|
||||
call("==============================\n"),
|
||||
call("(none)\n"),
|
||||
call("==============================\n"),
|
||||
call(" EXTRA MODELS:\n"),
|
||||
call("==============================\n"),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class TestImporterCommand(TestCase):
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from uuid import UUID
|
|||
from wuttjamaican.testing import DataTestCase
|
||||
|
||||
from wuttasync.importing import handlers as mod, Importer, ToSqlalchemy
|
||||
from wuttasync.importing.wutta import FromWuttaToWuttaImport
|
||||
|
||||
|
||||
class FromFooToBar(mod.ImportHandler):
|
||||
|
|
@ -253,6 +254,25 @@ class TestImportHandler(DataTestCase):
|
|||
KeyError, handler.get_importer, "BunchOfNonsense", model_class=model.Setting
|
||||
)
|
||||
|
||||
def test_is_default(self):
|
||||
handler = self.make_handler()
|
||||
# nb. anything is considered default, by default
|
||||
self.assertTrue(handler.is_default("there_is_no_way_this_is_valid"))
|
||||
|
||||
def test_get_default_importer_keys(self):
|
||||
|
||||
# use handler which already has some non/default keys
|
||||
handler = FromWuttaToWuttaImport(self.config)
|
||||
|
||||
# it supports many importers
|
||||
self.assertIn("Person", handler.importers)
|
||||
self.assertIn("User", handler.importers)
|
||||
self.assertIn("Setting", handler.importers)
|
||||
|
||||
# but only Person is default
|
||||
keys = handler.get_default_importer_keys()
|
||||
self.assertEqual(keys, ["Person"])
|
||||
|
||||
def test_get_warnings_email_key(self):
|
||||
handler = FromFooToBar(self.config)
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,9 @@ class TestEmailSettings(ImportExportWarningTestCase):
|
|||
|
||||
return config
|
||||
|
||||
def test_export_to_wutta_from_wutta_warning(self):
|
||||
self.do_test_preview("export_to_wutta_from_wutta_warning")
|
||||
|
||||
def test_import_to_versions_from_wutta_warning(self):
|
||||
self.do_test_preview("import_to_versions_from_wutta_warning")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue