do not store req as an attribute of ApacheURLRewrite - fix test
authorFlorent <florent@secondweb.fr>
Fri, 29 May 2009 12:04:23 +0200
changeset 2000 bcb9a55a89e0
parent 1999 b9a8f5995658
child 2001 c6bb482f40c6
do not store req as an attribute of ApacheURLRewrite - fix test
web/test/unittest_views_apacherewrite.py
web/views/apacherewrite.py
--- 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