Ejemplo n.º 1
0
def create_and_log_in_user(testapp=None,
                           department=None,
                           rolename=None,
                           username="******"):
    # set up a user
    user = User.create(username=username,
                       email="{}@example.com".format(username),
                       password="******")

    # associate a department if a department is passed
    if department:
        user.departments.append(department)

    user.active = True
    user.save()

    # associate a role if a name is passed
    if rolename:
        user_role = Role(name=rolename)
        user_role.save()
        user.roles.append(user_role)

    # login
    response = testapp.get("/login/")
    form = response.forms['loginForm']
    form['username'] = user.username
    form['password'] = '******'
    response = form.submit().follow()
    return user
Ejemplo n.º 2
0
 def test_role(self):
     role = Role(name='admin')
     role.save()
     u = UserFactory()
     u.roles.append(role)
     u.save()
     assert role in u.roles
Ejemplo n.º 3
0
def make_admin_user():
    password = prompt_pass("Password")
    user = User.create(username="******", email="*****@*****.**", password=password, active=True)
    admin_role = Role(name='admin')
    admin_role.save()
    user.roles.append(admin_role)
    user.save()
Ejemplo n.º 4
0
 def test_role(self):
     role = Role(name='admin')
     role.save()
     u = UserFactory()
     u.roles.append(role)
     u.save()
     assert role in u.roles
Ejemplo n.º 5
0
    def test_is_admin(self):
        admin_role = Role(name='admin')
        admin_role.save()

        u = UserFactory()
        u.roles.append(admin_role)
        u.save()

        assert u.is_admin()
Ejemplo n.º 6
0
    def test_is_admin(self):
        admin_role = Role(name='admin')
        admin_role.save()

        u = UserFactory()
        u.roles.append(admin_role)
        u.save()

        assert u.is_admin()
Ejemplo n.º 7
0
def make_admin_user():
    password = prompt_pass("Password")
    user = User.create(username="******",
                       email="*****@*****.**",
                       password=password,
                       active=True)
    admin_role = Role(name='admin')
    admin_role.save()
    user.roles.append(admin_role)
    user.save()
Ejemplo n.º 8
0
 def test_many_roles(self):
     admin_role = Role(name='admin')
     admin_role.save()
     other_role = Role(name='other')
     other_role.save()
     u = UserFactory()
     u.roles.append(admin_role)
     u.roles.append(other_role)
     u.save()
     assert admin_role in u.roles
     assert other_role in u.roles
Ejemplo n.º 9
0
 def test_many_roles(self):
     admin_role = Role(name='admin')
     admin_role.save()
     other_role = Role(name='other')
     other_role.save()
     u = UserFactory()
     u.roles.append(admin_role)
     u.roles.append(other_role)
     u.save()
     assert admin_role in u.roles
     assert other_role in u.roles
Ejemplo n.º 10
0
    def test_many_users(self):
        admin_role = Role(name='admin')
        admin_role.save()

        u = UserFactory()
        u.roles.append(admin_role)
        u.save()

        admin_role_two = Role(name='admin')
        admin_role_two.save()

        u_two = UserFactory()
        u_two.roles.append(admin_role_two)
        u_two.save()

        assert admin_role in u.roles
        assert admin_role_two in u_two.roles
Ejemplo n.º 11
0
    def test_many_users(self):
        admin_role = Role(name='admin')
        admin_role.save()

        u = UserFactory()
        u.roles.append(admin_role)
        u.save()

        admin_role_two = Role(name='admin')
        admin_role_two.save()

        u_two = UserFactory()
        u_two.roles.append(admin_role_two)
        u_two.save()

        assert admin_role in u.roles
        assert admin_role_two in u_two.roles
Ejemplo n.º 12
0
def create_and_log_in_user(testapp=None, department=None, rolename=None, username="******"):
    # set up a user
    user = User.create(username=username, email="{}@example.com".format(username), password="******")

    # associate a department if a department is passed
    if department:
        user.departments.append(department)

    user.active = True
    user.save()

    # associate a role if a name is passed
    if rolename:
        user_role = Role(name=rolename)
        user_role.save()
        user.roles.append(user_role)

    # login
    response = testapp.get("/login/")
    form = response.forms['loginForm']
    form['username'] = user.username
    form['password'] = '******'
    response = form.submit().follow()
    return user