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
decentral1se
djangoldp
Compare revisions
master to e997443e84ae1a8dd8b669dd7718724c1efa03af
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
decentral1se/djangoldp
Select target project
No results found
e997443e84ae1a8dd8b669dd7718724c1efa03af
Select Git revision
Swap
Target
djangoldp-packages/djangoldp
Select target project
djangoldp-packages/djangoldp
decentral1se/djangoldp
femmefaytale/djangoldp
jvtrudel/djangoldp
4 results
master
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
inbox endpoint on LDPSerializers for receiving notifications
· 51caf1b2
Calum Mackervoy
authored
5 years ago
51caf1b2
inbox view for nested fields and for resources
· e997443e
Calum Mackervoy
authored
5 years ago
e997443e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
djangoldp/tests/runner.py
+12
-11
12 additions, 11 deletions
djangoldp/tests/runner.py
djangoldp/tests/tests_inbox.py
+39
-0
39 additions, 0 deletions
djangoldp/tests/tests_inbox.py
djangoldp/views.py
+20
-1
20 additions, 1 deletion
djangoldp/views.py
with
71 additions
and
12 deletions
djangoldp/tests/runner.py
View file @
e997443e
...
...
@@ -64,17 +64,18 @@ from django.test.runner import DiscoverRunner
test_runner
=
DiscoverRunner
(
verbosity
=
1
)
failures
=
test_runner
.
run_tests
([
'
djangoldp.tests.tests_ldp_model
'
,
'
djangoldp.tests.tests_save
'
,
'
djangoldp.tests.tests_user_permissions
'
,
'
djangoldp.tests.tests_guardian
'
,
'
djangoldp.tests.tests_anonymous_permissions
'
,
'
djangoldp.tests.tests_update
'
,
'
djangoldp.tests.tests_auto_author
'
,
'
djangoldp.tests.tests_get
'
,
'
djangoldp.tests.tests_delete
'
,
'
djangoldp.tests.tests_sources
'
,
'
djangoldp.tests.tests_pagination
'
,
#'djangoldp.tests.tests_ldp_model',
#'djangoldp.tests.tests_save',
#'djangoldp.tests.tests_user_permissions',
#'djangoldp.tests.tests_guardian',
#'djangoldp.tests.tests_anonymous_permissions',
#'djangoldp.tests.tests_update',
#'djangoldp.tests.tests_auto_author',
#'djangoldp.tests.tests_get',
#'djangoldp.tests.tests_delete',
#'djangoldp.tests.tests_sources',
#'djangoldp.tests.tests_pagination',
'
djangoldp.tests.tests_inbox
'
,
# 'djangoldp.tests.tests_temp'
])
if
failures
:
...
...
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_inbox.py
0 → 100644
View file @
e997443e
import
json
from
django.contrib.auth
import
get_user_model
from
rest_framework.test
import
APIClient
,
APITestCase
from
djangoldp.tests.models
import
PermissionlessDummy
,
JobOffer
,
Skill
class
TestsInbox
(
APITestCase
):
def
setUp
(
self
):
self
.
client
=
APIClient
(
enforce_csrf_checks
=
True
)
def
setUpLoggedInUser
(
self
):
self
.
user
=
get_user_model
().
objects
.
create_user
(
username
=
'
john
'
,
email
=
'
jlennon@beatles.com
'
,
password
=
'
glass onion
'
)
self
.
client
.
force_authenticate
(
user
=
self
.
user
)
def
test_post_to_inbox_container
(
self
):
self
.
setUpLoggedInUser
()
response
=
self
.
client
.
post
(
'
/permissionless-dummys/inbox/
'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_post_to_inbox_resource
(
self
):
self
.
setUpLoggedInUser
()
dummy
=
PermissionlessDummy
.
objects
.
create
(
some
=
'
test
'
,
slug
=
'
test
'
)
response
=
self
.
client
.
post
(
'
/permissionless-dummys/{}/inbox/
'
.
format
(
dummy
.
pk
))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_post_to_inbox_nested_field
(
self
):
self
.
setUpLoggedInUser
()
job_offer
=
JobOffer
.
objects
.
create
(
title
=
'
test
'
,
slug
=
'
test
'
)
response
=
self
.
client
.
post
(
'
/job-offers/{}/skills/inbox/
'
.
format
(
job_offer
.
slug
))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_post_to_inbox_nested_field_resoucre
(
self
):
self
.
setUpLoggedInUser
()
job_offer
=
JobOffer
.
objects
.
create
(
title
=
'
test
'
,
slug
=
'
joboffer1
'
)
skill
=
Skill
.
objects
.
create
(
title
=
'
test
'
,
obligatoire
=
'
test
'
,
slug
=
'
skill1
'
)
response
=
self
.
client
.
post
(
'
/job-offers/{}/skills/{}/inbox/
'
.
format
(
job_offer
.
slug
,
skill
.
slug
))
self
.
assertEqual
(
response
.
status_code
,
200
)
This diff is collapsed.
Click to expand it.
djangoldp/views.py
View file @
e997443e
...
...
@@ -11,6 +11,7 @@ from django.views import View
from
pyld
import
jsonld
from
rest_framework
import
status
from
rest_framework.authentication
import
SessionAuthentication
from
rest_framework.permissions
import
AllowAny
from
rest_framework.parsers
import
JSONParser
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework.response
import
Response
...
...
@@ -57,7 +58,17 @@ class NoCSRFAuthentication(SessionAuthentication):
return
class
LDPViewSetGenerator
(
ModelViewSet
):
class
InboxModelMixin
:
"""
Receive linked data notifications
"""
inbox_actions
=
{
'
post
'
:
'
receiveNotification
'
}
def
receiveNotification
(
self
,
request
,
pk
=
None
,
*
args
,
**
kwargs
):
return
Response
(
'
Hello World!
'
,
status
=
status
.
HTTP_200_OK
)
class
LDPViewSetGenerator
(
ModelViewSet
,
InboxModelMixin
):
"""
An extension of ModelViewSet that generates automatically URLs for the model
"""
model
=
None
nested_fields
=
[]
...
...
@@ -93,8 +104,16 @@ class LDPViewSetGenerator(ModelViewSet):
model_name
=
'
{}-{}
'
.
format
(
kwargs
[
'
model_prefix
'
],
model_name
)
detail_expr
=
cls
.
get_detail_expr
(
**
kwargs
)
# inbox endpoint should have flexible permissions - I can receive a notification from anyone
inbox_kwargs
=
kwargs
inbox_kwargs
[
'
permission_classes
'
]
=
[
AllowAny
]
urls
=
[
url
(
'
^inbox/$
'
,
cls
.
as_view
(
cls
.
inbox_actions
,
**
inbox_kwargs
),
name
=
'
{}-inbox
'
.
format
(
model_name
)),
url
(
'
^$
'
,
cls
.
as_view
(
cls
.
list_actions
,
**
kwargs
),
name
=
'
{}-list
'
.
format
(
model_name
)),
url
(
'
^
'
+
detail_expr
+
'
inbox/$
'
,
cls
.
as_view
(
cls
.
inbox_actions
,
**
inbox_kwargs
),
name
=
'
{}-detail-inbox
'
.
format
(
model_name
)),
url
(
'
^
'
+
detail_expr
+
'
$
'
,
cls
.
as_view
(
cls
.
detail_actions
,
**
kwargs
),
name
=
'
{}-detail
'
.
format
(
model_name
)),
]
...
...
This diff is collapsed.
Click to expand it.