Closed
Description
When running tests the response.data
doesn't contain data
key. Instead the results
key is available.
Example code:
class AdvertsTestCase(APITestCase):
def test_get_adverts_list(self):
advert1 = f.AdvertFactory.create()
advert2 = f.AdvertFactory.create()
advert3 = f.AdvertFactory.create()
url = reverse('advert-list')
response = self.client.get(url)
print(response.data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
The result from print(response.data)
{'results': [ ... ], 'meta': { ... }, 'links': { ... }}
But when access the response.content
there is data
attribute in the raw response's data:
b'{"links":{ ... },"data":[ ... ],"meta":{ ... }'
When accessing API via Postman or web-browser, the data
key in the response is available. Seems like tests doesn't use renderers correctly - it's my assumption.
requirements.txt
Django==2.0.4
psycopg2-binary==2.7.4
djangorestframework==3.7.7
django-cors-headers==2.2.0
boto3==1.6.15
django-storages==1.6.5
environs==2.1.0
django-dirtyfields==1.3.1
django-filter==1.1.0
drf_yasg==1.7.0
djangorestframework-jsonapi==2.4.0
Metadata
Metadata
Assignees
Labels
No labels