client = RequestsClient()
client.headers.update({'x-test': 'true'})AttributeError: 'Client' object has no attribute 'headers'
certifi==2017.11.5chardet==3.0.4coverage==4.4.2Django==2.0.1django-reversion==2.0.12django-reversion-compare==0.8.3djangorestframework==3.7.7djangorestframework-jwt==1.11.0idna==2.6PyJWT==1.5.3pytz==2017.3requests==2.18.4urllib3==1.22--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.test import TestCasefrom dummy.models import Dummyfrom rest_framework.test import RequestsClientfrom requests import Sessionfrom user.models import User
class DummyTestCase(TestCase): client = RequestsClient() url = '/dummies/' headers = {'content-type': 'application/json'} token = '' headers = {}
def setUp(self): Dummy.objects.create(name='this is a dummy test') User.objects.create_user('username', 'email', 'Password1234') result = self.client.post('/api-token-auth/', data={'username':'username','password':'Password1234'}) self.token = result.data['token'] self.headers['Authorization'] = 'JWT ' + self.token
def test_can_GET_dummies(self): self.client.headers.update({'Authorization': 'JWT ' + self.token}) #print(self.headers) response = self.client.get(self.url, headers=self.headers) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1)
python manage.py testLinovia.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.