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
|
import webtest
from webtest.debugapp import debug_app
def raises(exc, func, *args, **kw):
try:
func(*args, **kw)
except exc:
pass
else:
raise AssertionError(
"Expected exception %s from %s"
% (exc, func))
def test_testing():
app = webtest.TestApp(debug_app)
res = app.get('/')
assert res.status_int == 200
assert res.headers['content-type'] == 'text/plain'
assert res.content_type == 'text/plain'
raises(Exception, app.get, '/?error=t')
raises(webtest.AppError, app.get, '/?status=404%20Not%20Found')
app.get('/?status=404%20Not%20Found', status=404)
raises(webtest.AppError, app.get, '/', status=404)
res = app.get('/?status=303%20Redirect&header-location=/foo')
assert res.status_int == 303
print res.location
assert res.location == 'http://localhost/foo'
assert res.headers['location'] == '/foo'
res = res.follow()
assert res.request.url == 'http://localhost/foo'
class FakeDict(object):
def items(self):
return [('a', '10'), ('a', '20')]
res = app.post('/params', params=FakeDict())
|