1
|
|
|
""" |
2
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
3
|
|
|
:License: Modified BSD, see LICENSE for details. |
4
|
|
|
|
5
|
|
|
API-specific fixtures |
6
|
|
|
""" |
7
|
|
|
|
8
|
|
|
import pytest |
9
|
|
|
|
10
|
|
|
from tests.base import CONFIG_FILENAME_TEST_ADMIN, create_app |
11
|
|
|
from tests.helpers import create_brand, create_party, create_user |
12
|
|
|
|
13
|
|
|
from ..conftest import database_recreated |
14
|
|
|
from ..helpers import create_email_config, create_site |
15
|
|
|
|
16
|
|
|
from .helpers import assemble_authorization_header |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
API_TOKEN = 'just-say-PLEASE!' |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
@pytest.fixture(scope='session') |
23
|
|
|
def api_app_without_db(db): |
24
|
|
|
app = create_app(CONFIG_FILENAME_TEST_ADMIN, {'API_TOKEN': API_TOKEN}) |
25
|
|
|
with app.app_context(): |
26
|
|
|
yield app |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
@pytest.fixture(scope='module') |
30
|
|
|
def app(api_app_without_db, db): |
31
|
|
|
app = api_app_without_db |
32
|
|
|
with database_recreated(db): |
33
|
|
|
yield app |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
@pytest.fixture(scope='module') |
37
|
|
|
def site(app): |
38
|
|
|
create_email_config() |
39
|
|
|
return create_site() |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
@pytest.fixture(scope='module') |
43
|
|
|
def party(app): |
44
|
|
|
brand = create_brand() |
45
|
|
|
return create_party(brand.id) |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
@pytest.fixture(scope='module') |
49
|
|
|
def admin(app): |
50
|
|
|
return create_user('Admin') |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
@pytest.fixture(scope='module') |
54
|
|
|
def user(app): |
55
|
|
|
return create_user('User') |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
@pytest.fixture(scope='module') |
59
|
|
|
def api_client(app): |
60
|
|
|
"""Provide a test HTTP client against the API.""" |
61
|
|
|
return app.test_client() |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
@pytest.fixture(scope='module') |
65
|
|
|
def api_client_authz_header(): |
66
|
|
|
"""Provide a test HTTP client against the API.""" |
67
|
|
|
return assemble_authorization_header(API_TOKEN) |
68
|
|
|
|