--- a/test/unittest_rqlrewrite.py Thu Mar 15 14:26:12 2012 +0100
+++ b/test/unittest_rqlrewrite.py Fri Mar 16 10:29:15 2012 +0100
@@ -183,9 +183,9 @@
self.assertEqual(rqlst.as_string(),
"Any A,C,T WHERE A documented_by C?, A is Affaire "
"WITH C,T BEING (Any C,T WHERE C title T, "
- "EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', G require_group F), "
- "D eid %(A)s, C is Card, "
- "EXISTS(C in_state E, E name 'public'))")
+ "(EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', G require_group F)) "
+ "OR (EXISTS(C in_state E, E name 'public')), "
+ "D eid %(A)s, C is Card)")
def test_optional_var_4(self):
constraint1 = 'A created_by U, X documented_by A'
@@ -199,8 +199,8 @@
u'Any X,LA,Y WHERE LA? documented_by X, LA concerne Y, B eid %(C)s, '
'EXISTS(X created_by B), EXISTS(Y created_by B), '
'X is Card, Y is IN(Division, Note, Societe) '
- 'WITH LA BEING (Any LA WHERE EXISTS(A created_by B, LA documented_by A), '
- 'B eid %(D)s, LA is Affaire, EXISTS(E created_by B, LA concerne E))')
+ 'WITH LA BEING (Any LA WHERE (EXISTS(A created_by B, LA documented_by A)) OR (EXISTS(E created_by B, LA concerne E)), '
+ 'B eid %(D)s, LA is Affaire)')
def test_optional_var_inlined(self):
c1 = ('X require_permission P')
@@ -431,6 +431,33 @@
self.assertEqual(rqlst.as_string(),
u'Any A WHERE NOT EXISTS(A documented_by C, EXISTS(C owned_by B, B login "hop", B is CWUser), C is Card), A is Affaire')
+ def test_rqlexpr_multiexpr_outerjoin(self):
+ c1 = RRQLExpression('X owned_by Z, Z login "hop"', 'X')
+ c2 = RRQLExpression('X owned_by Z, Z login "hip"', 'X')
+ c3 = RRQLExpression('X owned_by Z, Z login "momo"', 'X')
+ rqlst = rqlhelper.parse('Any A WHERE A documented_by C?', annotate=False)
+ rewrite(rqlst, {('C', 'X'): (c1, c2, c3)}, {}, 'X')
+ self.assertEqual(rqlst.as_string(),
+ u'Any A WHERE A documented_by C?, A is Affaire '
+ 'WITH C BEING (Any C WHERE ((EXISTS(C owned_by B, B login "hop")) '
+ 'OR (EXISTS(C owned_by D, D login "momo"))) '
+ 'OR (EXISTS(C owned_by A, A login "hip")), C is Card)')
+
+ def test_multiple_erql_one_bad(self):
+ #: reproduce bug #2236985
+ #: (rqlrewrite fails to remove rewritten entry for unsupported constraint and then crash)
+ #:
+ #: This check a very rare code path triggered by the four condition below
+
+ # 1. c_ok introduce an ambiguity
+ c_ok = ERQLExpression('X concerne R')
+ # 2. c_bad is just plain wrong and won't be kept
+ # 3. but it declare a new variable
+ # 4. this variable require a rewrite
+ c_bad = ERQLExpression('X documented_by R, A in_state R')
+
+ rqlst = parse('Any A, R WHERE A ref R, S is Affaire')
+ rewrite(rqlst, {('A', 'X'): (c_ok, c_bad)}, {})
if __name__ == '__main__':
unittest_main()