Пример #1
0
    def test_add_roles_to_user(self):
        user = utils.create_and_save_user()
        user.roles.append(Role.admin())
        db.session.add(user)
        db.session.commit()

        actual_user = User.query.get(user.id)
        self.assertIn(Role.admin(), actual_user.roles)
        self.assertIn(Role.regular(),
                      actual_user.roles)  # All have this by default
        self.assertNotIn(Role.manager(), actual_user.roles)
Пример #2
0
def fill_db():
    create_roles()
    u1 = User('u1', 'p1', 'Us', 'Er1')
    u2 = User('u2', 'p2', 'Us', 'Er2')
    u3 = User('u3', 'p3', 'Us', 'Er3')

    admin = User('admin', 'admin', 'Ad', 'Min')
    admin.roles.append(Role.admin())
    user_manager = User('manager', 'manager', 'Man', 'Ager')
    user_manager.roles.append(Role.manager())

    today = datetime.date.today()
    one_day = datetime.timedelta(days=1)
    one_month = datetime.timedelta(days=30)
    two_months = one_day + one_month

    t1 = Trip('D1', utils.print_date(today), utils.print_date(today + one_day),
              'C1', u1)
    t2 = Trip('D2', utils.print_date(today + one_day),
              utils.print_date(today + two_months), 'C1', u1)
    t3 = Trip('D3', utils.print_date(today - one_month),
              utils.print_date(today - one_day), 'C1', u1)

    db.session.add_all([u1, u2, u3, admin, user_manager, t1, t2, t3])
    db.session.commit()
Пример #3
0
def create_user_admin(username='******', password='******'):
    admin_user = create_and_save_user(username, password)
    admin_user.roles.append(Role.admin())
    db.session.add(admin_user)
    db.session.commit()

    return admin_user