8

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!?

fabian.kirstein
  • 708
  • 8
  • 26

1 Answers1

0

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

Phoenix
  • 3,996
  • 4
  • 29
  • 40
Amrit
  • 2,115
  • 1
  • 21
  • 41