forked from soasme/flask-perm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
50 lines (38 loc) · 1.15 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
from collections import namedtuple
from pytest import fixture
from flask import Flask, g
from flask_sqlalchemy import SQLAlchemy
from flask_perm import Perm
from flask_perm.core import db
@fixture
def app(request):
flask_app = Flask(__name__)
flask_app.config['TESTING'] = True
flask_app.config['DEBUG'] = True
flask_app.config['SERVER_NAME'] = 'localhost'
ctx = flask_app.app_context()
ctx.push()
request.addfinalizer(ctx.pop)
return flask_app
class User(namedtuple('User', 'id nickname')):
pass
@fixture
def perm(app, request):
def user_loader(id):
return User(id=id, nickname='User%d'%id)
def current_user_loader():
return user_loader(1)
def users_loader(**kwargs):
return [user_loader(id) for id in range(20)]
app.config['PERM_URL_PREFIX'] = '/perm'
app.config['PERM_ADMIN_USERNAME'] = 'admin'
app.config['PERM_ADMIN_PASSWORD'] = 'test'
perm = Perm()
perm.app = app
perm.init_app(app)
perm.user_loader(user_loader)
perm.current_user_loader(current_user_loader)
perm.users_loader(users_loader)
db.create_all()
return perm