diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index 75940ba9d7501bd284db1a3497526dd85db2902d..72155ecb1ff32ec791dd4fd62cb1018ec84ff70c 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -285,7 +285,7 @@ class LDPSerializer(HyperlinkedModelSerializer): object_list = dictionary["@graph"] if self.parent.instance is None: obj = next(filter( - lambda o: not hasattr(o, self.parent.url_field_name) or "./" in o[self.url_field_name], + lambda o: not self.parent.url_field_name in o or "./" in o[self.parent.url_field_name], object_list)) value = super().get_value(obj) else: diff --git a/djangoldp/tests/models.py b/djangoldp/tests/models.py index f3c6e88c11d33937f143c44ed2cd7bf078c8a7a4..8bda453d3fa039d7e52302ffba65f3a5e766128c 100644 --- a/djangoldp/tests/models.py +++ b/djangoldp/tests/models.py @@ -98,9 +98,8 @@ class Post(Model): author = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True) peer_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="peers_post") - class Meta: auto_author = 'author' -get_user_model()._meta.serializer_fields = ['@id', 'username', 'first_name', 'last_name', 'email', 'userprofile', 'conversation_set'] +get_user_model()._meta.serializer_fields = ['@id', 'username', 'first_name', 'last_name', 'email', 'userprofile', 'conversation_set',] diff --git a/djangoldp/tests/runner.py b/djangoldp/tests/runner.py index 82859e21c5022f65a5da76022a61154b1ecadc3f..c3d2bf25f3b29e63219831892fbfcf451461e5c2 100644 --- a/djangoldp/tests/runner.py +++ b/djangoldp/tests/runner.py @@ -33,8 +33,8 @@ settings.configure(DEBUG=True, "delete": "acl:Delete", "control": "acl:Control" } - } - , + }, + AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend'), ROOT_URLCONF='djangoldp.urls', DJANGOLDP_PACKAGES=['djangoldp.tests'], INSTALLED_APPS=('django.contrib.auth', diff --git a/djangoldp/tests/tests_save.py b/djangoldp/tests/tests_save.py index d0acfadfa82e0171eee433e8e77798f37f3efb58..c4ca139960d27350215870d93612e0e04f2ff782 100644 --- a/djangoldp/tests/tests_save.py +++ b/djangoldp/tests/tests_save.py @@ -3,7 +3,7 @@ from rest_framework.utils import json from djangoldp.models import Model from djangoldp.serializers import LDPSerializer -from djangoldp.tests.models import Skill, JobOffer, Invoice, Message +from djangoldp.tests.models import Skill, JobOffer, Invoice, LDPDummy class Save(TestCase): @@ -214,3 +214,26 @@ class Save(TestCase): self.assertEqual(response.status_code, 201) self.assertEqual(response.data['peer_user'], None) + def test_save_sub_object_in_new_object_with_reverse_1to1_relation(self): + dummy = LDPDummy.objects.create(some="foo") + + body = [ + { + '@id': "_:b216", + 'http://happy-dev.fr/owl/#description': "user update", + 'http://happy-dev.fr/owl/#ddummy': { + "@id": "https://happy-dev.fr{}{}/".format(Model.container_id(dummy), dummy.id) + } + }, + { + '@id': './', + "http://happy-dev.fr/owl/#first_name": "Alexandre", + "http://happy-dev.fr/owl/#last_name": "Bourlier", + "http://happy-dev.fr/owl/#username": "alex", + 'http://happy-dev.fr/owl/#userprofile': {'@id': "_:b216"} + } + ] + response = self.client.post('/users/', data=json.dumps(body), + content_type='application/ld+json') + self.assertEqual(response.status_code, 201) + self.assertIn('userprofile', response.data) diff --git a/djangoldp/tests/tests_temp.py b/djangoldp/tests/tests_temp.py index 03dfb977037b04c683aa9d60cd8397de5b01022c..1864f386b785ba0ca266a74422bd152cb91c1533 100644 --- a/djangoldp/tests/tests_temp.py +++ b/djangoldp/tests/tests_temp.py @@ -14,31 +14,7 @@ class TestTemp(TestCase): self.client = APIClient() self.user = User.objects.create_user(username='john', email='jlennon@beatles.com', password='glass onion') - def tearDown(self): pass - def test_post_should_accept_missing_field_id_nullable(self): - body = [ - { - '@id': "./", - 'http://happy-dev.fr/owl/#content': "post update", - } - ] - response = self.client.post('/posts/', data=json.dumps(body), - content_type='application/ld+json') - self.assertEqual(response.status_code, 201) - self.assertIn('peer_user', response.data) - - def test_post_should_accept_empty_field_if_nullable(self): - body = [ - { - '@id': "./", - 'http://happy-dev.fr/owl/#content': "post update", - 'http://happy-dev.fr/owl/#peer_user': "" - } - ] - response = self.client.post('/posts/', data=json.dumps(body), - content_type='application/ld+json') - self.assertEqual(response.status_code, 201) - self.assertEqual(response.data['peer_user'], None) + diff --git a/djangoldp/tests/tests_update.py b/djangoldp/tests/tests_update.py index 4e31ea7ded51763a416e57002c90c5a7c84aaafc..c14589889694f5b719e5e5019200885c677977c8 100644 --- a/djangoldp/tests/tests_update.py +++ b/djangoldp/tests/tests_update.py @@ -280,7 +280,10 @@ class Update(TestCase): body = [ { '@id': "_:b975", - 'http://happy-dev.fr/owl/#description': "user description" + 'http://happy-dev.fr/owl/#description': "user description", + 'http://happy-dev.fr/owl/#dummy': { + '@id' : './' + } }, { '@id': '/users/{}/'.format(user.pk),