Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Monitor
Incidents
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
djangoldp-packages
djangoldp
Commits
a49c824e
Commit
a49c824e
authored
6 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
update: add test reproducing the
#94
error
parent
0b6e9b0c
No related branches found
No related tags found
No related merge requests found
Pipeline
#771
failed
6 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/tests/models.py
+17
-0
17 additions, 0 deletions
djangoldp/tests/models.py
djangoldp/tests/tests_save.py
+38
-4
38 additions, 4 deletions
djangoldp/tests/tests_save.py
with
55 additions
and
4 deletions
djangoldp/tests/models.py
+
17
−
0
View file @
a49c824e
...
...
@@ -32,3 +32,20 @@ class Dummy(models.Model):
class
LDPDummy
(
Model
):
some
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
class
Invoice
(
Model
):
title
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
class
Batch
(
Model
):
invoice
=
models
.
ForeignKey
(
Invoice
,
on_delete
=
models
.
CASCADE
,
related_name
=
'
batches
'
)
title
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
class
Task
(
models
.
Model
):
batch
=
models
.
ForeignKey
(
Batch
,
on_delete
=
models
.
CASCADE
,
related_name
=
'
tasks
'
)
title
=
models
.
CharField
(
max_length
=
255
)
Batch
.
_meta
.
serializer_fields
=
[
'
@id
'
,
'
title
'
,
'
invoice
'
,
'
tasks
'
]
Task
.
_meta
.
serializer_fields
=
[
'
@id
'
,
'
title
'
,
'
batch
'
]
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_save.py
+
38
−
4
View file @
a49c824e
from
django.test
import
TestCase
from
djangoldp.serializers
import
LDPSerializer
from
djangoldp.tests.models
import
Skill
,
JobOffer
from
djangoldp.tests.models
import
Skill
,
JobOffer
,
Invoice
class
Save
(
TestCase
):
def
test_save_m2m_graph_with_many_nested
(
self
):
invoice
=
{
"
@graph
"
:
[
{
"
@id
"
:
"
./
"
,
"
batches
"
:
{
"
@id
"
:
"
_:b381
"
},
"
title
"
:
"
Nouvelle facture
"
,
},
{
"
@id
"
:
"
_:b381
"
,
"
tasks
"
:
{
"
@id
"
:
"
_:b382
"
},
"
title
"
:
"
Batch 1
"
},
{
"
@id
"
:
"
_:b382
"
,
"
title
"
:
"
Tache 1
"
}
]
}
meta_args
=
{
'
model
'
:
Invoice
,
'
depth
'
:
1
,
'
fields
'
:
(
"
@id
"
,
"
title
"
,
"
batches
"
)}
meta_class
=
type
(
'
Meta
'
,
(),
meta_args
)
serializer_class
=
type
(
LDPSerializer
)(
'
InvoiceSerializer
'
,
(
LDPSerializer
,),
{
'
Meta
'
:
meta_class
})
serializer
=
serializer_class
(
data
=
invoice
)
serializer
.
is_valid
()
result
=
serializer
.
save
()
self
.
assertEquals
(
result
.
title
,
"
Nouvelle facture
"
)
self
.
assertIs
(
result
.
batches
.
count
(),
1
)
self
.
assertEquals
(
result
.
batches
.
all
()[
0
].
title
,
"
Batch 1
"
)
self
.
assertIs
(
result
.
batches
.
all
()[
0
].
tasks
.
count
(),
1
)
#self.assertEquals(result.batches.all()[0].tasks.all()[0].title, "Tache 1")
def
test_save_m2m
(
self
):
skill1
=
Skill
.
objects
.
create
(
title
=
"
skill1
"
,
obligatoire
=
"
obligatoire
"
)
skill2
=
Skill
.
objects
.
create
(
title
=
"
skill2
"
,
obligatoire
=
"
obligatoire
"
)
...
...
@@ -35,9 +69,9 @@ class Save(TestCase):
def
test_save_m2m_graph_simple
(
self
):
job
=
{
"
@graph
"
:
[
{
"
title
"
:
"
job test
"
,
},
]}
{
"
title
"
:
"
job test
"
,
},
]}
meta_args
=
{
'
model
'
:
JobOffer
,
'
depth
'
:
1
,
'
fields
'
:
(
"
@id
"
,
"
title
"
,
"
skills
"
)}
...
...
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