@@ -138,7 +138,9 @@ def test_ctor_with_app_iter_doesnt_set_default_app_iter(self):
138
138
def test_ctor_with_body_sets_default_app_iter_html (self ):
139
139
cls = self ._getTargetSubclass ()
140
140
exc = cls ('detail' )
141
- body = list (exc .app_iter )[0 ]
141
+ environ = _makeEnviron ()
142
+ start_response = DummyStartResponse ()
143
+ body = list (exc (environ , start_response ))[0 ]
142
144
self .assertTrue (body .startswith ('<html' ))
143
145
self .assertTrue ('200 OK' in body )
144
146
self .assertTrue ('explanation' in body )
@@ -148,7 +150,9 @@ def test_ctor_with_body_sets_default_app_iter_text(self):
148
150
cls = self ._getTargetSubclass ()
149
151
exc = cls ('detail' )
150
152
exc .content_type = 'text/plain'
151
- body = list (exc .app_iter )[0 ]
153
+ environ = _makeEnviron ()
154
+ start_response = DummyStartResponse ()
155
+ body = list (exc (environ , start_response ))[0 ]
152
156
self .assertEqual (body , '200 OK\n \n explanation\n \n \n detail\n \n ' )
153
157
154
158
def test__str__detail (self ):
@@ -169,59 +173,69 @@ def test_exception(self):
169
173
exc = self ._makeOne ()
170
174
self .assertTrue (exc is exc .exception )
171
175
176
+ def test__calls_start_response (self ):
177
+ cls = self ._getTargetSubclass ()
178
+ exc = cls ()
179
+ exc .content_type = 'text/plain'
180
+ environ = _makeEnviron ()
181
+ start_response = DummyStartResponse ()
182
+ exc (environ , start_response )
183
+ self .assertTrue (start_response .headerlist )
184
+ self .assertEqual (start_response .status , '200 OK' )
185
+
172
186
def test__default_app_iter_no_comment_plain (self ):
173
187
cls = self ._getTargetSubclass ()
174
188
exc = cls ()
175
189
exc .content_type = 'text/plain'
176
- body = list (exc ._default_app_iter ())[0 ]
190
+ environ = _makeEnviron ()
191
+ start_response = DummyStartResponse ()
192
+ body = list (exc (environ , start_response ))[0 ]
177
193
self .assertEqual (body , '200 OK\n \n explanation\n \n \n \n \n ' )
178
194
179
195
def test__default_app_iter_with_comment_plain (self ):
180
196
cls = self ._getTargetSubclass ()
181
197
exc = cls (comment = 'comment' )
182
198
exc .content_type = 'text/plain'
183
- body = list (exc ._default_app_iter ())[0 ]
199
+ environ = _makeEnviron ()
200
+ start_response = DummyStartResponse ()
201
+ body = list (exc (environ , start_response ))[0 ]
184
202
self .assertEqual (body , '200 OK\n \n explanation\n \n \n \n comment\n ' )
185
203
186
204
def test__default_app_iter_no_comment_html (self ):
187
205
cls = self ._getTargetSubclass ()
188
206
exc = cls ()
189
207
exc .content_type = 'text/html'
190
- body = list (exc ._default_app_iter ())[0 ]
208
+ environ = _makeEnviron ()
209
+ start_response = DummyStartResponse ()
210
+ body = list (exc (environ , start_response ))[0 ]
191
211
self .assertFalse ('<!-- ' in body )
192
212
193
213
def test__default_app_iter_with_comment_html (self ):
194
214
cls = self ._getTargetSubclass ()
195
215
exc = cls (comment = 'comment & comment' )
196
216
exc .content_type = 'text/html'
197
- body = list (exc ._default_app_iter ())[0 ]
217
+ environ = _makeEnviron ()
218
+ start_response = DummyStartResponse ()
219
+ body = list (exc (environ , start_response ))[0 ]
198
220
self .assertTrue ('<!-- comment & comment -->' in body )
199
221
200
- def test_custom_body_template_no_environ (self ):
222
+ def test_custom_body_template (self ):
201
223
cls = self ._getTargetSubclass ()
202
- exc = cls (body_template = '${location}' , location = 'foo ' )
224
+ exc = cls (body_template = '${REQUEST_METHOD} ' )
203
225
exc .content_type = 'text/plain'
204
- body = list (exc ._default_app_iter ())[0 ]
205
- self .assertEqual (body , '200 OK\n \n foo' )
206
-
207
- def test_custom_body_template_with_environ (self ):
208
- cls = self ._getTargetSubclass ()
209
- from pyramid .request import Request
210
- request = Request .blank ('/' )
211
- exc = cls (body_template = '${REQUEST_METHOD}' , request = request )
212
- exc .content_type = 'text/plain'
213
- body = list (exc ._default_app_iter ())[0 ]
226
+ environ = _makeEnviron ()
227
+ start_response = DummyStartResponse ()
228
+ body = list (exc (environ , start_response ))[0 ]
214
229
self .assertEqual (body , '200 OK\n \n GET' )
215
230
216
231
def test_body_template_unicode (self ):
217
- from pyramid .request import Request
218
232
cls = self ._getTargetSubclass ()
219
233
la = unicode ('/La Pe\xc3 \xb1 a' , 'utf-8' )
220
- request = Request .blank ('/' )
221
- request .environ ['unicodeval' ] = la
222
- exc = cls (body_template = '${unicodeval}' , request = request )
234
+ environ = _makeEnviron (unicodeval = la )
235
+ exc = cls (body_template = '${unicodeval}' )
223
236
exc .content_type = 'text/plain'
224
- body = list (exc ._default_app_iter ())[0 ]
237
+ start_response = DummyStartResponse ()
238
+ body = list (exc (environ , start_response ))[0 ]
225
239
self .assertEqual (body , '200 OK\n \n /La Pe\xc3 \xb1 a' )
226
240
227
241
class TestRenderAllExceptionsWithoutArguments (unittest .TestCase ):
@@ -230,9 +244,11 @@ def _doit(self, content_type):
230
244
L = []
231
245
self .assertTrue (status_map )
232
246
for v in status_map .values ():
247
+ environ = _makeEnviron ()
248
+ start_response = DummyStartResponse ()
233
249
exc = v ()
234
250
exc .content_type = content_type
235
- result = list (exc . app_iter )[0 ]
251
+ result = list (exc ( environ , start_response ) )[0 ]
236
252
if exc .empty_body :
237
253
self .assertEqual (result , '' )
238
254
else :
@@ -275,3 +291,16 @@ def test_it_result_passed(self):
275
291
class DummyRequest (object ):
276
292
exception = None
277
293
294
+ class DummyStartResponse (object ):
295
+ def __call__ (self , status , headerlist ):
296
+ self .status = status
297
+ self .headerlist = headerlist
298
+
299
+ def _makeEnviron (** kw ):
300
+ environ = {'REQUEST_METHOD' :'GET' ,
301
+ 'wsgi.url_scheme' :'http' ,
302
+ 'SERVER_NAME' :'localhost' ,
303
+ 'SERVER_PORT' :'80' }
304
+ environ .update (kw )
305
+ return environ
306
+
0 commit comments