forked from python-cn/firefly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
47 lines (38 loc) · 1.17 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
# coding=utf-8
from __future__ import absolute_import
from flask import url_for
from flask_login import current_user
import pytest
from firefly.app import create_app
from firefly.ext import db
from firefly.models.user import User
@pytest.fixture
def app(request):
app = create_app('tests/settings.py')
db_name = app.config['MONGODB_SETTINGS']['db']
def cleanup():
db.connection.drop_database(db_name)
request.addfinalizer(cleanup)
return app
@pytest.fixture
def client_class(request, client):
def login(cls):
user = User.objects.filter(email='[email protected]').first()
if user is None:
user = User.create_user('foo', '[email protected]', 'foobar')
else:
user.set_password('foobar')
user.save()
form = {
'email': '[email protected]',
'password': 'foobar',
}
rv = client.post(
url_for('home.login'), data=form,
follow_redirects=True
)
assert current_user.is_authenticated()
assert url_for('security.logout') in rv.data
if request.cls is not None:
request.cls.client = client
request.cls._login = login