use cubicweb test api stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 15 Apr 2010 18:30:30 +0200
branchstable
changeset 108 6adea1a62e97
parent 107 d7b05aec0868
child 109 9cc78cbf5813
use cubicweb test api
test/data/schema.py
test/unittest_classification.py
test/unittest_descendant_of.py
test/unittest_security.py
--- a/test/data/schema.py	Thu Apr 15 18:30:19 2010 +0200
+++ b/test/data/schema.py	Thu Apr 15 18:30:30 2010 +0200
@@ -2,4 +2,4 @@
 
 class applied_to(RelationDefinition):
     subject = 'Keyword'
-    object = ('CWGroup', 'CWUser')
+    object = ('CWUser', 'CWGroup')
--- a/test/unittest_classification.py	Thu Apr 15 18:30:19 2010 +0200
+++ b/test/unittest_classification.py	Thu Apr 15 18:30:30 2010 +0200
@@ -6,39 +6,46 @@
 class ClassificationHooksTC(CubicWebTC):
 
     def setup_database(self):
-        self.execute('INSERT Classification C: C name "classif1", C classifies ET WHERE ET name "CWGroup"')
-        self.execute('INSERT Classification C: C name "classif2", C classifies ET WHERE ET name "CWUser"')
-        self.kw1 = self.execute('INSERT Keyword K: K name "kwgroup", K included_in C WHERE C name "classif1"')[0][0]
-        self.kw2 = self.execute('INSERT Keyword K: K name "kwuser", K included_in C WHERE C name "classif2"')[0][0]
-        #self.zone = self.add_entity('Zone', name=u"Paris")
+        req = self.request()
+        # classification for CWGroup
+        cwgroup = self.execute('Any U WHERE U is ET, U name "CWGroup"').get_entity(0,0)
+        self.classif1 = self.request().create_entity('Classification', name=u"classif1", classifies=cwgroup)
+        self.kwgroup = req.create_entity('Keyword', name=u'kwgroup', included_in=self.classif1)
+        # classification for CWUser
+        cwuser = self.execute('Any U WHERE U is ET, U name "CWUser"').get_entity(0,0)
+        self.classif2 = self.request().create_entity('Classification', name=u"classif2", classifies=cwuser)
+        self.kwuser = req.create_entity('Keyword', name=u'kwuser', included_in=self.classif2)
 
     def test_application_of_bad_keyword_fails(self):
-        self.execute('SET K applied_to G WHERE G is CWGroup, K name "kwuser"')
+        self.execute('SET K applied_to G WHERE G is CWGroup, K eid %(k)s',
+                     {'k':self.kwuser.eid})
         self.assertRaises(ValidationError, self.commit)
 
-
     def test_creating_a_new_subkeyword_sets_included_in(self):
-        self.execute('INSERT Keyword SK: SK name "kwgroup2", SK subkeyword_of K '
-                     'WHERE K name "kwgroup"')
+        req = self.request()
+        kwgroup2 = req.create_entity('Keyword', name=u'kwgroup2', subkeyword_of=self.kwgroup)
         self.commit()
-        rset = self.execute('Any N WHERE C name N, K included_in C, K name "kwgroup2"')
+        rset = self.execute('Any N WHERE C name N, K included_in C, K eid %(k)s', {'k':kwgroup2.eid})
         self.assertEquals(len(rset), 1)
         self.assertEqual(rset[0][0], 'classif1')
 
 
     def test_cannot_create_subkeyword_from_other_classification(self):
-        self.execute('SET X subkeyword_of Y WHERE X eid %s, Y eid %s' % (self.kw1, self.kw2))
+        self.execute('SET K1 subkeyword_of K2 WHERE K1 eid %(k1)s, K2 eid %(k2)s',
+                     {'k1':self.kwgroup.eid, 'k2':self.kwuser.eid})
         self.assertRaises(ValidationError, self.commit)
 
 
     def test_cannot_create_cycles(self):
+        req = self.request()
         # direct obvious cycle
