author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 28 May 2009 09:20:07 +0200 | |
changeset 1977 | 606923dff11b |
parent 0 | b97547f5f1fa |
child 2000 | bcb9a55a89e0 |
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): |
|
15 |
class MyAppRules(ApacheURLRewrite): |
|
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'), |
|
22 |
RewriteCond('(?P<cat>.*)\.logilab\.fr', match='host', |
|
23 |
rules=[('/(.*)', r'/m_%(cat)s/\1')]), |
|
24 |
] |
|
25 |
urlrewriter = MyAppRules() |
|
26 |
try: |
|
27 |
urlrewriter.rewrite('logilab.fr', '/whatever') |
|
28 |
self.fail('redirect exception expected') |
|
29 |
except Redirect, ex: |
|
30 |
self.assertEquals(ex.location, 'http://www.logilab.fr/whatever') |
|
31 |
self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/whatever'), |
|
32 |
'/whatever') |
|
33 |
self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/json/bla'), |
|
34 |
'/json/bla') |
|
35 |
self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/json/bla'), |
|
36 |
'/json/bla') |
|
37 |
self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/data/bla'), |
|
38 |
'/data/bla') |
|
39 |
self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/whatever'), |
|
40 |
'/m_abcd/whatever') |
|
41 |
self.assertEquals(urlrewriter.rewrite('abcd.fr', '/whatever'), |
|
42 |
'/whatever') |
|
43 |
||
44 |
||
45 |
if __name__ == '__main__': |
|
46 |
unittest_main() |