Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ async def get_comments(
result.total = len(result.comments)
result.comments = [comment_validator.model_validate(comment) for comment in result.comments]

# Получаем ФИО пользователя
Copy link
Member

Choose a reason for hiding this comment

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

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

comments_with_usernames = []
for comment in result.comments:
if user and comment.user_id == user.get("id"):
userdata_info = user.get("userdata", [])
full_name_info = list(filter(lambda x: x.get('param') == "Полное имя", userdata_info))
comment.user_full_name = full_name_info[0].get("value") if full_name_info else None
else:
comment.user_full_name = None
comments_with_usernames.append(comment)

result.comments = comments_with_usernames

return result


Expand Down
1 change: 1 addition & 0 deletions rating_api/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CommentGet(Base):
lecturer_id: int
like_count: int
dislike_count: int
user_full_name: str | None = None
Copy link
Member

Choose a reason for hiding this comment

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

поменять на user_fullname название



class CommentGetWithStatus(CommentGet):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_routes/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,33 @@ def test_update_comment(client, dbsession, nonanonymous_comment, body, response_
assert getattr(nonanonymous_comment, k, None) == v # Есть ли изменения в БД


@pytest.mark.parametrize("is_own_comment", [True, False])
Copy link
Member

Choose a reason for hiding this comment

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

здесь все неправильно
фикстуры user нет в test/conftest.py из-за этого вылетает ошибка при использовании pytest

def test_user_full_name_field(client, dbsession, lecturers, user, is_own_comment):
"""Проверяет, что user_full_name заполняется только для комментариев текущего пользователя"""
lecturer = lecturers[0]
comment_data = {
"user_id": user.get("id") if is_own_comment else 9999,
"lecturer_id": lecturer.id,
"subject": "Test subject",
"text": "Test text",
"mark_kindness": 1,
"mark_freebie": 0,
"mark_clarity": 0,
"review_status": ReviewStatus.APPROVED,
}
comment = Comment(**comment_data)
dbsession.add(comment)
dbsession.commit()

response = client.get(f_url(comment.uuid))

assert response.status_code == status.HTTP_200_OK
if is_own_comment:
assert response.json()["user_full_name"] is not None
else:
assert response.json()["user_full_name"] is None


# TODO: переписать под новую логику
# def test_delete_comment(client, dbsession, comment):
# response = client.delete(f'{url}/{comment.uuid}')
Expand Down