-        self.assertRaises(ValidationError, self.execute,
-                          'SET X subkeyword_of Y WHERE X eid %s, Y eid %s' % (self.kw1, self.kw1))
+        self.execute('SET K1 subkeyword_of K2 WHERE K1 eid %(k1)s, K2 eid %(k2)s',
+                          {'k1':self.kwgroup.eid, 'k2':self.kwuser.eid})
+        self.assertRaises(ValidationError, self.commit)
         # testing indirect cycles
-        kw3 = self.execute('INSERT Keyword SK: SK name "kwgroup2", SK included_in C, '
-                           'SK subkeyword_of K WHERE C name "classif1", K eid %s' % self.kw1)[0][0]
-        self.execute('SET X subkeyword_of Y WHERE X eid %s, Y eid %s' % (self.kw1, kw3))
+        kwgroup2 =  req.create_entity('Keyword', name=u'kwgroup2', included_in=self.classif1, subkeyword_of=self.kwgroup)
+        self.execute('SET K subkeyword_of K2 WHERE K eid %(k)s, K2 eid %(k2)s',
+                     {'k':self.kwgroup.eid, 'k2':kwgroup2.eid})
         self.assertRaises(ValidationError, self.commit)
 
 
--- a/test/unittest_descendant_of.py	Thu Apr 15 18:30:19 2010 +0200
+++ b/test/unittest_descendant_of.py	Thu Apr 15 18:30:30 2010 +0200
@@ -6,144 +6,145 @@
 class KeywordHooksTC(CubicWebTC):
 
     def setup_database(self):
