Exemplo n.º 1
0
def tt_make_user(name=None, instance_group=None):
    if name is not None:
        name = unicode(name)
        user = model.meta.Session.query(model.User)
        user = user.filter(model.User.user_name == name).first()
        if user:
            return user

    if name is None:
        name = tt_make_str()
    user = model.User(name, u"*****@*****.**", u"test",
                      i18n.get_default_locale())

    default_group = model.Group.by_code(model.Group.CODE_DEFAULT)
    default_membership = model.Membership(user, None, default_group)
    memberships = [default_membership]
    if instance_group:
        instance = tt_get_instance()
        group_membership = model.Membership(user, instance, instance_group)
        memberships.append(group_membership)
    user.memberships = memberships
    model.meta.Session.add(user)
    model.meta.Session.flush()  # write to db and updated db
    # generated attributes
    return user
Exemplo n.º 2
0
def tt_get_admin():
    admin = model.User(tt_make_str(), u"*****@*****.**", u"password")
    model.meta.Session.add(admin)
    model.meta.Session.flush()
    return admin