deprecated one more custom add_entity in favor of req.create_entity
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Dec 2009 09:38:14 +0100
changeset 4016 250784a2d105
parent 4015 4f8235204dda
child 4017 a5b4d4f2a1c7
deprecated one more custom add_entity in favor of req.create_entity
devtools/testlib.py
--- a/devtools/testlib.py	Tue Dec 08 09:10:39 2009 +0100
+++ b/devtools/testlib.py	Tue Dec 08 09:38:14 2009 +0100
@@ -353,38 +353,6 @@
     def entity(self, rql, args=None, eidkey=None, req=None):
         return self.execute(rql, args, eidkey, req=req).get_entity(0, 0)
 
-    def add_entity(self, etype, req=None, **kwargs):
-        rql = ['INSERT %s X' % etype]
-        # dict for replacement in RQL Request
-        args = {}
-        if kwargs:
-            rql.append(':')
-            # dict to define new entities variables
-            entities = {}
-            # assignement part of the request
-            sub_rql = []
-            for key, value in kwargs.iteritems():
-                # entities
-                if hasattr(value, 'eid'):
-                    new_value = "%s__" % key.upper()
-                    entities[new_value] = value.eid
-                    args[new_value] = value.eid
-
-                    sub_rql.append("X %s %s" % (key, new_value))
-                # final attributes
-                else:
-                    sub_rql.append('X %s %%(%s)s' % (key, key))
-                    args[key] = value
-            rql.append(', '.join(sub_rql))
-            if entities:
-                rql.append('WHERE')
-                # WHERE part of the request (to link entity to they eid)
-                sub_rql = []
-                for key, value in entities.iteritems():
-                    sub_rql.append("%s eid %%(%s)s" % (key, key))
-                rql.append(', '.join(sub_rql))
-        return self.execute(' '.join(rql), args, req=req).get_entity(0, 0)
-
     # vregistry inspection utilities ###########################################
 
     def pviews(self, req, rset):
@@ -689,6 +657,12 @@
 
     # deprecated ###############################################################
 
+    @deprecated('[3.6] use self.request().create_entity(...)')
+    def add_entity(self, etype, req=None, **kwargs):
+        if req is None:
+            req = self.request()
+        return req.create_entity(etype, **kwargs)
+
     @deprecated('[3.4] use self.vreg["etypes"].etype_class(etype)(self.request())')
     def etype_instance(self, etype, req=None):
         req = req or self.request()