author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 19:23:09 +0200 | |
changeset 3447 | 0a0f8df4a2f7 |
parent 2172 | cf8f9180e63e |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
7 |
""" |
0 | 8 |
from logilab.common.testlib import TestCase, unittest_main |
9 |
||
10 |
from cubicweb.web.views.apacherewrite import * |
|
11 |
||
12 |
class ApacheURLRewriteTC(TestCase): |
|
13 |
||
14 |
def test(self): |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2000
diff
changeset
|
15 |
class MyAppRules(ApacheURLRewrite): |
0 | 16 |
rules = [ |
17 |
RewriteCond('logilab\.fr', match='host', |
|
18 |
rules=[('/(.*)', r'http://www.logilab.fr/\1')], |
|
19 |
action='redirect'), |
|
20 |
RewriteCond('(www)\.logilab\.fr', match='host', action='stop'), |
|
21 |
RewriteCond('/(data|json)/', match='path', action='stop'), |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2000
diff
changeset
|
22 |
RewriteCond('(?P<cat>.*)\.logilab\.fr', match='host', |
0 | 23 |
rules=[('/(.*)', r'/m_%(cat)s/\1')]), |
24 |
] |
|
25 |
urlrewriter = MyAppRules() |
|
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
26 |
req = None # not used in the above rules, so keep a simple TestCase here |
0 | 27 |
try: |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
28 |
urlrewriter.rewrite('logilab.fr', '/whatever', req) |
0 | 29 |
self.fail('redirect exception expected') |
30 |
except Redirect, ex: |
|
31 |
self.assertEquals(ex.location, 'http://www.logilab.fr/whatever') |
|
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
32 |
self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/whatever', req), |
0 | 33 |
'/whatever') |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
34 |
self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/json/bla', req), |
0 | 35 |
'/json/bla') |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
36 |
self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/json/bla', req), |
0 | 37 |
'/json/bla') |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
38 |
self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/data/bla', req), |
0 | 39 |
'/data/bla') |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
40 |
self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/whatever', req), |
0 | 41 |
'/m_abcd/whatever') |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
42 |
self.assertEquals(urlrewriter.rewrite('abcd.fr', '/whatever', req), |
0 | 43 |
'/whatever') |
44 |
||
45 |
||
46 |
if __name__ == '__main__': |
|
47 |
unittest_main() |