Following redirects with the Django test client

When running unit tests with in Django, the test client’s default behaviour is to stop at the first response, even if that response is a redirect. If you want the client to follow these redirects and return the last page, perform your requests like this: response = c.get(‘/redirect_me/’, follow=True) This will also add response.redirect_chain so […]

Django unit tests: How to populate request.raw_post_data

If you are creating unit tests with Django, you might need to send raw data with the Client object. In the example below, we are testing how our view reacts to a raw POST string sent by another API. The string in question is myrawpoststring. All you need to do is set the data attribute […]