Skip to content

Inject user to middleware tests #5203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions readthedocs/rtd_tests/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from corsheaders.middleware import CorsMiddleware
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.http import Http404
from django.test import TestCase
from django.test.client import RequestFactory
Expand Down Expand Up @@ -32,6 +33,7 @@ def setUp(self):
def test_failey_cname(self):
self.assertFalse(Domain.objects.filter(domain='my.host.com').exists())
request = self.factory.get(self.url, HTTP_HOST='my.host.com')
request.user = AnonymousUser()
r = self.middleware.process_request(request)
self.assertEqual(r.status_code, 404)
self.assertEqual(request.cname, True)
Expand Down Expand Up @@ -96,6 +98,7 @@ def test_domain_object(self):
def test_domain_object_missing(self):
self.domain = get(Domain, domain='docs.foobar2.com', project=self.pip)
request = self.factory.get(self.url, HTTP_HOST='docs.foobar.com')
request.user = AnonymousUser()
r = self.middleware.process_request(request)
self.assertEqual(r.status_code, 404)

Expand Down Expand Up @@ -137,15 +140,19 @@ def test_use_subdomain(self):
self.assertEqual(request.slug, 'pip')
self.assertTrue(request.domain_object)

@override_settings(PRODUCTION_DOMAIN='readthedocs.org')
def test_long_bad_subdomain(self):
domain = 'www.pip.readthedocs.org'
request = self.factory.get(self.url, HTTP_HOST=domain)
request.user = AnonymousUser()
res = self.middleware.process_request(request)
self.assertEqual(res.status_code, 400)

@override_settings(PRODUCTION_DOMAIN='readthedocs.org')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was failing bc we override production_domain to readthedocs.com

def test_long_subdomain(self):
domain = 'some.long.readthedocs.org'
request = self.factory.get(self.url, HTTP_HOST=domain)
request.user = AnonymousUser()
res = self.middleware.process_request(request)
self.assertIsNone(res)

Expand Down