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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
import unittest
class WSGIAppTests(unittest.TestCase):
def _callFUT(self, app):
from repoze.bfg.wsgi import wsgiapp
return wsgiapp(app)
def test_decorator(self):
context = DummyContext()
request = DummyRequest()
decorator = self._callFUT(dummyapp)
response = decorator(context, request)
self.assertEqual(response, dummyapp)
class TestNotFound(unittest.TestCase):
def _getTargetClass(self):
from repoze.bfg.wsgi import NotFound
return NotFound
def _makeOne(self):
return self._getTargetClass()()
def test_no_message(self):
environ = {}
L = []
def start_response(status, headers):
L.append((status, headers))
app = self._makeOne()
result = app(environ, start_response)
self.assertEqual(len(result), 1)
self.failUnless('404 Not Found' in result[0])
self.assertEqual(L[0][0], '404 Not Found')
self.assertEqual(L[0][1], [('Content-Length', len(result[0])),
('Content-Type', 'text/html')])
def test_with_message(self):
environ = {'message':'<hi!>'}
L = []
def start_response(status, headers):
L.append((status, headers))
app = self._makeOne()
result = app(environ, start_response)
self.assertEqual(len(result), 1)
self.failUnless('404 Not Found' in result[0])
self.failUnless('<hi!>' in result[0])
self.assertEqual(L[0][0], '404 Not Found')
self.assertEqual(L[0][1], [('Content-Length', len(result[0])),
('Content-Type', 'text/html')])
class TestUnauthorized(unittest.TestCase):
def _getTargetClass(self):
from repoze.bfg.wsgi import Unauthorized
return Unauthorized
def _makeOne(self):
return self._getTargetClass()()
def test_no_message(self):
environ = {}
L = []
def start_response(status, headers):
L.append((status, headers))
app = self._makeOne()
result = app(environ, start_response)
self.assertEqual(len(result), 1)
self.failUnless('401 Unauthorized' in result[0])
self.assertEqual(L[0][0], '401 Unauthorized')
self.assertEqual(L[0][1], [('Content-Length', len(result[0])),
('Content-Type', 'text/html')])
def test_with_message(self):
environ = {'message':'<hi!>'}
L = []
def start_response(status, headers):
L.append((status, headers))
app = self._makeOne()
result = app(environ, start_response)
self.assertEqual(len(result), 1)
self.failUnless('401 Unauthorized' in result[0])
self.failUnless('<hi!>' in result[0])
self.assertEqual(L[0][0], '401 Unauthorized')
self.assertEqual(L[0][1], [('Content-Length', len(result[0])),
('Content-Type', 'text/html')])
def dummyapp(environ, start_response):
""" """
class DummyContext:
pass
class DummyRequest:
def get_response(self, application):
return application
|