Skip to content

Fix test_rental_session#147

Merged
petrCher merged 11 commits intomainfrom
fix-test-item-new
Apr 4, 2026
Merged

Fix test_rental_session#147
petrCher merged 11 commits intomainfrom
fix-test-item-new

Conversation

@Georgon
Copy link
Copy Markdown
Contributor

@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.731s ⏱️

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

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

Comment thread rental_backend/routes/rental_session.py
Comment thread tests/conftest.py Outdated
"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 thread tests/conftest.py Outdated
], # добавлен нужный скоуп "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 thread tests/conftest.py Outdated
"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 thread tests/conftest.py Outdated
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 thread tests/conftest.py Outdated
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 thread tests/conftest.py
'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, лучше в аргументах функции указать требуемые фикстуры

Comment thread tests/conftest.py
@petrCher petrCher merged commit e40d363 into main Apr 4, 2026
2 checks passed
@petrCher petrCher linked an issue Apr 4, 2026 that may be closed by this pull request
@petrCher petrCher deleted the fix-test-item-new branch April 4, 2026 19:47
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.

test rental session

2 participants