-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
36 lines (34 loc) · 1.48 KB
/
conftest.py
File metadata and controls
36 lines (34 loc) · 1.48 KB
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
import allure
import pytest
import requests
@pytest.fixture(scope="function")
def generate_new_object():
with allure.step("Sending POST/objects request for precondition"):
headers = {
"Content-Type": "application/json"
}
body = {
"name": "Apple MacBook Pro 16",
"data": {
"year": 2019,
"price": 1849.99,
"CPU model": "Intel Core i9",
"Hard disk size": "1 TB"
}
}
with allure.step(f"Sending POST/objects request for creating new object and getting id"):
response_generator = requests.post(
"https://api.restful-api.dev/objects", headers=headers, json=body
).json()
with allure.step(f"Checking that REST-full API for learning not reached limit today"):
try:
if response_generator["error"]:
raise Exception("REST-full API for learning not reached limit today, status code 405")
except Exception as e:
raise e
with allure.step(f"Checking that param 'createdAt' is not null"):
assert response_generator["createdAt"] is not None, "Object is not created"
yield response_generator
with allure.step(f"Sending DELETE/objects/{response_generator['id']} request"):
requests.delete(f"https://api.restful-api.dev/objects/{response_generator['id']}")
assert requests.get(f"https://api.restful-api.dev/objects/{response_generator['id']}").status_code == 404