diff --git a/tests/management/commands/xml_command.py b/tests/management/commands/xml_command.py new file mode 100644 index 0000000000000000000000000000000000000000..ee1d8b67c7c716b6dfa757ae00348a97b1bf6a67 --- /dev/null +++ b/tests/management/commands/xml_command.py @@ -0,0 +1,40 @@ +import os + +from django.db import models +from django_diu import import_command + +from tests.models import AModel + +class XMLImportTask(import_command.XMLImportTask): + + description = "A very basic 'import from XML' test task" + + option = "b" + + target_classes = [AModel] + + main_class = AModel + + depends_on = [] + + xpathSelector = 'a' + + def __init__(self, command, **kwargs): + super().__init__(command, **kwargs) + self.xmlFile = command.xmlFile + + def migrate_row(self, row): + a = AModel() + a.a_field = row.get("value")[0] + a.save() + return a + + +class Command(import_command.ImportCommand): + + help = "Test command to test django-diu's ImportCommand" + + xmlFile = os.path.join(os.path.dirname(__file__),'xml_command_file.xml') + + # list all the import tasks that should be available via the command + task_classes = [XMLImportTask] \ No newline at end of file diff --git a/tests/management/commands/xml_command_file.xml b/tests/management/commands/xml_command_file.xml new file mode 100644 index 0000000000000000000000000000000000000000..f2f7ef506fdc2dd35e15af6b9bbbae1655b5bee7 --- /dev/null +++ b/tests/management/commands/xml_command_file.xml @@ -0,0 +1,6 @@ +<toto> + <a value="A" /> + <a value="B" /> + <a value="C" /> + <a value="D" /> +</toto> \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index b257de3339aa3a2c3b29cecaee18c18f25125b28..8b5c24cf85248e555b3107839b52b1c7d6f1722c 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -25,8 +25,13 @@ from .models import AModel class CommandTests(TestCase): - def test_command(self): + def test_list_command(self): management.call_command('a_command', 'a') count = AModel.objects.count() self.assertEquals(count, 4) + def test_xml_command(self): + management.call_command('xml_command', 'b') + count = AModel.objects.count() + self.assertEquals(count, 4) +