Move CWSchemaTC to RQLExpressionTC
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Fri, 10 May 2019 16:07:32 +0200
changeset 12597 7882ad333954
parent 12596 48ea46ad80da
child 12600 0f33639d305b
Move CWSchemaTC to RQLExpressionTC The test actually doesn't require a cubicweb schema, except for testing EmailAdress which is out of scope of the test (testing RQLExpression.transform_has_permission()). Just move the test in existing RQLExpressionTC inheriting from TestCase and rename the tests to be more explicit.
cubicweb/test/unittest_schema.py
--- a/cubicweb/test/unittest_schema.py	Wed Apr 17 16:41:41 2019 +0200
+++ b/cubicweb/test/unittest_schema.py	Fri May 10 16:07:32 2019 +0200
@@ -457,6 +457,20 @@
         self.assertNotEqual(ERQLExpression('X is CWUser', 'X', 0),
                             ERQLExpression('X is CWGroup', 'X', 0))
 
+    def test_has_update_permission(self):
+        expr = ERQLExpression('P use_email X, U has_update_permission P')
+        rql, found, keyarg = expr.transform_has_permission()
+        self.assertEqual(rql, 'Any X,P WHERE P use_email X, X eid %(x)s')
+        self.assertEqual(found, [(u'update', 1)])
+        self.assertEqual(keyarg, None)
+
+    def test_expression(self):
+        expr = ERQLExpression('U use_email X')
+        rql, found, keyarg = expr.transform_has_permission()
+        self.assertEqual(rql, 'Any X WHERE EXISTS(U use_email X, X eid %(x)s, U eid %(u)s)')
+        self.assertEqual(found, None)
+        self.assertEqual(keyarg, None)
+
 
 class GuessRrqlExprMainVarsTC(TestCase):
     def test_exists(self):
@@ -575,32 +589,5 @@
                                          for r, role in schema[etype].composite_rdef_roles]))
 
 
-class CWShemaTC(CubicWebTC):
-
-    def test_transform_has_permission_match(self):
-        with self.admin_access.repo_cnx() as cnx:
-            eschema = cnx.vreg.schema['EmailAddress']
-            rql_exprs = eschema.get_rqlexprs('update')
-            self.assertEqual(len(rql_exprs), 1)
-            self.assertEqual(rql_exprs[0].expression,
-                             'P use_email X, U has_update_permission P')
-            rql, found, keyarg = rql_exprs[0].transform_has_permission()
-            self.assertEqual(rql, 'Any X,P WHERE P use_email X, X eid %(x)s')
-            self.assertEqual(found, [(u'update', 1)])
-            self.assertEqual(keyarg, None)
-
-    def test_transform_has_permission_no_match(self):
-        with self.admin_access.repo_cnx() as cnx:
-            eschema = cnx.vreg.schema['EmailAddress']
-            rql_exprs = eschema.get_rqlexprs('read')
-            self.assertEqual(len(rql_exprs), 1)
-            self.assertEqual(rql_exprs[0].expression,
-                             'U use_email X')
-            rql, found, keyarg = rql_exprs[0].transform_has_permission()
-            self.assertEqual(rql, 'Any X WHERE EXISTS(U use_email X, X eid %(x)s, U eid %(u)s)')
-            self.assertEqual(found, None)
-            self.assertEqual(keyarg, None)
-
-
 if __name__ == '__main__':
     unittest_main()