-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
55 lines (42 loc) · 1.69 KB
/
conftest.py
File metadata and controls
55 lines (42 loc) · 1.69 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
import requests
import random
import string
import allure
def generate_random_string(length: int) -> str:
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for _ in range(length))
def create_courier():
"""Метод создания нового курьера возвращает словарь с данными курьера."""
login = generate_random_string(10)
password = generate_random_string(10)
first_name = generate_random_string(10)
payload = {
"login": login,
"password": password,
"firstName": first_name
}
return payload
@pytest.fixture
def base_url():
return "https://qa-scooter.praktikum-services.ru"
@pytest.fixture
def delete_courier(base_url):
"""Фикстура для удаления курьера после теста"""
couriers_to_delete = []
yield couriers_to_delete
# После каждого теста удаляем созданных курьеров
for courier_data in couriers_to_delete:
login = courier_data["login"]
password = courier_data["password"]
# Логинимся чтобы получить id
login_payload = {"login": login, "password": password}
try:
login_response = requests.post(f"{base_url}/api/v1/courier/login",
json=login_payload,
timeout=5)
if login_response.status_code == 200:
courier_id = login_response.json()["id"]
requests.delete(f"{base_url}/api/v1/courier/{courier_id}", timeout=5)
except Exception:
pass