Commit a783dd8c authored by Jean-Baptiste's avatar Jean-Baptiste

update: fix @id on nested GET

parent a3378d36
Pipeline #5299 passed with stage
in 1 minute and 21 seconds
......@@ -69,8 +69,8 @@ class LDListMixin:
container_permissions.extend(
Model.get_permissions(parent_model, self.context['request'].user,
['view']))
if self.id == '':
self.id = '{}{}'.format(settings.SITE_URL, Model.resource(parent_model))
if not self.id.startswith('http'):
self.id = '{}{}{}'.format(settings.SITE_URL, Model.resource(parent_model), self.id)
return {'@id': self.id,
'@type': 'ldp:Container',
'ldp:contains': super().to_representation(filtered_values),
......@@ -433,7 +433,10 @@ class LDPSerializer(HyperlinkedModelSerializer):
@classmethod
def many_init(cls, *args, **kwargs):
kwargs['child'] = cls(**kwargs)
return ContainerSerializer(*args, **kwargs)
serializer = ContainerSerializer(*args, **kwargs)
if 'context' in kwargs and getattr(kwargs['context']['view'], 'nested_field', None) is not None:
serializer.id = '{}{}/'.format(serializer.id, kwargs['context']['view'].nested_field)
return serializer
def get_value(self, dictionary):
try:
......
......@@ -37,7 +37,7 @@ settings.configure(DEBUG=False,
}
},
AUTHENTICATION_BACKENDS=(
'django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend'),
'django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend'),
ROOT_URLCONF='djangoldp.urls',
DJANGOLDP_PACKAGES=['djangoldp.tests'],
INSTALLED_APPS=('django.contrib.auth',
......@@ -49,7 +49,7 @@ settings.configure(DEBUG=False,
'djangoldp.tests',
),
SITE_URL='http://happy-dev.fr',
REST_FRAMEWORK = {
REST_FRAMEWORK={
'DEFAULT_PAGINATION_CLASS': 'djangoldp.pagination.LDPPagination',
'PAGE_SIZE': 5
},
......
import json
from rest_framework.test import APIRequestFactory, APIClient, APITestCase
from django.contrib.auth.models import User
from rest_framework.test import APIRequestFactory, APIClient, APITestCase
from djangoldp.tests.models import Post, Task, Invoice, JobOffer, Skill
from djangoldp.tests.models import Post, Invoice, JobOffer, Skill, Batch
class TestGET(APITestCase):
......@@ -27,13 +26,13 @@ class TestGET(APITestCase):
response = self.client.get('/posts/', content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
self.assertIn('permissions', response.data)
self.assertEquals(2, len(response.data['permissions'])) # read and add
self.assertEquals(2, len(response.data['permissions'])) # read and add
Invoice.objects.create(title="content")
response = self.client.get('/invoices/', content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
self.assertIn('permissions', response.data)
self.assertEquals(1, len(response.data['permissions'])) # read only
self.assertEquals(1, len(response.data['permissions'])) # read only
def test_get_empty_container(self):
Post.objects.all().delete()
......@@ -74,4 +73,9 @@ class TestGET(APITestCase):
self.assertIn('some_skill', response.data)
self.assertEqual(response.data['some_skill']['@id'], "http://testserver/skills/1/")
def test_get_nested(self):
invoice = Invoice.objects.create(title="invoice")
batch = Batch.objects.create(invoice=invoice, title="batch")
response = self.client.get('/invoices/{}/batches/'.format(invoice.pk), content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
self.assertEquals(response.data['@id'], 'http://happy-dev.fr/invoices/{}/batches/'.format(invoice.pk))
......@@ -4,7 +4,7 @@ from django.contrib.auth.models import User
from django.test import TestCase
from rest_framework.test import APIRequestFactory, APIClient
from djangoldp.tests.models import Resource, JobOffer
from djangoldp.tests.models import Resource, JobOffer, Invoice, Batch
class TestTemp(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment