feat: add support for wutta export-csv command

This commit is contained in:
Lance Edgar 2026-01-03 15:41:47 -06:00
parent c873cc462e
commit 61deaad251
21 changed files with 1186 additions and 16 deletions

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8; -*-
import inspect
import sys
from unittest import TestCase
from unittest.mock import patch, Mock
@ -67,6 +68,75 @@ class TestImportCommandHandler(DataTestCase):
transaction_comment="hello world",
)
def test_run_missing_input(self):
handler = self.make_handler(
import_handler="wuttasync.importing.csv:FromCsvToWutta"
)
class Object:
def __init__(self, **kw):
self.__dict__.update(kw)
# fails without input_file_path
with patch.object(sys, "exit") as exit_:
exit_.side_effect = RuntimeError
ctx = Object(
params={},
parent=Object(params={}),
)
try:
handler.run(ctx)
except RuntimeError:
pass
exit_.assert_called_once_with(1)
# runs with input_file_path
with patch.object(sys, "exit") as exit_:
exit_.side_effect = RuntimeError
ctx = Object(
params={"input_file_path": self.tempdir},
parent=Object(
params={},
),
)
self.assertRaises(FileNotFoundError, handler.run, ctx)
exit_.assert_not_called()
def test_run_missing_output(self):
handler = self.make_handler(
import_handler="wuttasync.exporting.csv:FromWuttaToCsv"
)
class Object:
def __init__(self, **kw):
self.__dict__.update(kw)
# fails without output_file_path
with patch.object(sys, "exit") as exit_:
exit_.side_effect = RuntimeError
ctx = Object(
params={},
parent=Object(params={}),
)
try:
handler.run(ctx)
except RuntimeError:
pass
exit_.assert_called_once_with(1)
# runs with output_file_path
with patch.object(sys, "exit") as exit_:
exit_.side_effect = RuntimeError
ctx = Object(
params={"output_file_path": self.tempdir},
parent=Object(
params={},
),
)
# self.assertRaises(FileNotFoundError, handler.run, ctx)
handler.run(ctx)
exit_.assert_not_called()
def test_list_models(self):
handler = self.make_handler(
import_handler="wuttasync.importing.csv:FromCsvToWutta"
@ -96,6 +166,23 @@ class TestImporterCommand(TestCase):
self.assertIn("dry_run", sig2.parameters)
class TestFileExporterCommand(TestCase):
def test_basic(self):
def myfunc(ctx, **kwargs):
pass
sig1 = inspect.signature(myfunc)
self.assertIn("kwargs", sig1.parameters)
self.assertNotIn("dry_run", sig1.parameters)
self.assertNotIn("output_file_path", sig1.parameters)
wrapt = mod.file_export_command(myfunc)
sig2 = inspect.signature(wrapt)
self.assertNotIn("kwargs", sig2.parameters)
self.assertIn("dry_run", sig2.parameters)
self.assertIn("output_file_path", sig2.parameters)
class TestFileImporterCommand(TestCase):
def test_basic(self):