--- a/web/test/unittest_views_apacherewrite.py Fri May 29 10:49:01 2009 +0200
+++ b/web/test/unittest_views_apacherewrite.py Fri May 29 12:04:23 2009 +0200
@@ -23,22 +23,23 @@
rules=[('/(.*)', r'/m_%(cat)s/\1')]),
]
urlrewriter = MyAppRules()
+ req = None # not used in the above rules, so keep a simple TestCase here
try:
- urlrewriter.rewrite('logilab.fr', '/whatever')
+ urlrewriter.rewrite('logilab.fr', '/whatever', req)
self.fail('redirect exception expected')
except Redirect, ex:
self.assertEquals(ex.location, 'http://www.logilab.fr/whatever')
- self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/whatever'),
+ self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/whatever', req),
'/whatever')
- self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/json/bla'),
+ self.assertEquals(urlrewriter.rewrite('www.logilab.fr', '/json/bla', req),
'/json/bla')
- self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/json/bla'),
+ self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/json/bla', req),
'/json/bla')
- self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/data/bla'),
+ self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/data/bla', req),
'/data/bla')
- self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/whatever'),
+ self.assertEquals(urlrewriter.rewrite('abcd.logilab.fr', '/whatever', req),
'/m_abcd/whatever')
- self.assertEquals(urlrewriter.rewrite('abcd.fr', '/whatever'),
+ self.assertEquals(urlrewriter.rewrite('abcd.fr', '/whatever', req),
'/whatever')
--- a/web/views/apacherewrite.py Fri May 29 10:49:01 2009 +0200
+++ b/web/views/apacherewrite.py Fri May 29 12:04:23 2009 +0200
@@ -88,9 +88,11 @@
id = 'urlrewriter'
rules = []
+ def get_rules(self, req):
+ return self.rules
+
def rewrite(self, host, path, req):
- self.req = req
- for cond in self.rules:
+ for cond in self.get_rules(req):
if cond.match(host=host, path=path):
return cond.process(path)
return path