[testlib] create_user support extra kwargs to give to create_entity(CWUser) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 29 Mar 2010 11:51:02 +0200
branchstable
changeset 5055 14906474c55d
parent 5054 cb066d29166a
child 5056 5de07c77d73f
[testlib] create_user support extra kwargs to give to create_entity(CWUser)
devtools/testlib.py
--- a/devtools/testlib.py	Mon Mar 29 10:20:01 2010 +0200
+++ b/devtools/testlib.py	Mon Mar 29 11:51:02 2010 +0200
@@ -275,20 +275,20 @@
             return req.user
 
     def create_user(self, login, groups=('users',), password=None, req=None,
-                    commit=True):
+                    commit=True, **kwargs):
         """create and return a new user entity"""
         if password is None:
             password = login.encode('utf8')
-        cursor = self._orig_cnx.cursor(req or self.request())
-        rset = cursor.execute('INSERT CWUser X: X login %(login)s, X upassword %(passwd)s',
-                              {'login': unicode(login), 'passwd': password})
-        user = rset.get_entity(0, 0)
-        cursor.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)'
-                       % ','.join(repr(g) for g in groups),
-                       {'x': user.eid}, 'x')
+        if req is None:
+            req = self._orig_cnx.request()
+        user = req.create_entity('CWUser', login=unicode(login),
+                                 upassword=password, **kwargs)
+        req.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)'
+                    % ','.join(repr(g) for g in groups),
+                    {'x': user.eid}, 'x')
         user.clear_related_cache('in_group', 'subject')
         if commit:
-            self._orig_cnx.commit()
+            req.cnx.commit()
         return user
 
     def login(self, login, **kwargs):