devtools/testlib.py
branchstable
changeset 7337 67cd9d5b4c2e
parent 7331 7fcc4f22f3e4
child 7338 591d6ed3e1f4
child 7376 38524ca653e5
equal deleted inserted replaced
7335:9a42f480b856 7337:67cd9d5b4c2e
   354         else:
   354         else:
   355             return req.user
   355             return req.user
   356 
   356 
   357     @iclassmethod # XXX turn into a class method
   357     @iclassmethod # XXX turn into a class method
   358     def create_user(self, req, login=None, groups=('users',), password=None,
   358     def create_user(self, req, login=None, groups=('users',), password=None,
   359                     commit=True, **kwargs):
   359                     email=None, commit=True, **kwargs):
   360         """create and return a new user entity"""
   360         """create and return a new user entity"""
   361         if isinstance(req, basestring):
   361         if isinstance(req, basestring):
   362             warn('[3.12] create_user arguments are now (req, login[, groups, password, commit, **kwargs])',
   362             warn('[3.12] create_user arguments are now (req, login[, groups, password, commit, **kwargs])',
   363                  DeprecationWarning, stacklevel=2)
   363                  DeprecationWarning, stacklevel=2)
   364             if not isinstance(groups, (tuple, list)):
   364             if not isinstance(groups, (tuple, list)):
   374         user = req.create_entity('CWUser', login=unicode(login),
   374         user = req.create_entity('CWUser', login=unicode(login),
   375                                  upassword=password, **kwargs)
   375                                  upassword=password, **kwargs)
   376         req.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)'
   376         req.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)'
   377                     % ','.join(repr(str(g)) for g in groups),
   377                     % ','.join(repr(str(g)) for g in groups),
   378                     {'x': user.eid})
   378                     {'x': user.eid})
       
   379         if email is not None:
       
   380             req.create_entity('EmailAddress', address=unicode(email),
       
   381                               reverse_primary_email=user)
   379         user.cw_clear_relation_cache('in_group', 'subject')
   382         user.cw_clear_relation_cache('in_group', 'subject')
   380         if commit:
   383         if commit:
   381             try:
   384             try:
   382                 req.commit() # req is a session
   385                 req.commit() # req is a session
   383             except AttributeError:
   386             except AttributeError: