Skip to content

Fix test_rental_session#147

Open
Georgon wants to merge 8 commits intomainfrom
fix-test-item-new
Open

Fix test_rental_session#147
Georgon wants to merge 8 commits intomainfrom
fix-test-item-new

Conversation

@Georgon
Copy link
Copy Markdown

@Georgon Georgon commented Apr 2, 2026

Fix test_item and test_rental_session:

Все тесты работают.
Для test_item пофикшен тест test_delete_item.

В conftest.py:
Добавил новые фикстуры, необходимые для новых тестов, дабы в test_rental_session.py не было прямого обращения к БД. Также переписаны некоторые уже существующие фикстуры. Их изменения не влияют на другие файлы.

В test_rental_session.py:
Переписал уже существующие тесты, проверив их логику и работоспособность. Дописал новые. Также для ручки patch("/{session_id}") update_rental_session написал два теста на проверку прав для обычного пользователя и админа.

PS: Объединил несколько тестов в один и убрал тесты на скоупы

@Georgon Georgon requested a review from petrCher April 2, 2026 15:58
@Georgon Georgon self-assigned this Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

💩 Code linting failed, use black and isort to fix it.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Summary

Tests Skipped Failures Errors Time
131 0 💤 0 ❌ 0 🔥 16.767s ⏱️

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

💩 Code linting failed, use black and isort to fix it.

)
async def start_rental_session(
session_id, deadline_ts=Depends(validate_deadline_ts), user=Depends(UnionAuth(scopes=["rental.session.admin"]))
session_id: int, deadline_ts=Depends(validate_deadline_ts), user=Depends(UnionAuth(scopes=["rental.session.admin"]))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

правильно сделано, молодец

"auth_methods": ["string"],
"session_scopes": [{"id": 0, "name": "string"}],
"user_scopes": [{"id": 0, "name": "string"}],
"user_scopes": [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

если это сейчас ничего не делает зачем оставлять? удали

], # добавлен нужный скоуп "rental.session.admin" (по сути сейчас эта строка ничего не делает, но как в UnionAuth)
"scopes": [
"rental.session.admin"
], # добавлено для корректной работы прав в тесте test_admin_can_update_any_rental_session
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

такого теста нет, удаляй тоже

"auth_methods": ["string"],
"session_scopes": [{"id": 0, "name": "string"}],
"user_scopes": [{"id": 0, "name": "string"}],
"user_scopes": [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

здесь тоже, зачем это? запускаю и проверяю у себя все локально, работает и без этого

Comment on lines +96 to +101
"user_scopes": [
{"id": 1, "name": "rental.session.admin"}
], # добавлен нужный скоуп "rental.session.admin" (по сути сейчас эта строка ничего не делает, но как в UnionAuth)
"scopes": [
"rental.session.admin"
], # добавлено для корректной работы прав в тесте test_admin_can_update_any_rental_session
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

убирай и возвращай как было, это не нужно, можешь сам запустить тесты без изменения этого кода и убедиться, что все корректно работает

Comment on lines +122 to +123
"user_scopes": [],
"scopes": [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

также не нужно

Comment on lines -257 to -262
for i in item_types:
for item in i.items:
dbsession.delete(item)
dbsession.flush()
dbsession.delete(i)
dbsession.commit()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

думаю что это не стоит удалять, попробуй лучше переработать падающий тест на delete item с этим кодом. и изучи логику удаления, вероятно с ней ошибка сейчас(изучить надо эндпоинт в первую очередь)

'session_id, right_status_code',
[
(0, status.HTTP_200_OK),
# (1, status.HTTP_404_NOT_FOUND),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

комменты оставлять так не надо, если не используется - убираем

assert response.json()["status"] == RentStatus.EXPIRED


# Тест на начало уже активной сессии
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

этот коммент лишний, ты же добавил описание функции

assert response.status_code == expected_status


# Тест для блокирующего кейса (параметризуется фикстурой blocking_session)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

коммент лишний, вся суть должна быть отражена в документации к тесту(то что с тремя кавычками)

check_object_update(item_fixture, session=dbsession, is_available=end_item_avail),
):
if case_name == "available_item":
item = request.getfixturevalue("available_item")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

мне не нравится непрямое обращение к фикстуре с помощью getfixturevalue, лучше в аргументах функции указать требуемые фикстуры

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