In environments different from local, I set DJ_SSL_REDIRECT = True
for my Django project.
But now, all my unit tests related to REST API endpoints failed when they are run in another environment (for example, in Travis CI).
What is happening is that all HTTP responses are 301
(I'm expecting 2XX
or 4XX
in my tests) because of the DJ_SSL_REDIRECT
setting, as explained in doc :
If you set the SECURE_SSL_REDIRECT setting to True, SecurityMiddleware will permanently (HTTP 301) redirect all HTTP connections to HTTPS.
How can I deal with this in a simple way, keeping my unit tests relevant? Thanks.
Note : I'm using Django Rest Framework 3.5
I've had a similar problem and solved it using the "secure"-attribute for the testing client post ang get functions, like
response = self.client.post('/accounts/signup/', self.getvalues(), follow=True, secure=True)
Hope this helps!
Mikko
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With