104 req = self.request() |
104 req = self.request() |
105 pmid, rset = rewriter.rewrite(req, u'/DaLToN/JoE') |
105 pmid, rset = rewriter.rewrite(req, u'/DaLToN/JoE') |
106 self.assertEquals(len(rset), 1) |
106 self.assertEquals(len(rset), 1) |
107 self.assertEquals(rset[0][0], self.p1.eid) |
107 self.assertEquals(rset[0][0], self.p1.eid) |
108 |
108 |
|
109 def test_inheritance_precedence(self): |
|
110 RQL1 = 'Any C WHERE C is CWEType' |
|
111 RQL2 = 'Any C WHERE C is CWUser' |
|
112 |
|
113 class BaseRewriter(SchemaBasedRewriter): |
|
114 rules = [ |
|
115 (rgx('/collector(.*)'), |
|
116 rgx_action(rql=RQL1, |
|
117 form=dict(vid='baseindex')), |
|
118 ), |
|
119 ] |
|
120 class Rewriter(BaseRewriter): |
|
121 rules = [ |
|
122 (rgx('/collector/something(/?)'), |
|
123 rgx_action(rql=RQL2, |
|
124 form=dict(vid='index')), |
|
125 ), |
|
126 ] |
|
127 |
|
128 rewriter = Rewriter() |
|
129 req = self.request() |
|
130 pmid, rset = rewriter.rewrite(req, '/collector') |
|
131 self.assertEquals(rset.rql, RQL1) |
|
132 self.assertEquals(req.form, {'vid' : "baseindex"}) |
|
133 pmid, rset = rewriter.rewrite(req, '/collector/something') |
|
134 self.assertEquals(rset.rql, RQL2) |
|
135 self.assertEquals(req.form, {'vid' : "index"}) |
|
136 pmid, rset = rewriter.rewrite(req, '/collector/something/') |
|
137 self.assertEquals(req.form, {'vid' : "index"}) |
|
138 self.assertEquals(rset.rql, RQL2) |
|
139 pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/') |
|
140 self.assertEquals(rset.rql, RQL1) |
|
141 self.assertEquals(req.form, {'vid' : "baseindex"}) |
|
142 |
|
143 def test_inheritance_precedence_same_rgx(self): |
|
144 RQL1 = 'Any C WHERE C is CWEType' |
|
145 RQL2 = 'Any C WHERE C is CWUser' |
|
146 |
|
147 class BaseRewriter(SchemaBasedRewriter): |
|
148 rules = [ |
|
149 (rgx('/collector(.*)'), |
|
150 rgx_action(rql=RQL1, |
|
151 form=dict(vid='baseindex')), |
|
152 ), |
|
153 ] |
|
154 class Rewriter(BaseRewriter): |
|
155 rules = [ |
|
156 (rgx('/collector(.*)'), |
|
157 rgx_action(rql=RQL2, |
|
158 form=dict(vid='index')), |
|
159 ), |
|
160 ] |
|
161 |
|
162 rewriter = Rewriter() |
|
163 req = self.request() |
|
164 pmid, rset = rewriter.rewrite(req, '/collector') |
|
165 self.assertEquals(rset.rql, RQL2) |
|
166 self.assertEquals(req.form, {'vid' : "index"}) |
|
167 pmid, rset = rewriter.rewrite(req, '/collector/something') |
|
168 self.assertEquals(rset.rql, RQL2) |
|
169 self.assertEquals(req.form, {'vid' : "index"}) |
|
170 pmid, rset = rewriter.rewrite(req, '/collector/something/') |
|
171 self.assertEquals(req.form, {'vid' : "index"}) |
|
172 self.assertEquals(rset.rql, RQL2) |
|
173 pmid, rset = rewriter.rewrite(req, '/collector/somethingelse/') |
|
174 self.assertEquals(rset.rql, RQL2) |
|
175 self.assertEquals(req.form, {'vid' : "index"}) |
109 |
176 |
110 |
177 |
111 if __name__ == '__main__': |
178 if __name__ == '__main__': |
112 unittest_main() |
179 unittest_main() |