diff --git a/djangoldp/tests/tests_update.py b/djangoldp/tests/tests_update.py index cbd74bc9116bd16a13923705eb4710487bb61a4c..c94facfe799e8b0d87cda7b30dceb6e878ae4538 100644 --- a/djangoldp/tests/tests_update.py +++ b/djangoldp/tests/tests_update.py @@ -1,12 +1,22 @@ from django.contrib.auth.models import User from django.test import TestCase +from rest_framework.test import APIRequestFactory, APIClient +from rest_framework.utils import json from djangoldp.serializers import LDPSerializer +from djangoldp.tests.models import Post from djangoldp.tests.models import Skill, JobOffer, Conversation, Message class Update(TestCase): + def setUp(self): + self.factory = APIRequestFactory() + self.client = APIClient() + + def tearDown(self): + pass + def test_update(self): skill = Skill.objects.create(title="to drop", obligatoire="obligatoire", slug="slug1") skill1 = Skill.objects.create(title="skill1", obligatoire="obligatoire", slug="slug2") @@ -250,3 +260,13 @@ class Update(TestCase): self.assertEquals(messages[0].text, "Message 1 UP") self.assertEquals(messages[1].text, "Message 2 UP") self.assertEquals(messages[2].text, "Message 3 NEW") + + def test_put_resource(self): + post = Post.objects.create(content="content") + body = [{ + '@id': '/posts/{}/'.format(post.pk), + 'http://happy-dev.fr/owl/#content': "post content"}] + response = self.client.put('/posts/{}/'.format(post.pk), data=json.dumps(body), content_type='application/ld+json') + self.assertEqual(response.status_code, 200) + self.assertEquals(response.data['content'], "post content") + self.assertIn('location', response._headers) diff --git a/djangoldp/views.py b/djangoldp/views.py index f5056c871dcf8c7471f44889461f02d8f4563567..51cfd4537fd09b713a8ca37f81bab3e3d0706398 100644 --- a/djangoldp/views.py +++ b/djangoldp/views.py @@ -140,8 +140,10 @@ class LDPViewSet(LDPViewSetGenerator): response["Access-Control-Expose-Headers"] = "Location" response["Access-Control-Allow-Credentials"] = 'true' response["Accept-Post"] = "application/ld+json" - if response.status_code == 201 and '@id' in response.data: + if response.status_code in [201, 200] and '@id' in response.data: response["Location"] = response.data['@id'] + else: + pass response["Accept-Post"] = "application/ld+json" if request.user.is_authenticated(): try: