Skip to content
Snippets Groups Projects
Commit 7c8af895 authored by Jean-Baptiste's avatar Jean-Baptiste
Browse files

update: add location header on every 200 responses

parent 2c4fd05a
No related branches found
No related tags found
1 merge request!61Resolve "Send `location` header on edit?"
Pipeline #940 passed
This commit is part of merge request !61. Comments created here will be created in the context of that merge request.
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)
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment