~noskcaj/ubuntu/vivid/webtest/merge2

« back to all changes in this revision

Viewing changes to tests/test_script_name.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-10-02 19:37:14 UTC
  • mfrom: (1.2.1) (14.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20131002193714-t0na13dhqrskvvff
Tags: 2.0.9-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
  - bump minimum required Python version to 2.6
  - add python-six, python-waitress and python-bs4 to Depends
  - remove python-pastescript from Depends
  - remove python-simplejson and python-beautifulsoup from Recommends
  - add python-pyquery to Recommends
* Update debian/watch file to check for zip files
* Standards-Version bumped to 3.9.4 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
import webtest
3
 
from webob import Request, Response
4
 
from tests.compat import unittest
5
 
from webtest.compat import to_bytes
6
 
 
7
 
def application(environ, start_response):
8
 
    req = Request(environ)
9
 
    if req.path_info == '/redirect':
10
 
        req.path_info = '/path'
11
 
        resp = Response()
12
 
        resp.status = '302 Found'
13
 
        resp.location = req.path
14
 
    else:
15
 
        resp = Response()
16
 
        resp.body = to_bytes('<html><body><a href="%s">link</a></body></html>' % req.path)
17
 
    return resp(environ, start_response)
18
 
 
19
 
class TestScriptName(unittest.TestCase):
20
 
 
21
 
    def test_script_name(self):
22
 
        app = webtest.TestApp(application)
23
 
 
24
 
        resp = app.get('/script', extra_environ={'SCRIPT_NAME':'/script'})
25
 
        resp.mustcontain('href="/script"')
26
 
 
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)
30
 
 
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"')
35
 
 
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)
41
 
 
42
 
        resp = resp.follow()
43
 
        resp.mustcontain('href="/script/path"')
44
 
        resp = resp.click('link')
45
 
        resp.mustcontain('href="/script/path"')
46
 
 
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"')
51