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:
Lance Edgar 2026-03-17 18:24:42 -05:00
parent ae282ab468
commit d7d0768a9c
7 changed files with 148 additions and 15 deletions

View file

@ -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):