blob: 4091eb941223d6e4dc8c21a2bfd53d7b95503daa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import unittest
class TestExceptionResponse(unittest.TestCase):
def _makeOne(self, message):
from repoze.bfg.exceptions import ExceptionResponse
return ExceptionResponse(message)
def test_app_iter(self):
exc = self._makeOne('')
self.failUnless('<code></code>' in exc.app_iter[0])
def test_headerlist(self):
exc = self._makeOne('')
headerlist = exc.headerlist
headerlist.sort()
app_iter = exc.app_iter
clen = str(len(app_iter[0]))
self.assertEqual(headerlist[0], ('Content-Length', clen))
self.assertEqual(headerlist[1], ('Content-Type', 'text/html'))
def test_withmessage(self):
exc = self._makeOne('abc&123')
self.failUnless('<code>abc&123</code>' in exc.app_iter[0])
class TestNotFound(unittest.TestCase):
def _makeOne(self, message):
from repoze.bfg.exceptions import NotFound
return NotFound(message)
def test_it(self):
from repoze.bfg.exceptions import ExceptionResponse
e = self._makeOne('notfound')
self.failUnless(isinstance(e, ExceptionResponse))
self.assertEqual(e.status, '404 Not Found')
class TestForbidden(unittest.TestCase):
def _makeOne(self, message):
from repoze.bfg.exceptions import Forbidden
return Forbidden(message)
def test_it(self):
from repoze.bfg.exceptions import ExceptionResponse
e = self._makeOne('unauthorized')
self.failUnless(isinstance(e, ExceptionResponse))
self.assertEqual(e.status, '401 Unauthorized')
|