--- a/test/unittest_selectors.py Mon Jul 04 16:46:29 2011 +0200
+++ b/test/unittest_selectors.py Tue Jul 05 10:52:34 2011 +0200
@@ -26,7 +26,7 @@
from cubicweb.appobject import Selector, AndSelector, OrSelector
from cubicweb.selectors import (is_instance, adaptable, match_user_groups,
multi_lines_rset, score_entity, is_in_state,
- on_transition, rql_condition)
+ on_transition, rql_condition, relation_possible)
from cubicweb.web import action
@@ -144,35 +144,6 @@
self.assertEqual(selector(None), 0)
-class IsInStateSelectorTC(CubicWebTC):
- def setup_database(self):
- wf = self.shell().add_workflow("testwf", 'StateFull', default=True)
- initial = wf.add_state(u'initial', initial=True)
- final = wf.add_state(u'final')
- wf.add_transition(u'forward', (initial,), final)
-
- def test_initial_state(self):
- req = self.request()
- entity = req.create_entity('StateFull')
- selector = is_in_state(u'initial')
- self.commit()
- score = selector(entity.__class__, None, entity=entity)
- self.assertEqual(score, 1)
-
- def test_final_state(self):
- req = self.request()
- entity = req.create_entity('StateFull')
- selector = is_in_state(u'initial')
- self.commit()
- entity.cw_adapt_to('IWorkflowable').fire_transition(u'forward')
- self.commit()
- score = selector(entity.__class__, None, entity=entity)
- self.assertEqual(score, 0)
- selector = is_in_state(u'final')
- score = selector(entity.__class__, None, entity=entity)
- self.assertEqual(score, 1)
-
-
class ImplementsSelectorTC(CubicWebTC):
def test_etype_priority(self):
req = self.request()
@@ -319,6 +290,27 @@
self.assertEqual(selector(None, self.req, rset=self.rset), 0)
+class RelationPossibleTC(CubicWebTC):
+
+ def test_rqlst_1(self):
+ req = self.request()
+ selector = relation_possible('in_group')
+ select = self.vreg.parse(req, 'Any X WHERE X is CWUser').children[0]
+ score = selector(None, req, rset=1,
+ select=select, filtered_variable=select.defined_vars['X'])
+ self.assertEqual(score, 1)
+
+ def test_rqlst_2(self):
+ req = self.request()
+ selector = relation_possible('in_group')
+ select = self.vreg.parse(req, 'Any 1, COUNT(X) WHERE X is CWUser, X creation_date XD, '
+ 'Y creation_date YD, Y is CWGroup '
+ 'HAVING DAY(XD)=DAY(YD)').children[0]
+ score = selector(None, req, rset=1,
+ select=select, filtered_variable=select.defined_vars['X'])
+ self.assertEqual(score, 1)
+
+
class MatchUserGroupsTC(CubicWebTC):
def test_owners_group(self):
"""tests usage of 'owners' group with match_user_group"""