Skip to content
Snippets Groups Projects
Commit 21618991 authored by Hervé Ménager's avatar Hervé Ménager
Browse files

add basic test for XMLImportTask

parent d070928f
No related branches found
No related tags found
No related merge requests found
Pipeline #39073 passed
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
<toto>
<a value="A" />
<a value="B" />
<a value="C" />
<a value="D" />
</toto>
\ No newline at end of file
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment