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
Fay Arnold
djangoldp
Commits
f9c6853e
Commit
f9c6853e
authored
6 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
update: add test reproducing the issue 85
parent
67c7eba4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/tests/models.py
+2
-0
2 additions, 0 deletions
djangoldp/tests/models.py
djangoldp/tests/tests_update.py
+60
-3
60 additions, 3 deletions
djangoldp/tests/tests_update.py
with
62 additions
and
3 deletions
djangoldp/tests/models.py
+
2
−
0
View file @
f9c6853e
...
@@ -14,10 +14,12 @@ class JobOffer(models.Model):
...
@@ -14,10 +14,12 @@ class JobOffer(models.Model):
class
Thread
(
models
.
Model
):
class
Thread
(
models
.
Model
):
description
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
description
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
author_user
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
)
class
Message
(
models
.
Model
):
class
Message
(
models
.
Model
):
text
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
text
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
thread
=
models
.
ForeignKey
(
Thread
,
on_delete
=
models
.
DO_NOTHING
)
thread
=
models
.
ForeignKey
(
Thread
,
on_delete
=
models
.
DO_NOTHING
)
author_user
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
)
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_update.py
+
60
−
3
View file @
f9c6853e
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
django.test
import
TestCase
from
djangoldp.serializers
import
LDPSerializer
from
djangoldp.serializers
import
LDPSerializer
...
@@ -136,9 +137,10 @@ class Serializer(TestCase):
...
@@ -136,9 +137,10 @@ class Serializer(TestCase):
self
.
assertEquals
(
skills
[
2
].
title
,
"
skill2 UP
"
)
# title updated
self
.
assertEquals
(
skills
[
2
].
title
,
"
skill2 UP
"
)
# title updated
def
test_update_list_with_reverse_relation
(
self
):
def
test_update_list_with_reverse_relation
(
self
):
thread
=
Thread
.
objects
.
create
(
description
=
"
Thread 1
"
)
user1
=
User
.
objects
.
create
()
message1
=
Message
.
objects
.
create
(
text
=
"
Message 1
"
,
thread
=
thread
)
thread
=
Thread
.
objects
.
create
(
description
=
"
Thread 1
"
,
author_user
=
user1
)
message2
=
Message
.
objects
.
create
(
text
=
"
Message 2
"
,
thread
=
thread
)
message1
=
Message
.
objects
.
create
(
text
=
"
Message 1
"
,
thread
=
thread
,
author_user
=
user1
)
message2
=
Message
.
objects
.
create
(
text
=
"
Message 2
"
,
thread
=
thread
,
author_user
=
user1
)
json
=
{
"
@graph
"
:
[
json
=
{
"
@graph
"
:
[
...
@@ -173,3 +175,58 @@ class Serializer(TestCase):
...
@@ -173,3 +175,58 @@ class Serializer(TestCase):
self
.
assertIs
(
result
.
message_set
.
count
(),
2
)
self
.
assertIs
(
result
.
message_set
.
count
(),
2
)
self
.
assertEquals
(
messages
[
0
].
text
,
"
Message 1 UP
"
)
self
.
assertEquals
(
messages
[
0
].
text
,
"
Message 1 UP
"
)
self
.
assertEquals
(
messages
[
1
].
text
,
"
Message 2 UP
"
)
self
.
assertEquals
(
messages
[
1
].
text
,
"
Message 2 UP
"
)
def
test_add_new_element_with_foreign_key_id
(
self
):
user1
=
User
.
objects
.
create
()
thread
=
Thread
.
objects
.
create
(
description
=
"
Thread 1
"
,
author_user
=
user1
)
message1
=
Message
.
objects
.
create
(
text
=
"
Message 1
"
,
thread
=
thread
,
author_user
=
user1
)
message2
=
Message
.
objects
.
create
(
text
=
"
Message 2
"
,
thread
=
thread
,
author_user
=
user1
)
json
=
{
"
@graph
"
:
[
{
"
@id
"
:
"
https://happy-dev.fr/messages/{}/
"
.
format
(
message1
.
pk
),
"
text
"
:
"
Message 1 UP
"
,
"
author_user_id
"
:
user1
.
pk
,
},
{
"
@id
"
:
"
https://happy-dev.fr/messages/{}/
"
.
format
(
message2
.
pk
),
"
text
"
:
"
Message 2 UP
"
,
"
author_user_id
"
:
user1
.
pk
,
},
{
"
@id
"
:
"
_:b1
"
,
"
text
"
:
"
Message 3 NEW
"
,
"
author_user_id
"
:
user1
.
pk
,
},
{
'
@id
'
:
"
https://happy-dev.fr/threads/{}
"
.
format
(
thread
.
pk
),
"
author_user_id
"
:
user1
.
pk
,
'
description
'
:
"
Thread 1 UP
"
,
'
message_set
'
:
{
"
@id
"
:
"
https://happy-dev.fr/threads/{}/message_set
"
.
format
(
thread
.
pk
)
}
},
{
'
@id
'
:
"
https://happy-dev.fr/threads/{}/message_set
"
.
format
(
thread
.
pk
),
"
ldp:contains
"
:
[
{
"
@id
"
:
"
https://happy-dev.fr/messages/{}/
"
.
format
(
message1
.
pk
)},
{
"
@id
"
:
"
https://happy-dev.fr/messages/{}/
"
.
format
(
message2
.
pk
)},
{
"
@id
"
:
"
_:b1
"
}
]
}
]
}
meta_args
=
{
'
model
'
:
Thread
,
'
depth
'
:
1
,
'
fields
'
:
(
"
@id
"
,
"
description
"
,
"
message_set
"
)}
meta_class
=
type
(
'
Meta
'
,
(),
meta_args
)
serializer_class
=
type
(
LDPSerializer
)(
'
ThreadSerializer
'
,
(
LDPSerializer
,),
{
'
Meta
'
:
meta_class
})
serializer
=
serializer_class
(
data
=
json
,
instance
=
thread
)
serializer
.
is_valid
()
result
=
serializer
.
save
()
messages
=
result
.
message_set
.
all
().
order_by
(
'
text
'
)
self
.
assertEquals
(
result
.
description
,
"
Thread 1 UP
"
)
self
.
assertIs
(
result
.
message_set
.
count
(),
3
)
self
.
assertEquals
(
messages
[
0
].
text
,
"
Message 1 UP
"
)
self
.
assertEquals
(
messages
[
1
].
text
,
"
Message 2 UP
"
)
self
.
assertEquals
(
messages
[
2
].
text
,
"
Message 3 NEW
"
)
\ No newline at end of file
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