kapt-labs / django-check-seo

Django Check SEO will check the SEO aspects of your site for you, and will provide advice in case of problems. Compatible with Django & Django-CMS!
GNU General Public License v3.0
154 stars 12 forks source link

Have the test-client follow redirects #56

Closed mbi closed 1 year ago

mbi commented 1 year ago

On the production machine, we have SECURE_SSL_REDIRECT = True, and as a result, the test client redirects by default:

from django.test import Client
client = Client()
resp = client.get('/fr/')
print(resp) 
<HttpResponsePermanentRedirect status_code=301, "text/html; charset=utf-8", url="https://testserver/fr/">

As a result, response.content is empty and BeautifulSoup chokes, resulting in a error 500 down the line.

With this patch, the test client follows redirects and as a result, we get html to feed to BeautifulSoup.

corentinbettiol commented 1 year ago

Hi! Thanks for this new PR!

We had an optional setting for this before switching to the new TestClient, so we have 3 choices here: 1) enable the auto-follow-redirects after adding a setting 2) just add the auto-follow-redirects feature and activate it without any setting 3) add & activate the auto-follow-redirects feature, but add an optional setting to disable it

Since we're not using requests anymore, this feature should not bring any risks (for example this cve), so we may just allow the redirects every time, but I will re-check that there's no other problem we're missing here.

corentinbettiol commented 1 year ago

Hi! Thank you for your patience, I searched for more information on following redirects in django test client and found nothing.

corentinbettiol commented 1 year ago

Version 0.6.1 is out and includes these changes!

mbi commented 1 year ago

Awesome, thank you! I'll update my projects to use this version instead of our fork ^^