|
@@ -1,4 +1,3 @@
|
|
|
-from django.core.urlresolvers import reverse
|
|
|
from django.http import Http404
|
|
|
from django.core import exceptions as django_exceptions
|
|
|
from django.core.exceptions import PermissionDenied
|
|
@@ -56,93 +55,3 @@ class GetExceptionHandlerTests(TestCase):
|
|
|
for exception in INVALID_EXCEPTIONS:
|
|
|
with self.assertRaises(ValueError):
|
|
|
exceptionhandler.get_exception_handler(exception())
|
|
|
-
|
|
|
-
|
|
|
-class HandleHttp404ExceptionTests(TestCase):
|
|
|
- def setUp(self):
|
|
|
- self.exception = Http404()
|
|
|
- self.request = RequestFactory().get(reverse('forum_index'))
|
|
|
-
|
|
|
- def test_get_handle_http404_exception(self):
|
|
|
- """get_exception_handler returns correct Http404 exception handler"""
|
|
|
- found_handler = exceptionhandler.get_exception_handler(self.exception)
|
|
|
- self.assertEqual(
|
|
|
- found_handler, exceptionhandler.handle_http404_exception)
|
|
|
-
|
|
|
- response = found_handler(self.request, self.exception)
|
|
|
- self.assertEqual(response.status_code, 404)
|
|
|
-
|
|
|
- def test_handle_http404_exception(self):
|
|
|
- """handle_misago_exception handles Http404 exception correctly"""
|
|
|
- response = exceptionhandler.handle_misago_exception(
|
|
|
- self.request, self.exception)
|
|
|
- self.assertEqual(response.status_code, 404)
|
|
|
-
|
|
|
-
|
|
|
-class HandleOutdatedSlugExceptionTests(TestCase):
|
|
|
- def setUp(self):
|
|
|
- self.exception = OutdatedSlug()
|
|
|
- self.request = RequestFactory().get(reverse('forum_index'))
|
|
|
-
|
|
|
- def test_get_handle_outdated_slug_exception(self):
|
|
|
- """
|
|
|
- get_exception_handler returns correct OutdatedSlug exception handler
|
|
|
- """
|
|
|
- found_handler = exceptionhandler.get_exception_handler(self.exception)
|
|
|
- self.assertEqual(
|
|
|
- found_handler, exceptionhandler.handle_outdated_slug_exception)
|
|
|
-
|
|
|
- response = found_handler(self.request, self.exception)
|
|
|
- self.assertEqual(response.status_code, 301)
|
|
|
-
|
|
|
- def test_handle_outdated_slug_exception(self):
|
|
|
- """
|
|
|
- handle_misago_exception handles OutdatedSlug exception correctly
|
|
|
- """
|
|
|
- response = exceptionhandler.handle_misago_exception(
|
|
|
- self.request, self.exception)
|
|
|
- self.assertEqual(response.status_code, 301)
|
|
|
-
|
|
|
-
|
|
|
-class HandlePermissionDeniedExceptionTests(TestCase):
|
|
|
- def setUp(self):
|
|
|
- self.exception_message = "Page access not allowed"
|
|
|
- self.exception = PermissionDenied(self.exception_message)
|
|
|
- self.request = RequestFactory().get(reverse('forum_index'))
|
|
|
-
|
|
|
- def test_get_handle_permission_denied_exception(self):
|
|
|
- """
|
|
|
- get_exception_handler returns correct PermissionDenied exception
|
|
|
- handler
|
|
|
- """
|
|
|
- found_handler = exceptionhandler.get_exception_handler(self.exception)
|
|
|
- self.assertEqual(
|
|
|
- found_handler, exceptionhandler.handle_permission_denied_exception)
|
|
|
-
|
|
|
- response = found_handler(self.request, self.exception)
|
|
|
- self.assertIn(self.exception_message, response.content)
|
|
|
- self.assertEqual(response.status_code, 403)
|
|
|
-
|
|
|
- def test_handle_permission_denied_exception(self):
|
|
|
- """
|
|
|
- handle_misago_exception handles PermissionDenied exception correctly
|
|
|
- """
|
|
|
- response = exceptionhandler.handle_misago_exception(
|
|
|
- self.request, self.exception)
|
|
|
- self.assertIn(self.exception_message, response.content)
|
|
|
- self.assertEqual(response.status_code, 403)
|
|
|
-
|
|
|
-
|
|
|
-class GetExceptionMessageTests(TestCase):
|
|
|
- def test_get_exception_message(self):
|
|
|
- """_get_exception_message returns message for exception with one"""
|
|
|
- message = "Fish's name Eric"
|
|
|
- exception = Http404(message)
|
|
|
- self.assertEqual(exceptionhandler._get_exception_message(exception),
|
|
|
- message)
|
|
|
-
|
|
|
- def test_get_no_exception_message(self):
|
|
|
- """_get_exception_message returns None for exception without one"""
|
|
|
- exception = Http404()
|
|
|
- self.assertEqual(exceptionhandler._get_exception_message(exception),
|
|
|
- None)
|