-        self.execute('INSERT Classification C: C name "classif1", C classifies ET WHERE ET name "CWGroup"')
-        self.execute('INSERT Classification C: C name "classif2", C classifies ET WHERE ET name "CWUser"')
-        self.kw1 = self.execute('INSERT Keyword K: K name "kwgroup", K included_in C WHERE C name "classif1"')[0][0]
-        self.kw2 = self.execute('INSERT Keyword K: K name "kwuser", K included_in C WHERE C name "classif2"')[0][0]
+        cwgroup = self.execute('Any U WHERE U is ET, U name "CWGroup"').get_entity(0,0)
+        self.classif1 = self.request().create_entity('Classification', name=u"classif1", classifies=cwgroup)
 
     def test_keyword_add1(self):
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw2"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw3"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw4"')
+        req = self.request()
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', subkeyword_of=kw2, included_in=self.classif1)
+        kw4 = req.create_entity('Keyword', name=u'kw4', subkeyword_of=kw3, included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw5', subkeyword_of=kw4, included_in=self.classif1)
         self.commit()
-        parent = self.execute('Any K WHERE K is Keyword, K name "kw1"').get_entity(0, 0)
-        child = self.execute('Any K WHERE K is Keyword, K name "kw5"').get_entity(0, 0)
+        parent = kw1
+        child = kw5
         self.assertUnorderedIterableEquals([kw.name for kw in child.iterparents()], ['kw4', 'kw3', 'kw2', 'kw1'])
         self.assertUnorderedIterableEquals([kw.name for kw in child.descendant_of], ['kw4', 'kw3', 'kw2', 'kw1'])
         self.assertUnorderedIterableEquals([kw.name for kw in parent.reverse_descendant_of], ['kw5', 'kw4', 'kw3', 'kw2'])
         self.assertUnorderedIterableEquals([kw.name for kw in parent.iterchildren()], ['kw5', 'kw4', 'kw3', 'kw2'])
 
     def test_keyword_add2(self):
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, KK subkeyword_of K WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C, KK subkeyword_of K WHERE C name "classif1", KK name "kw2"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C, KK subkeyword_of K WHERE C name "classif1", KK name "kw3"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, KK subkeyword_of K WHERE C name "classif1", KK name "kw4"')
+        req = self.request()
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', included_in=self.classif1)
+        kw4 = req.create_entity('Keyword', name=u'kw4', subkeyword_of=kw3, included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw5',  subkeyword_of=kw4, included_in=self.classif1)
         self.commit()
-        child  = self.execute('Any K WHERE K is Keyword, K name "kw1"').get_entity(0, 0)
-        parent = self.execute('Any K WHERE K is Keyword, K name "kw5"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in child.iterparents()], ['kw2', 'kw3', 'kw4', 'kw5'])
-        self.assertUnorderedIterableEquals([kw.name for kw in child.descendant_of], ['kw2', 'kw3', 'kw4', 'kw5'])
-        self.assertUnorderedIterableEquals([kw.name for kw in parent.reverse_descendant_of], ['kw4', 'kw3', 'kw2', 'kw1'])
-        self.assertUnorderedIterableEquals([kw.name for kw in parent.iterchildren()], ['kw4', 'kw3', 'kw2', 'kw1'])
-
-    def test_keyword_add3(self):
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw3"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw4"')
+        self.execute('SET K3 subkeyword_of K2 WHERE K3 eid %(kw3)s, K2 eid %(kw2)s',
+                     {'kw3':kw3.eid, 'kw2':kw2.eid})
         self.commit()
-        self.execute('SET K subkeyword_of KK WHERE K name "kw3", KK name "kw2"')
-        self.commit()
-        parent = self.execute('Any K WHERE K is Keyword, K name "kw1"').get_entity(0, 0)
-        child = self.execute('Any K WHERE K is Keyword, K name "kw5"').get_entity(0, 0)
+        parent = kw1
+        child = kw5
         self.assertUnorderedIterableEquals([kw.name for kw in child.iterparents()], ['kw4', 'kw3', 'kw2', 'kw1'])
         self.assertUnorderedIterableEquals([kw.name for kw in child.descendant_of], ['kw4', 'kw3', 'kw2', 'kw1'])
         self.assertUnorderedIterableEquals([kw.name for kw in parent.reverse_descendant_of], ['kw5', 'kw4', 'kw3', 'kw2'])
         self.assertUnorderedIterableEquals([kw.name for kw in parent.iterchildren()], ['kw5', 'kw4', 'kw3', 'kw2'])
 
-    def test_keyword_add4(self):
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, KK subkeyword_of K WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, KK subkeyword_of K WHERE C name "classif1", KK name "kw4"')
+    def test_keyword_add3(self):
+        req = self.request()
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', included_in=self.classif1)
+        kw4 = req.create_entity('Keyword', name=u'kw4', included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw5', subkeyword_of=kw4, included_in=self.classif1)
         self.commit()
-        self.execute('SET KK subkeyword_of K WHERE K name "kw3", KK name "kw2"')
-        self.execute('SET KK subkeyword_of K WHERE K name "kw4", KK name "kw3"')
+        self.execute('SET K2 subkeyword_of K3 WHERE K2 eid %(k2)s, K3 eid %(k3)s',
+                     {'k2': kw4.eid, 'k3': kw3.eid})
+        self.execute('SET K3 subkeyword_of K4 WHERE K3 eid %(k3)s, K4 eid %(k4)s',
+                     {'k3': kw3.eid, 'k4': kw2.eid})
         self.commit()
-        child  = self.execute('Any K WHERE K is Keyword, K name "kw1"').get_entity(0, 0)
-        parent = self.execute('Any K WHERE K is Keyword, K name "kw5"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in child.descendant_of], ['kw2', 'kw3', 'kw4', 'kw5'])
-        self.assertUnorderedIterableEquals([kw.name for kw in child.iterparents()], ['kw2', 'kw3', 'kw4', 'kw5'])
-        self.assertUnorderedIterableEquals([kw.name for kw in parent.iterchildren()], ['kw4', 'kw3', 'kw2', 'kw1'])
-        self.assertUnorderedIterableEquals([kw.name for kw in parent.reverse_descendant_of], ['kw4', 'kw3', 'kw2', 'kw1'])
+        child  = kw5
+        parent = kw1
+        self.assertUnorderedIterableEquals([kw.name for kw in child.descendant_of], ['kw4', 'kw3', 'kw2', 'kw1'])
+        # XXX check the order of iterparents
+        self.assertUnorderedIterableEquals([kw.name for kw in child.iterparents()], ['kw4', 'kw3', 'kw2', 'kw1'])
+        self.assertUnorderedIterableEquals([kw.name for kw in parent.iterchildren()], ['kw2', 'kw3', 'kw4', 'kw5'])
+        self.assertUnorderedIterableEquals([kw.name for kw in parent.reverse_descendant_of], ['kw2', 'kw3', 'kw4', 'kw5'])
 
-    def test_keyword_add5(self):
-        self.execute('INSERT Keyword K: K name "kw0", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw4"')
-        self.execute('SET K subkeyword_of KK WHERE K name "kw3", KK name "kw2"')
+    def test_keyword_add4(self):
+        req = self.request()
+        kw0 = req.create_entity('Keyword', name=u'kw0', included_in=self.classif1)
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', included_in=self.classif1)
+        kw4 = req.create_entity('Keyword', name=u'kw4', included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw5',  subkeyword_of=kw4, included_in=self.classif1)
+        self.execute('SET K3 subkeyword_of K2 WHERE K3 eid %(kw3)s, K2 eid %(kw2)s',
+                     {'kw2': kw2.eid, 'kw3': kw3.eid})
         self.commit();
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw1', 'kw2'])
-        self.execute('SET K descendant_of KK WHERE K name "kw3", KK name "kw0"')
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw1', 'kw2'])
+        self.execute('SET K3 descendant_of K0 WHERE K3 eid %(kw3)s, K0 eid %(kw0)s',
+                      {'kw3': kw3.eid, 'kw0': kw0.eid})
         self.commit()
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw0', 'kw1', 'kw2'])
-        self.execute('SET K descendant_of KK WHERE K name "kw3", KK name "kw4"')
+        kw3.clear_all_caches()
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw0', 'kw1', 'kw2'])
+        self.execute('SET K3 descendant_of K4 WHERE K3 eid %(kw3)s, K4 eid %(kw4)s',
+                      {'kw3': kw3.eid, 'kw4': kw4.eid})
         self.commit()
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw0', 'kw1', 'kw2', 'kw4'])
-        self.execute('SET K descendant_of KK WHERE K name "kw3", KK name "kw5"')
+        kw3.clear_all_caches()
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw0', 'kw1', 'kw2', 'kw4'])
+        self.execute('SET K3 descendant_of K5 WHERE K3 eid %(kw3)s, K5 eid %(kw5)s',
+                       {'kw3': kw3.eid, 'kw5': kw5.eid})
         self.commit()
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw0', 'kw1', 'kw2', 'kw4', 'kw5'])
+        kw3.clear_all_caches()
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw0', 'kw1', 'kw2', 'kw4', 'kw5'])
 
     def test_keyword_update1(self):
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw4"')
-        self.execute('SET K subkeyword_of KK WHERE K name "kw3", KK name "kw2"')
+        req = self.request()
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', included_in=self.classif1)
+        kw4 = req.create_entity('Keyword', name=u'kw4', included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw5',  subkeyword_of=kw4, included_in=self.classif1)
+        self.execute('SET K3 subkeyword_of K2 WHERE K3 eid %(kw3)s, K2 eid %(kw2)s',
+                      {'kw3': kw3.eid, 'kw2': kw2.eid})
         self.commit();
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw1', 'kw2'])
-        self.execute('SET K subkeyword_of KK WHERE K name "kw3", KK name "kw4"')
+        kw3 =  req.entity_from_eid(kw3.eid)
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw1', 'kw2'])
+        self.execute('SET K3 subkeyword_of K4 WHERE K3 eid %(kw3)s, K4 eid %(kw4)s',
+                      {'kw3': kw3.eid, 'kw4': kw4.eid})
         self.commit()
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw4'])
-        self.execute('SET K subkeyword_of KK WHERE K name "kw3", KK name "kw5"')
+        kw3.clear_all_caches()
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw4'])
+        self.execute('SET K3 subkeyword_of K5 WHERE K3 eid %(kw3)s, K5 eid %(kw5)s',
+                     {'kw3': kw3.eid, 'kw5': kw5.eid})
         self.commit()
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], ['kw4', 'kw5'])
+        kw3.clear_all_caches()
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], ['kw4', 'kw5'])
 
     def test_keyword_delete(self):
         """*after_delete_relation* of ``subkeyword_of``
         """
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw2"')
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw3"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw4"')
+        req = self.request()
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', subkeyword_of=kw2, included_in=self.classif1)
+        kw4 = req.create_entity('Keyword', name=u'kw4', subkeyword_of=kw3, included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw5',  subkeyword_of=kw4, included_in=self.classif1)
         self.commit()
-        self.execute('DELETE K subkeyword_of KK WHERE K is Keyword, K name "kw3"')
+        self.execute('DELETE K subkeyword_of K3 WHERE K is Keyword, K eid %(kw3)s',
+                     {'kw3':kw3.eid})
         self.commit()
-        keyword = self.execute('Any K WHERE K is Keyword, K name "kw3"').get_entity(0, 0)
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.iterparents()], [])
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.descendant_of], [])
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.reverse_descendant_of], ['kw5', 'kw4'])
-        self.assertUnorderedIterableEquals([kw.name for kw in keyword.iterchildren()], ['kw5', 'kw4'])
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.iterparents()], [])
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.descendant_of], [])
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.reverse_descendant_of], ['kw5', 'kw4'])
+        self.assertUnorderedIterableEquals([kw.name for kw in kw3.iterchildren()], ['kw5', 'kw4'])
 
     def test_no_add_descendant_cycle(self):
         """no ``descendant_of`` cycle"""
