feat: add wutta import-csv command

This commit is contained in:
Lance Edgar 2024-12-05 21:19:06 -06:00
parent 84a8beaf46
commit f43a066341
19 changed files with 500 additions and 15 deletions

0
tests/cli/__init__.py Normal file
View file

0
tests/cli/example.conf Normal file
View file

38
tests/cli/test_base.py Normal file
View file

@ -0,0 +1,38 @@
#-*- coding: utf-8; -*-
import inspect
from unittest import TestCase
from wuttasync.cli import base as mod
class TestImporterCommand(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)
wrapt = mod.importer_command(myfunc)
sig2 = inspect.signature(wrapt)
self.assertNotIn('kwargs', sig2.parameters)
self.assertIn('dry_run', sig2.parameters)
class TestFileImporterCommand(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('input_file_path', sig1.parameters)
wrapt = mod.file_importer_command(myfunc)
sig2 = inspect.signature(wrapt)
self.assertNotIn('kwargs', sig2.parameters)
self.assertIn('dry_run', sig2.parameters)
self.assertIn('input_file_path', sig2.parameters)

View file

@ -0,0 +1,24 @@
#-*- coding: utf-8; -*-
import os
from unittest import TestCase
from unittest.mock import MagicMock, patch
from wuttasync.cli import import_csv as mod
from wuttasync.importing.csv import FromCsvToWutta
here = os.path.dirname(__file__)
example_conf = os.path.join(here, 'example.conf')
class TestImportCsv(TestCase):
def test_basic(self):
ctx = MagicMock(params={'models': [],
'create': True, 'update': True, 'delete': False,
'dry_run': True})
with patch.object(FromCsvToWutta, 'process_data') as process_data:
mod.import_csv(ctx)
process_data.assert_called_once_with(create=True, update=True, delete=False,
dry_run=True)