Skip to content

Task 2: API tests with Allure report#1

Open
EvaV21 wants to merge 2 commits intomainfrom
develop2
Open

Task 2: API tests with Allure report#1
EvaV21 wants to merge 2 commits intomainfrom
develop2

Conversation

@EvaV21
Copy link
Owner

@EvaV21 EvaV21 commented Mar 3, 2026

No description provided.

def token(api, registered_user):
with allure.step("Логинимся и получаем токен"):
r = api.login({"email": registered_user["email"], "password": registered_user["password"]})
assert r.status_code == 200, f"login failed: {r.status_code} {r.text}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: в фикстурах не проводим тестирование, это делает все тесты где используется фикстура неатомарными

def ingredient_ids(api):
with allure.step("Получаем список ингредиентов"):
r = api.get_ingredients()
assert r.status_code == 200, f"ingredients failed: {r.status_code} {r.text}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и тут

def registered_user(api, user_data):
with allure.step("Регистрируем пользователя"):
r = api.register(user_data)
assert r.status_code == 200, f"register failed: {r.status_code} {r.text}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и тут


@pytest.fixture
def user_data():
return generate_user()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: фикстуры не занимаются прокидыванием данных в тест и выполнением примитивной логики, они выполняют сложную логику предусловий\постусловий и вычислений.

assert body.get("success") is True
assert "accessToken" in body
assert "refreshToken" in body
assert body["user"]["email"] == user_data["email"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно исправить: везде где создавали пользователя после теста нужно его удалять при помощи фикстуры

assert r.status_code == 403
body = r.json()

assert body.get("success") is False No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно лучше: кажется хорошей идеей включить постусловие с удалением курьера в тесты с неуспешной регистрацией, на случай если там будут баги, мы всё равно оставим после тестирования чистую БД

with allure.step("Регистрируем пользователя"):
r = api.register(user_data)
assert r.status_code == 200, f"register failed: {r.status_code} {r.text}"
return user_data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно исправить: везде где создавали пользователя после теста нужно его удалять при помощи фикстуры

@EvaV21
Copy link
Owner Author

EvaV21 commented Mar 8, 2026

allure_graphs allure_overview allure_suites

Allure report attached.

Test coverage includes:

  • User creation
  • User login
  • Order creation

All tests passed successfully (15/15).


@allure.title("Можно создать уникального пользователя")
def test_create_unique_user_success(self, registered_user):
response = registered_user["response"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: Здесь и везде. Фикстура - это объект, который можно рассматривать, как набор условий необходимых тесту для выполнения. То есть она не должна заменять шаги теста. В этом случае тестируются шаги регистрации, поэтому нельзя использовать фикстуру с регистрацией


@allure.title("Создание заказа с авторизацией")
def test_create_order_with_auth(self, api, token, ingredient_ids):
r = api.create_order(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: Над каждым логическим методом (запрос через requests) нужно прописать декоратор allure.step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants