-
Notifications
You must be signed in to change notification settings - Fork 4
/
conftest.py
105 lines (85 loc) · 2.56 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
import logging
import pytest
from swagger_coverage.src.coverage import SwaggerCoverage
from common.api_builder import ApiBuilder
from fixtures.app import StoreApp
from fixtures.common_models import UserStore
from fixtures.register.model import RegisterUser
from fixtures.store.model import Store
from fixtures.user_info.model import AddUserInfo
logger = logging.getLogger("api")
@pytest.fixture(scope="session")
def app(request):
url = request.config.getoption("--api-url")
logger.info(f"Start api tests, url is {url}")
return StoreApp(url)
@pytest.fixture
def register_user(app) -> UserStore:
"""
Register new user
"""
data = RegisterUser.random()
res = app.register.register(data=data)
data = UserStore(user=data, user_uuid=res.data.uuid)
return data
@pytest.fixture
def auth_user(app, register_user) -> UserStore:
"""
Login user
"""
res = app.auth.login(data=register_user.user)
token = res.data.access_token
header = {"Authorization": f"JWT {token}"}
data = UserStore(**register_user.to_dict())
data.header = header
return data
@pytest.fixture
def user_info(app, auth_user) -> UserStore:
"""
Add user info
"""
data = AddUserInfo.random()
app.user_info.add_user_info(
uuid=auth_user.user_uuid, data=data, header=auth_user.header
)
data_user = UserStore(**auth_user.to_dict())
data_user.user_info = data
return data_user
@pytest.fixture
def store(app, user_info) -> UserStore:
"""
Add store
"""
data = Store.random()
app.store.add_store(data.name, header=user_info.header)
data_store = UserStore(**user_info.to_dict())
data_store.store = data.name
return data_store
def pytest_addoption(parser):
parser.addoption(
"--api-url",
action="store",
help="enter api url",
default="http://localhost:56733",
),
parser.addoption(
"--swagger-url",
action="store",
help="enter swagger url",
default="https://api.swaggerhub.com/apis/berpress/flask-rest-api/1.0.0",
),
@pytest.fixture(scope="session", autouse=True)
def swagger_checker(request):
url = request.config.getoption("--swagger-url")
url_api = request.config.getoption("--api-url")
swagger = SwaggerCoverage(api_url=url_api, url=url)
swagger.create_coverage_data()
yield
swagger.create_report()
@pytest.fixture
def user_info_builder(app):
app_builder = ApiBuilder(app)
user = (
app_builder.authentication.register().auth().user_info.add_user_info().build()
)
return user