-        self.execute('INSERT Keyword K: K name "kw1", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw2", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw1"')
-        self.execute('INSERT Keyword K: K name "kw3", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw2"')
+        req = self.request()
+        kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        kw2 = req.create_entity('Keyword', name=u'kw2', subkeyword_of=kw1, included_in=self.classif1)
+        kw3 = req.create_entity('Keyword', name=u'kw3', subkeyword_of=kw2, included_in=self.classif1)
         self.commit()
-        rql = 'SET K descendant_of KK WHERE K name "kw1", KK name "kw3"'
+        rql = 'SET K1 descendant_of K3 WHERE K1 eid %(kw1)s, K3 eid %(kw3)s' % {'kw1':kw1.eid,  'kw3':kw3.eid}
         self.assertRaises(ValidationError, self.execute, rql)
-        self.execute('INSERT Keyword K: K name "kw4", K included_in C WHERE C name "classif1"')
-        self.execute('INSERT Keyword K: K name "kw5", K included_in C, K subkeyword_of KK WHERE C name "classif1", KK name "kw4"')
+        kw4 = req.create_entity('Keyword', name=u'kw4', included_in=self.classif1)
+        kw5 = req.create_entity('Keyword', name=u'kw4', subkeyword_of=kw4, included_in=self.classif1)
         self.commit()
