1
# -*- coding: utf-8 -*-
3
from webob import Request, Response
4
from tests.compat import unittest
5
from webtest.compat import to_bytes
7
def application(environ, start_response):
9
if req.path_info == '/redirect':
10
req.path_info = '/path'
12
resp.status = '302 Found'
13
resp.location = req.path
16
resp.body = to_bytes('<html><body><a href="%s">link</a></body></html>' % req.path)
17
return resp(environ, start_response)
19
class TestScriptName(unittest.TestCase):
21
def test_script_name(self):
22
app = webtest.TestApp(application)
24
resp = app.get('/script', extra_environ={'SCRIPT_NAME':'/script'})
25
resp.mustcontain('href="/script"')
27
resp = app.get('/script/redirect', extra_environ={'SCRIPT_NAME':'/script'})
28
self.assertEqual(resp.status_int, 302)
29
self.assertEqual(resp.location, 'http://localhost/script/path', resp.location)
31
resp = resp.follow(extra_environ={'SCRIPT_NAME':'/script'})
32
resp.mustcontain('href="/script/path"')
33
resp = resp.click('link')
34
resp.mustcontain('href="/script/path"')
36
def test_app_script_name(self):
37
app = webtest.TestApp(application, extra_environ={'SCRIPT_NAME':'/script'})
38
resp = app.get('/script/redirect')
39
self.assertEqual(resp.status_int, 302)
40
self.assertEqual(resp.location, 'http://localhost/script/path', resp.location)
43
resp.mustcontain('href="/script/path"')
44
resp = resp.click('link')
45
resp.mustcontain('href="/script/path"')
47
def test_script_name_doesnt_match(self):
48
app = webtest.TestApp(application)
49
resp = app.get('/path', extra_environ={'SCRIPT_NAME':'/script'})
50
resp.mustcontain('href="/script/path"')