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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.