forked from cafebabel/cafebabel.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
53 lines (38 loc) · 1.16 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
51
52
53
from pathlib import Path
from tempfile import mkdtemp
import pytest
from cafebabel import app as myapp
from cafebabel.articles.models import Article
from cafebabel.core.commands import _dropdb, _initdb
from cafebabel.users.models import Role, User, user_datastore
from flask_security.confirmable import confirm_user
def pytest_runtest_setup():
_initdb()
def pytest_runtest_teardown():
_dropdb()
@pytest.fixture
def app():
myapp.config['MONGODB_DB'] = 'tests'
myapp.config['WTF_CSRF_ENABLED'] = False
myapp.config['ARTICLES_IMAGES_PATH'] = Path(mkdtemp())
return myapp
@pytest.fixture
def user():
user = User.objects.create(email='[email protected]', password='secret')
with myapp.app_context():
confirm_user(user)
return user
@pytest.fixture
def editor(user):
editor_role = Role.objects.get(name='editor')
user_datastore.add_role_to_user(user, editor_role)
return user
@pytest.fixture
def admin():
return User.objects.get(email='[email protected]')
@pytest.fixture
def article():
return Article.objects.create(
title='title',
language=myapp.config['LANGUAGES'][0][0],
body='body')