-        rql = 'SET K descendant_of KK WHERE K name "kw4", KK name "kw5"'
+        rql = 'SET K4 descendant_of K5 WHERE K4 eid %(kw4)s, K5 eid %(kw5)s' % {'kw4':kw4.eid,  'kw5':kw5.eid}
         self.assertRaises(ValidationError, self.execute, rql)
 
 
--- a/test/unittest_security.py	Thu Apr 15 18:30:19 2010 +0200
+++ b/test/unittest_security.py	Thu Apr 15 18:30:30 2010 +0200
@@ -1,14 +1,15 @@
 from cubicweb.devtools.testlib import CubicWebTC
 
 class SecurityTC(CubicWebTC):
-
     def setup_database(self):
-        self.execute('INSERT Classification C: C name "classif1", C classifies ET WHERE ET name "CWGroup"')
-        self.kw1 = self.execute('INSERT Keyword K: K name "kwgroup", K included_in C WHERE C name "classif1"')[0][0]
+        req = self.request()
+        cwgroup = self.execute('Any U WHERE U is ET, U name "CWGroup"').get_entity(0,0)
+        self.classif1 = self.request().create_entity('Classification', name=u"classif1", classifies=cwgroup)
+        self.kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
 
     def test_nonregr_keyword_selection_as_guest(self):
         self.login('anon')
-        self.execute('Any X ORDERBY Z WHERE X modification_date Z, E eid %(e)s, E applied_to X', {'e':self.kw1}, 'e')
+        self.execute('Any X ORDERBY Z WHERE X modification_date Z, K eid %(k)s, K applied_to X', {'k':self.kw1.eid}, 'k')
 
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main