test_middleware.py 1.27 KB
Newer Older
Calen Pennington committed
1
from django.test import TestCase
2 3 4 5 6

import comment_client
import django.http
import django_comment_client.middleware as middleware

Calen Pennington committed
7

8 9
class AjaxExceptionTestCase(TestCase):

Calen Pennington committed
10
# TODO: check whether the correct error message is produced.
11
# The error message should be the same as the argument to CommentClientError
12 13 14 15 16 17 18 19 20
    def setUp(self):
        self.a = middleware.AjaxExceptionMiddleware()
        self.request1 = django.http.HttpRequest()
        self.request0 = django.http.HttpRequest()
        self.exception1 = comment_client.CommentClientError('{}')
        self.exception2 = comment_client.CommentClientError('Foo!')
        self.exception0 = ValueError()
        self.request1.META['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"
        self.request0.META['HTTP_X_REQUESTED_WITH'] = "SHADOWFAX"
Calen Pennington committed
21

22 23 24 25 26 27
    def test_process_exception(self):
        self.assertIsInstance(self.a.process_exception(self.request1, self.exception1), middleware.JsonError)
        self.assertIsInstance(self.a.process_exception(self.request1, self.exception2), middleware.JsonError)
        self.assertIsNone(self.a.process_exception(self.request1, self.exception0))
        self.assertIsNone(self.a.process_exception(self.request0, self.exception1))
        self.assertIsNone(self.a.process_exception(self.request0, self.exception0))