[test] add some tests for rql's add_type_restriction
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Nov 2011 18:43:01 +0100
changeset 8075 f57ffbfe90fe
parent 8074 a7f76e322659
child 8078 b4e1ef549bfa
[test] add some tests for rql's add_type_restriction
server/test/unittest_security.py
--- a/server/test/unittest_security.py	Wed Nov 09 18:41:12 2011 +0100
+++ b/server/test/unittest_security.py	Wed Nov 09 18:43:01 2011 +0100
@@ -570,6 +570,26 @@
         self.assertEqual(names, sorted(names, key=lambda x: x.lower()))
         cnx.close()
 
+    def test_restrict_is_instance_ok(self):
+        from rql import RQLException
+        rset = self.execute('Any X WHERE X is_instance_of BaseTransition')
+        rqlst = rset.syntax_tree()
+        select = rqlst.children[0]
+        x = select.get_selected_variables().next()
+        self.assertRaises(RQLException, select.add_type_restriction,
+                          x.variable, 'CWUser')
+        select.add_type_restriction(x.variable, 'BaseTransition')
+        select.add_type_restriction(x.variable, 'WorkflowTransition')
+        self.assertEqual(rqlst.as_string(), 'Any X WHERE X is_instance_of WorkflowTransition')
+
+    def test_restrict_is_instance_no_supported(self):
+        rset = self.execute('Any X WHERE X is_instance_of IN(CWUser, CWGroup)')
+        rqlst = rset.syntax_tree()
+        select = rqlst.children[0]
+        x = select.get_selected_variables().next()
+        self.assertRaises(NotImplementedError, select.add_type_restriction,
+                          x.variable, 'WorkflowTransition')
+
     def test_in_state_without_update_perm(self):
         """check a user change in_state without having update permission on the
         subject