author | Denis Laxalde <denis.laxalde@logilab.fr> |
Wed, 29 Apr 2015 11:39:35 +0200 | |
changeset 11563 | f9473eb6a8a9 |
parent 11556 | 1eeba41a2e95 |
child 11568 | a9940c6cd693 |
permissions | -rw-r--r-- |
11556
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
1 |
from pyramid_cubicweb.tests import PyramidCWTest |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
2 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
3 |
from cubicweb.view import View |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
4 |
from cubicweb.web import Redirect |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
5 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
6 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
7 |
class Redirector(View): |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
8 |
__regid__ = 'redirector' |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
9 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
10 |
def call(self, rset=None): |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
11 |
self._cw.set_header('Cache-Control', 'no-cache') |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
12 |
raise Redirect('http://example.org') |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
13 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
14 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
15 |
class CoreTest(PyramidCWTest): |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
16 |
anonymous_allowed = True |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
17 |
|
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
18 |
def test_cw_to_pyramid_copy_headers_on_redirect(self): |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
19 |
self.vreg.register(Redirector) |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
20 |
try: |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
21 |
res = self.webapp.get('/?vid=redirector', expect_errors=True) |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
22 |
self.assertEqual(res.status_int, 303) |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
23 |
self.assertEqual(res.headers['Cache-Control'], 'no-cache') |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
24 |
finally: |
1eeba41a2e95
On exceptions from CW, copy headers
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
25 |
self.vreg.unregister(Redirector) |