forked from Perehodko/API-test-pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
46 lines (34 loc) · 1.04 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
import pytest
from framework.helper import get_all_post, delete_post, gen_create_post
@pytest.fixture(scope='function')
def prepared_resource_id(request, post_exist=None):
response = get_all_post()
post_id = request.param
try:
if response.json()[post_id]:
post_exist = True
except IndexError:
post_exist = False
if post_exist:
delete_post(post_id=request.param)
def _clean_up():
if not post_exist:
delete_post(post_id=request.param)
request.addfinalizer(_clean_up)
return request.param
@pytest.fixture(scope='function')
def create_post(request, post_exist=None):
response = get_all_post()
post_id = request.param
try:
if response.json()[post_id]:
post_exist = True
except IndexError:
post_exist = False
if not post_exist:
gen_create_post(post_id=request.param)
def _clean_up():
if post_exist:
delete_post(post_id=request.param)
request.addfinalizer(_clean_up)
return request.param