diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 233ac3c..eeea8b5 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -62,7 +62,7 @@ jobs: - uses: isort/isort-action@master with: requirementsFiles: "requirements.txt requirements.dev.txt" - - uses: psf/black@stable + - uses: psf/black@23.11.0 - name: Comment if linting failed if: ${{ failure() }} uses: thollander/actions-comment-pull-request@v2 diff --git a/.github/workflows/review_code.py b/.github/workflows/review_code.py index 8b7a69c..6f5b47c 100644 --- a/.github/workflows/review_code.py +++ b/.github/workflows/review_code.py @@ -431,7 +431,6 @@ def create_review_with_comments(file_comments, commit_id): valid_review_comments = [] for comment in review_comments: - if "path" not in comment or "position" not in comment or comment["position"] is None: print( f"Пропускаем невалидный комментарий к файлу {comment.get('path', 'неизвестный')}: отсутствует позиция" diff --git a/rating_api/models/base.py b/rating_api/models/base.py index 932ac56..fc945d7 100644 --- a/rating_api/models/base.py +++ b/rating_api/models/base.py @@ -68,7 +68,6 @@ def update(cls, id: int | str, *, session: Session, **kwargs) -> BaseDbModel: # Проверка на изменение полей changed_fields = False for field, new_value in kwargs.items(): - old_value = getattr(obj, field) if old_value != new_value and not field in technical_fields: changed_fields = True diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index 1894b10..fc01f0c 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -172,8 +172,8 @@ async def get_comment(uuid: UUID, user=Depends(UnionAuth(auto_error=False, allow raise ObjectNotFound(Comment, uuid) base_data = CommentGet.model_validate(comment) if user: - base_data.is_liked=comment.has_reaction(user.get("id"), Reaction.LIKE) - base_data.is_disliked=comment.has_reaction(user.get("id"), Reaction.DISLIKE) + base_data.is_liked = comment.has_reaction(user.get("id"), Reaction.LIKE) + base_data.is_disliked = comment.has_reaction(user.get("id"), Reaction.DISLIKE) return base_data @@ -267,8 +267,8 @@ async def get_comments( base_data = comment_validator.model_validate(comment) if current_user_id: reaction = user_reactions.get(comment.uuid) - base_data.is_liked = (reaction == Reaction.LIKE) - base_data.is_disliked = (reaction == Reaction.DISLIKE) + base_data.is_liked = reaction == Reaction.LIKE + base_data.is_disliked = reaction == Reaction.DISLIKE comments_with_like.append(base_data) result.comments = comments_with_like @@ -320,8 +320,8 @@ async def update_comment(uuid: UUID, comment_update: CommentUpdate, user=Depends ) updated_comment = CommentGet.model_validate(updated_comment) - updated_comment.is_liked=comment.has_reaction(user.get("id"), Reaction.LIKE) - updated_comment.is_disliked=comment.has_reaction(user.get("id"), Reaction.DISLIKE) + updated_comment.is_liked = comment.has_reaction(user.get("id"), Reaction.LIKE) + updated_comment.is_disliked = comment.has_reaction(user.get("id"), Reaction.DISLIKE) return updated_comment @@ -387,9 +387,9 @@ async def like_comment( ) .first() ) - comment = CommentGet.model_validate(comment) - comment.is_liked = (reaction == Reaction.LIKE) - comment.is_disliked = (reaction == Reaction.DISLIKE) + + comment.is_liked = reaction == Reaction.LIKE + comment.is_disliked = reaction == Reaction.DISLIKE if existing_reaction and existing_reaction.reaction != reaction: new_reaction = CommentReaction.update(session=db.session, id=existing_reaction.uuid, reaction=reaction) @@ -399,4 +399,4 @@ async def like_comment( comment.is_disliked = False comment.is_liked = False CommentReaction.delete(session=db.session, id=existing_reaction.uuid) - return comment + return CommentGet.model_validate(comment) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index 26e72c5..1a51028 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -90,6 +90,7 @@ async def update_lecturer_rating( return response_validated + @lecturer.get("/timetable-id/{timetable_id}", response_model=LecturerGet) async def get_lecturer_by_timetable_id(timetable_id: int) -> LecturerGet: """ diff --git a/requirements.dev.txt b/requirements.dev.txt index e51c72c..336b8df 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,5 +1,5 @@ autoflake -black +black==23.11.0 httpx isort pytest diff --git a/tests/conftest.py b/tests/conftest.py index afb64a8..029db70 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -148,7 +148,7 @@ def _create_reaction(user_id: int, react: Reaction): dbsession.add(reaction) dbsession.commit() created_reactions.append(reaction) - + yield _create_reaction for reaction in created_reactions: diff --git a/tests/test_routes/test_comment.py b/tests/test_routes/test_comment.py index 3a82873..0ea2692 100644 --- a/tests/test_routes/test_comment.py +++ b/tests/test_routes/test_comment.py @@ -210,7 +210,9 @@ def test_create_comment(client, dbsession, lecturers, body, lecturer_n, response (None, None, None), # anonymous ], ) -def test_get_comment_with_reaction(client, comment, reaction_data, expected_reaction, comment_user_id, comment_reaction): +def test_get_comment_with_reaction( + client, comment, reaction_data, expected_reaction, comment_user_id, comment_reaction +): comment.user_id = comment_user_id if reaction_data: diff --git a/tests/test_routes/test_lecturer.py b/tests/test_routes/test_lecturer.py index f28fee7..64b284d 100644 --- a/tests/test_routes/test_lecturer.py +++ b/tests/test_routes/test_lecturer.py @@ -29,6 +29,7 @@ def test_create_lecturer(client, dbsession, response_status): lecturer = dbsession.query(Lecturer).filter(Lecturer.timetable_id == 0).one_or_none() assert lecturer is None + @pytest.mark.parametrize( 'lecturer_n, response_status', [ @@ -377,7 +378,6 @@ def test_lecturer_rating_update(client, dbsession, body, response_status): response = client.patch('/lecturer/import_rating', json=[body]) if response_status == status.HTTP_200_OK: - response_dict = response.json() assert isinstance(response_dict, dict)