test_context_processors.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from django.test import TestCase
  2. from misago.core import context_processors
  3. class MockRequest(object):
  4. def __init__(self, secure, host):
  5. self.secure = secure
  6. self.host = host
  7. def is_secure(self):
  8. return self.secure
  9. def get_host(self):
  10. return self.host
  11. class SiteAddressTests(TestCase):
  12. def test_site_address_for_http(self):
  13. """Correct SITE_ADDRESS set for HTTP request"""
  14. http_somewhere_com = MockRequest(False, 'somewhere.com')
  15. self.assertEqual(
  16. context_processors.site_address(http_somewhere_com),
  17. {
  18. 'SITE_ADDRESS': 'http://somewhere.com',
  19. 'SITE_HOST': 'somewhere.com',
  20. })
  21. def test_site_address_for_https(self):
  22. """Correct SITE_ADDRESS set for HTTPS request"""
  23. https_somewhere_com = MockRequest(True, 'somewhere.com')
  24. self.assertEqual(
  25. context_processors.site_address(https_somewhere_com),
  26. {
  27. 'SITE_ADDRESS': 'https://somewhere.com',
  28. 'SITE_HOST': 'somewhere.com',
  29. })