Response to Django Rest Framework API Test Response

I'm having trouble finding the perfect way to test the API endpoint developed by Django using the Django Rest Framework. I use the integrated APITestCase and execute the query as follows:

response = self.client.get('/resources')

The official documentation ( http://www.django-rest-framework.org/api-guide/testing ) states that it is better to use response.datainstaed response.content. My model includes a field DateTimeField, and response.datalooks like this:

{'id': 1, 'issued': datetime.datetime(2014, 5, 3, 0, 0, tzinfo=<UTC>)}

If the real answer in the browser looks like this:

{"id": 1, "issued": "2014-05-03T00:00:00Z"}

So, I'm not sure how to argue that these two are equal !?

+4
source share
1 answer

, ,

`self.assertEqual( wanted_datetime,'got_datetime)`

datetime django .

1. Django , /

2. Django

0

Source: https://habr.com/ru/post/1541936/


All Articles