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

update: fix @id on custom container views

parent 22f6cb72
Pipeline #5412 passed with stage
in 1 minute and 25 seconds
......@@ -241,7 +241,6 @@ class JsonLdIdentityField(JsonLdField):
return super().get_attribute(instance)
class LDPSerializer(HyperlinkedModelSerializer):
url_field_name = "@id"
serializer_related_field = JsonLdRelatedField
......@@ -461,6 +460,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
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)
elif 'context' in kwargs:
serializer.id = '{}{}'.format(settings.BASE_URL, kwargs['context']['view'].request.path)
return serializer
def to_internal_value(self, data):
......
......@@ -16,3 +16,9 @@ class TestSource(APITestCase):
source = LDPSource.objects.create(federation="source_name", urlid="http://bar.foo/")
response = self.client.get('/sources/{}/'.format(source.federation), content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['@id'], 'http://happy-dev.fr/sources/source_name/')
def test_get_empty_resource(self):
response = self.client.get('/sources/{}/'.format('unknown'), content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['@id'], 'http://happy-dev.fr/sources/unknown/')
......@@ -2,6 +2,9 @@ from django.contrib.auth.models import User
from django.test import TestCase
from rest_framework.test import APIRequestFactory, APIClient
from djangoldp.models import LDPSource
class TestTemp(TestCase):
def setUp(self):
......@@ -12,3 +15,4 @@ class TestTemp(TestCase):
def tearDown(self):
pass
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