1
1
from webob.request import Request
2
2
from webob.dec import wsgify
3
from webob.exc import sys
4
3
from webob.exc import no_escape
5
4
from webob.exc import strip_tags
6
5
from webob.exc import HTTPException
7
6
from webob.exc import WSGIHTTPException
8
from webob.exc import HTTPError
9
from webob.exc import HTTPRedirection
10
from webob.exc import HTTPRedirection
11
from webob.exc import HTTPOk
12
from webob.exc import HTTPCreated
13
from webob.exc import HTTPAccepted
14
from webob.exc import HTTPNonAuthoritativeInformation
15
from webob.exc import HTTPNoContent
16
from webob.exc import HTTPResetContent
17
from webob.exc import HTTPPartialContent
18
7
from webob.exc import _HTTPMove
19
from webob.exc import HTTPMultipleChoices
20
from webob.exc import HTTPMovedPermanently
21
from webob.exc import HTTPFound
22
from webob.exc import HTTPSeeOther
23
from webob.exc import HTTPNotModified
24
from webob.exc import HTTPUseProxy
25
from webob.exc import HTTPTemporaryRedirect
26
from webob.exc import HTTPClientError
27
from webob.exc import HTTPBadRequest
28
from webob.exc import HTTPUnauthorized
29
from webob.exc import HTTPPaymentRequired
30
from webob.exc import HTTPForbidden
31
from webob.exc import HTTPNotFound
32
8
from webob.exc import HTTPMethodNotAllowed
33
from webob.exc import HTTPNotAcceptable
34
from webob.exc import HTTPProxyAuthenticationRequired
35
from webob.exc import HTTPRequestTimeout
36
from webob.exc import HTTPConflict
37
from webob.exc import HTTPGone
38
from webob.exc import HTTPLengthRequired
39
from webob.exc import HTTPPreconditionFailed
40
from webob.exc import HTTPRequestEntityTooLarge
41
from webob.exc import HTTPRequestURITooLong
42
from webob.exc import HTTPUnsupportedMediaType
43
from webob.exc import HTTPRequestRangeNotSatisfiable
44
from webob.exc import HTTPExpectationFailed
45
from webob.exc import HTTPUnprocessableEntity
46
from webob.exc import HTTPLocked
47
from webob.exc import HTTPFailedDependency
48
from webob.exc import HTTPServerError
49
from webob.exc import HTTPInternalServerError
50
from webob.exc import HTTPNotImplemented
51
from webob.exc import HTTPBadGateway
52
from webob.exc import HTTPServiceUnavailable
53
from webob.exc import HTTPGatewayTimeout
54
from webob.exc import HTTPVersionNotSupported
55
from webob.exc import HTTPInsufficientStorage
56
9
from webob.exc import HTTPExceptionMiddleware
58
10
from webob.exc import status_map
60
12
from nose.tools import eq_, ok_, assert_equal, assert_raises
106
59
start_response = object()
107
60
exc = HTTPException('testing', _response)
108
61
ok_(exc.wsgi_response is _response)
109
ok_(exc.exception is exc)
62
with warnings.catch_warnings(record=True) as w:
63
warnings.simplefilter("always")
64
assert(exc.exception is exc)
110
66
result = exc(environ, start_response)
111
67
ok_(result is result)
112
68
assert_equal(_called, [(environ, start_response)])
114
70
def test_exception_with_unicode_data():
115
req = Request.blank('/', method=u'POST')
71
req = Request.blank('/', method='POST')
116
72
res = req.get_response(method_not_allowed_app)
117
assert res.status_int == 405
73
assert res.status_code == 405
119
75
def test_WSGIHTTPException_headers():
120
76
exc = WSGIHTTPException(headers=[('Set-Cookie', 'a=1'),
270
228
def verify_response(resp, description):
271
229
assert_equal(resp.content_type, CONTENT_TYPE, description)
272
230
assert_equal(resp.content_length, len(HELLO_WORLD), description)
273
assert_equal(resp.body, '', description)
231
assert_equal(resp.body, b'', description)
275
233
req = Request.blank('/', method='HEAD')
276
234
resp1 = req.get_response(head_app)
315
275
def test_HTTPMove_add_slash_and_location():
316
276
def start_response(status, headers, exc_info=None):
319
'wsgi.url_scheme': 'HTTP',
320
'SERVER_NAME': 'localhost',
322
'REQUEST_METHOD': 'HEAD'
324
assert_raises( TypeError, _HTTPMove, location='http://example.com', add_slash=True )
278
assert_raises( TypeError, _HTTPMove, location='http://example.com',
326
281
def test_HTTPMove_call_add_slash():
327
282
def start_response(status, headers, exc_info=None):