--- a/web/test/unittest_urlrewrite.py Thu Sep 10 14:10:58 2009 +0200
+++ b/web/test/unittest_urlrewrite.py Thu Sep 10 14:16:10 2009 +0200
@@ -106,6 +106,73 @@
self.assertEquals(len(rset), 1)
self.assertEquals(rset[0][0], self.p1.eid)
+ def test_inheritance_precedence(self):
+ RQL1 = 'Any C WHERE C is CWEType'
+ RQL2 = 'Any C WHERE C is CWUser'
+
+ class BaseRewriter(SchemaBasedRewriter):
+ rules = [
+ (rgx('/collector(.*)'),
+ rgx_action(rql=RQL1,
+ form=dict(vid='baseindex')),
+ ),
+ ]
+ class Rewriter(BaseRewriter):
+ rules = [
+ (rgx('/collector/something(/?)'),
+ rgx_action(rql=RQL2,
+ form=dict(vid='index')),
+ ),
+ ]
+
+ rewriter = Rewriter()
+ req = self.request()
+ pmid, rset = rewriter.rewrite(req, '/collector')
+ self.assertEquals(rset.rql, RQL1)
+ self.assertEquals(req.form, {'vid' : "baseindex"})
+ pmid, rset = rewriter.rewrite(req, '/collector/something')
+ self.assertEquals(rset.rql, RQL2)
+ self.assertEquals(req.form, {'vid' : "index"})
+ pmid, rset = rewriter.rewrite(req, '/collector/something/')
+ self.assertEquals(req.form, {'vid' : "index"})
+ self.assertEquals(rset.rql, RQL2)
+ pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/')
+ self.assertEquals(rset.rql, RQL1)
+ self.assertEquals(req.form, {'vid' : "baseindex"})
+
+ def test_inheritance_precedence_same_rgx(self):
+ RQL1 = 'Any C WHERE C is CWEType'
+ RQL2 = 'Any C WHERE C is CWUser'
+
+ class BaseRewriter(SchemaBasedRewriter):
+ rules = [
+ (rgx('/collector(.*)'),
+ rgx_action(rql=RQL1,
+ form=dict(vid='baseindex')),
+ ),
+ ]
+ class Rewriter(BaseRewriter):
+ rules = [
+ (rgx('/collector(.*)'),
+ rgx_action(rql=RQL2,
+ form=dict(vid='index')),
+ ),
+ ]
+
+ rewriter = Rewriter()
+ req = self.request()
+ pmid, rset = rewriter.rewrite(req, '/collector')
+ self.assertEquals(rset.rql, RQL2)
+ self.assertEquals(req.form, {'vid' : "index"})
+ pmid, rset = rewriter.rewrite(req, '/collector/something')
+ self.assertEquals(rset.rql, RQL2)
+ self.assertEquals(req.form, {'vid' : "index"})
+ pmid, rset = rewriter.rewrite(req, '/collector/something/')
+ self.assertEquals(req.form, {'vid' : "index"})
+ self.assertEquals(rset.rql, RQL2)
+ pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/')
+ self.assertEquals(rset.rql, RQL2)
+ self.assertEquals(req.form, {'vid' : "index"})
if __name__ == '__main__':