Browse Source

Minmaxing tests suite

Rafał Pitoń 11 years ago
parent
commit
44bdd68bb6

+ 11 - 1
misago/views/tests/test_exceptions.py → misago/views/tests/test_exceptionhandler.py

@@ -45,7 +45,7 @@ class GetExceptionHandlerTests(TestCase):
         self.assertEqual(len(exceptionhandler.HANDLED_EXCEPTIONS),
         self.assertEqual(len(exceptionhandler.HANDLED_EXCEPTIONS),
                          len(exceptionhandler.EXCEPTION_HANDLERS))
                          len(exceptionhandler.EXCEPTION_HANDLERS))
 
 
-    def test_get_exception_handler(self):
+    def test_get_exception_handler_for_handled_exceptions(self):
         """Exception handler has correct handler for every Misago exception"""
         """Exception handler has correct handler for every Misago exception"""
         for exception in exceptionhandler.HANDLED_EXCEPTIONS:
         for exception in exceptionhandler.HANDLED_EXCEPTIONS:
             try:
             try:
@@ -54,6 +54,16 @@ class GetExceptionHandlerTests(TestCase):
                 self.fail(
                 self.fail(
                     "%s has no exception handler defined" % exception.__name__)
                     "%s has no exception handler defined" % exception.__name__)
 
 
+    def test_get_exception_handler_for_non_handled_exceptio(self):
+        """Exception handler has no handler for non-supported exception"""
+        for exception in INVALID_EXCEPTIONS:
+            try:
+                exceptionhandler.get_exception_handler(exception())
+                self.fail("%s has exception handler, but it "
+                          "shouldn't" % exception.__name__)
+            except ValueError:
+                pass
+
 
 
 class HandleHttp404ExceptionTests(TestCase):
 class HandleHttp404ExceptionTests(TestCase):
     def setUp(self):
     def setUp(self):

+ 8 - 6
misago/views/tests/test_middleware.py

@@ -9,14 +9,16 @@ class MisagoExceptionHandlerMiddlewareTests(TestCase):
     def setUp(self):
     def setUp(self):
         self.request = RequestFactory().get(reverse('forum_index'))
         self.request = RequestFactory().get(reverse('forum_index'))
 
 
-    def test_middleware_returns_none_for_non_supported_exception(self):
-        exception = TypeError()
-        middleware = MisagoExceptionHandlerMiddleware()
-
-        self.assertFalse(middleware.process_exception(self.request, exception))
-
     def test_middleware_returns_response_for_supported_exception(self):
     def test_middleware_returns_response_for_supported_exception(self):
+        "Middleware returns HttpResponse for supported exception"
         exception = Http404()
         exception = Http404()
         middleware = MisagoExceptionHandlerMiddleware()
         middleware = MisagoExceptionHandlerMiddleware()
 
 
         self.assertTrue(middleware.process_exception(self.request, exception))
         self.assertTrue(middleware.process_exception(self.request, exception))
+
+    def test_middleware_returns_none_for_non_supported_exception(self):
+        """Middleware returns None for non-supported exception"""
+        exception = TypeError()
+        middleware = MisagoExceptionHandlerMiddleware()
+
+        self.assertFalse(middleware.process_exception(self.request, exception))