test_context_processors.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. serialized_rollback = True
  13. def test_site_address_for_http(self):
  14. """Correct SITE_ADDRESS set for HTTP request"""
  15. http_somewhere_com = MockRequest(False, 'somewhere.com')
  16. self.assertEqual(
  17. context_processors.site_address(http_somewhere_com),
  18. {
  19. 'SITE_ADDRESS': 'http://somewhere.com',
  20. 'SITE_HOST': 'somewhere.com',
  21. })
  22. def test_site_address_for_https(self):
  23. """Correct SITE_ADDRESS set for HTTPS request"""
  24. https_somewhere_com = MockRequest(True, 'somewhere.com')
  25. self.assertEqual(
  26. context_processors.site_address(https_somewhere_com),
  27. {
  28. 'SITE_ADDRESS': 'https://somewhere.com',
  29. 'SITE_HOST': 'somewhere.com',
  30. })