author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Thu, 15 Mar 2012 17:54:40 +0100 | |
changeset 8313 | 386b6313de28 |
parent 6340 | 470d8e828fda |
child 8695 | 358d8bed9626 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
18 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
20 |
""" |
0 | 21 |
from logilab.common.testlib import TestCase, unittest_main |
22 |
||
23 |
from cubicweb.web.views.apacherewrite import * |
|
24 |
||
25 |
class ApacheURLRewriteTC(TestCase): |
|
26 |
||
27 |
def test(self): |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2000
diff
changeset
|
28 |
class MyAppRules(ApacheURLRewrite): |
0 | 29 |
rules = [ |
30 |
RewriteCond('logilab\.fr', match='host', |
|
31 |
rules=[('/(.*)', r'http://www.logilab.fr/\1')], |
|
32 |
action='redirect'), |
|
33 |
RewriteCond('(www)\.logilab\.fr', match='host', action='stop'), |
|
34 |
RewriteCond('/(data|json)/', match='path', action='stop'), |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2000
diff
changeset
|
35 |
RewriteCond('(?P<cat>.*)\.logilab\.fr', match='host', |
0 | 36 |
rules=[('/(.*)', r'/m_%(cat)s/\1')]), |
37 |
] |
|
38 |
urlrewriter = MyAppRules() |
|
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
39 |
req = None # not used in the above rules, so keep a simple TestCase here |
0 | 40 |
try: |
2000
bcb9a55a89e0
do not store req as an attribute of ApacheURLRewrite - fix test
Florent <florent@secondweb.fr>
parents:
1977
diff
changeset
|
41 |
urlrewriter.rewrite('logilab.fr', '/whatever', req) |
0 | 42 |
self.fail('redirect exception expected') |
43 |
except Redirect, ex: |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
44 |
self.assertEqual(ex.location, 'http://www.logilab.fr/whatever') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
45 |
self.assertEqual(urlrewriter.rewrite('www.logilab.fr', '/whatever', req), |
0 | 46 |
'/whatever') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
47 |
self.assertEqual(urlrewriter.rewrite('www.logilab.fr', '/json/bla', req), |
0 | 48 |
'/json/bla') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
49 |
self.assertEqual(urlrewriter.rewrite('abcd.logilab.fr', '/json/bla', req), |
0 | 50 |
'/json/bla') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
51 |
self.assertEqual(urlrewriter.rewrite('abcd.logilab.fr', '/data/bla', req), |
0 | 52 |
'/data/bla') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
53 |
self.assertEqual(urlrewriter.rewrite('abcd.logilab.fr', '/whatever', req), |
0 | 54 |
'/m_abcd/whatever') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
55 |
self.assertEqual(urlrewriter.rewrite('abcd.fr', '/whatever', req), |
0 | 56 |
'/whatever') |
57 |
||
58 |
||
59 |
if __name__ == '__main__': |
|
60 |
unittest_main() |