Reputation: 718
I've an issues finding the ideal way to test the API endpoint developed in Django with the Django Rest Framework. I'm using the integrated APITestCase and performing the request like this:
response = self.client.get('/resources')
The official documentation (http://www.django-rest-framework.org/api-guide/testing) states that is better to use response.data
instaed of response.content
. My model includes a DateTimeField
field and the response.data
looks like this:
{'id': 1, 'issued': datetime.datetime(2014, 5, 3, 0, 0, tzinfo=<UTC>)}
Where as the real response in a browser looks like this:
{"id": 1, "issued": "2014-05-03T00:00:00Z"}
So I'm not sure how to assert that those two are equal!?
Upvotes: 8
Views: 1422
Reputation: 2175
For assert that those two are equal you can use
`self.assertEqual( wanted_datetime,'got_datetime')`
and to compare datetime in django you can look at following link.
1.Django unit testing with date/time-based objects
2.How to compare dates in Django
Upvotes: 0