Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-diu
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bryan BRANCOTTE
django-diu
Commits
21618991
Commit
21618991
authored
4 years ago
by
Hervé Ménager
Browse files
Options
Downloads
Patches
Plain Diff
add basic test for XMLImportTask
parent
d070928f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/management/commands/xml_command.py
+40
-0
40 additions, 0 deletions
tests/management/commands/xml_command.py
tests/management/commands/xml_command_file.xml
+6
-0
6 additions, 0 deletions
tests/management/commands/xml_command_file.xml
tests/tests.py
+6
-1
6 additions, 1 deletion
tests/tests.py
with
52 additions
and
1 deletion
tests/management/commands/xml_command.py
0 → 100644
+
40
−
0
View file @
21618991
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
This diff is collapsed.
Click to expand it.
tests/management/commands/xml_command_file.xml
0 → 100644
+
6
−
0
View file @
21618991
<toto>
<a
value=
"A"
/>
<a
value=
"B"
/>
<a
value=
"C"
/>
<a
value=
"D"
/>
</toto>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/tests.py
+
6
−
1
View file @
21618991
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment