@@ -94,10 +94,10 @@ def test_call_with_nonexception(self):
94
94
result = self ._callFUT (None , request )
95
95
self .assertEqual (result , context )
96
96
97
- class Test_no_escape (unittest .TestCase ):
97
+ class Test__no_escape (unittest .TestCase ):
98
98
def _callFUT (self , val ):
99
- from pyramid .exceptions import no_escape
100
- return no_escape (val )
99
+ from pyramid .exceptions import _no_escape
100
+ return _no_escape (val )
101
101
102
102
def test_null (self ):
103
103
self .assertEqual (self ._callFUT (None ), '' )
@@ -112,6 +112,103 @@ def __unicode__(self):
112
112
duo = DummyUnicodeObject ()
113
113
self .assertEqual (self ._callFUT (duo ), u'42' )
114
114
115
+ class TestWSGIHTTPException (unittest .TestCase ):
116
+ def _getTargetClass (self ):
117
+ from pyramid .exceptions import WSGIHTTPException
118
+ return WSGIHTTPException
119
+
120
+ def _makeOne (self , * arg , ** kw ):
121
+ cls = self ._getTargetClass ()
122
+ return cls (* arg , ** kw )
123
+
124
+ def test_ctor_sets_detail (self ):
125
+ exc = self ._makeOne ('message' )
126
+ self .assertEqual (exc .detail , 'message' )
127
+
128
+ def test_ctor_sets_comment (self ):
129
+ exc = self ._makeOne (comment = 'comment' )
130
+ self .assertEqual (exc .comment , 'comment' )
131
+
132
+ def test_ctor_calls_Exception_ctor (self ):
133
+ exc = self ._makeOne ('message' )
134
+ self .assertEqual (exc .message , 'message' )
135
+
136
+ def test_ctor_calls_Response_ctor (self ):
137
+ exc = self ._makeOne ('message' )
138
+ self .assertEqual (exc .status , 'None None' )
139
+
140
+ def test_ctor_extends_headers (self ):
141
+ exc = self ._makeOne (headers = [('X-Foo' , 'foo' )])
142
+ self .assertEqual (exc .headers .get ('X-Foo' ), 'foo' )
143
+
144
+ def test_ctor_sets_body_template_obj (self ):
145
+ exc = self ._makeOne (body_template = '${foo}' )
146
+ self .assertEqual (
147
+ exc .body_template_obj .substitute ({'foo' :'foo' }), 'foo' )
148
+
149
+ def test_ctor_with_empty_body (self ):
150
+ cls = self ._getTargetClass ()
151
+ class Subclass (cls ):
152
+ empty_body = True
153
+ exc = Subclass ()
154
+ self .assertEqual (exc .content_type , None )
155
+ self .assertEqual (exc .content_length , None )
156
+
157
+ def test_ctor_with_body_doesnt_set_default_app_iter (self ):
158
+ exc = self ._makeOne (body = '123' )
159
+ self .assertEqual (exc .app_iter , ['123' ])
160
+
161
+ def test_ctor_with_unicode_body_doesnt_set_default_app_iter (self ):
162
+ exc = self ._makeOne (unicode_body = u'123' )
163
+ self .assertEqual (exc .app_iter , ['123' ])
164
+
165
+ def test_ctor_with_app_iter_doesnt_set_default_app_iter (self ):
166
+ exc = self ._makeOne (app_iter = ['123' ])
167
+ self .assertEqual (exc .app_iter , ['123' ])
168
+
169
+ def test_ctor_with_body_sets_default_app_iter_html (self ):
170
+ cls = self ._getTargetClass ()
171
+ class Subclass (cls ):
172
+ code = '200'
173
+ title = 'OK'
174
+ explanation = 'explanation'
175
+ exc = Subclass ('detail' )
176
+ body = list (exc .app_iter )[0 ]
177
+ self .assertTrue (body .startswith ('<html' ))
178
+ self .assertTrue ('200 OK' in body )
179
+ self .assertTrue ('explanation' in body )
180
+ self .assertTrue ('detail' in body )
181
+
182
+ def test_ctor_with_body_sets_default_app_iter_text (self ):
183
+ cls = self ._getTargetClass ()
184
+ class Subclass (cls ):
185
+ code = '200'
186
+ title = 'OK'
187
+ explanation = 'explanation'
188
+ exc = Subclass ('detail' )
189
+ exc .content_type = 'text/plain'
190
+ body = list (exc .app_iter )[0 ]
191
+ self .assertEqual (body , '200 OK\n \n explanation\n \n \n detail\n \n ' )
192
+
193
+ def test__str__detail (self ):
194
+ exc = self ._makeOne ()
195
+ exc .detail = 'abc'
196
+ self .assertEqual (str (exc ), 'abc' )
197
+
198
+ def test__str__explanation (self ):
199
+ exc = self ._makeOne ()
200
+ exc .explanation = 'def'
201
+ self .assertEqual (str (exc ), 'def' )
202
+
203
+ def test_wsgi_response (self ):
204
+ exc = self ._makeOne ()
205
+ self .assertTrue (exc is exc .wsgi_response )
206
+
207
+ def test_exception (self ):
208
+ exc = self ._makeOne ()
209
+ self .assertTrue (exc is exc .exception )
210
+
211
+
115
212
class DummyRequest (object ):
116
213
exception = None
117
214
0 commit comments