-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
114 lines (87 loc) · 2.87 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import pytest
from flask_security.utils import hash_password
from cafebabel import create_app
from cafebabel.commands import auth_fixtures, drop_collections
from cafebabel.articles.models import Article
from cafebabel.articles.tags.models import Tag
from cafebabel.articles.translations.models import Translation
from cafebabel.users.models import User, UserProfile
test_app = create_app('config.TestingConfig')
def pytest_runtest_setup():
auth_fixtures(test_app)
ds = test_app.user_datastore
with test_app.app_context():
user = ds.create_user(email='[email protected]',
profile=UserProfile(name='Testy Tester'),
password=hash_password('password'))
ds.activate_user(user)
user2 = ds.create_user(email='[email protected]',
password=hash_password('password'))
ds.activate_user(user2)
ds.commit()
def pytest_runtest_teardown():
drop_collections()
@pytest.fixture(scope='session')
def app(request):
"""Session-wide test `Flask` application."""
ctx = test_app.app_context()
ctx.push()
def tearDown():
ctx.pop()
request.addfinalizer(tearDown)
return test_app
@pytest.fixture
def user():
return User.objects.get(email='[email protected]')
@pytest.fixture
def user2():
return User.objects.get(email='[email protected]')
@pytest.fixture
def editor():
return User.objects.get(email=test_app.config['EDITOR_EMAILS']['en'])
@pytest.fixture
def tag():
return Tag.objects.create(
name='Wonderful',
summary='summary text',
language=test_app.config['LANGUAGES'][0][0])
@pytest.fixture
def article(user):
return Article.objects.create(
title='article title',
summary='summary text',
authors=[user],
language=test_app.config['LANGUAGES'][0][0],
body='body text')
@pytest.fixture
def published_article(user):
return Article.objects.create(
title='article title',
summary='summary text',
authors=[user],
language=test_app.config['LANGUAGES'][0][0],
body='body text',
status='published')
@pytest.fixture
def translation(user, article):
language = test_app.config['LANGUAGES'][1][0]
return Translation.objects.create(
title='title',
summary='summary text',
language=language,
body='body text',
authors=[user],
translators=[user.id],
original_article=article.id)
@pytest.fixture
def published_translation(user, published_article):
language = test_app.config['LANGUAGES'][1][0]
return Translation.objects.create(
title='title',
summary='summary text',
language=language,
body='body text',
authors=[user],
translators=[user.id],
original_article=published_article.id,
status='published')