-
Notifications
You must be signed in to change notification settings - Fork 3
Get comment reaction #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get comment reaction #156
Changes from all commits
9f4eb62
8c5a15e
c5358ba
28f1edd
d558235
0388ac0
533a554
b53352c
bf3657c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,23 @@ def comment(dbsession, lecturer): | |
| dbsession.commit() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. красиво сделал, мне нравится |
||
| def comment_reaction(dbsession, comment): | ||
| created_reactions = [] | ||
|
|
||
| def _create_reaction(user_id: int, react: Reaction): | ||
| reaction = CommentReaction(user_id=user_id, comment_uuid=comment.uuid, reaction=react) | ||
| dbsession.add(reaction) | ||
| dbsession.commit() | ||
| created_reactions.append(reaction) | ||
|
|
||
| yield _create_reaction | ||
|
|
||
| for reaction in created_reactions: | ||
| dbsession.delete(reaction) | ||
| dbsession.commit() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def unreviewed_comment(dbsession, lecturer): | ||
| _comment = Comment( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import datetime | ||
| import logging | ||
| import uuid | ||
|
|
||
| import pytest | ||
| from starlette import status | ||
|
|
@@ -196,13 +195,39 @@ def test_create_comment(client, dbsession, lecturers, body, lecturer_n, response | |
| assert user_comment is not None | ||
|
|
||
|
|
||
| def test_get_comment(client, comment): | ||
| @pytest.mark.parametrize( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. здесь вроде норм, я потестил, все работает |
||
| "reaction_data, expected_reaction, comment_user_id", | ||
| [ | ||
| (None, None, 0), | ||
| ((0, Reaction.LIKE), "is_liked", 0), # my like on my comment | ||
| ((0, Reaction.DISLIKE), "is_disliked", 0), | ||
| ((999, Reaction.LIKE), None, 0), # someone else's like on my comment | ||
| ((999, Reaction.DISLIKE), None, 0), | ||
| ((0, Reaction.LIKE), "is_liked", 999), # my like on someone else's comment | ||
| ((0, Reaction.DISLIKE), "is_disliked", 999), | ||
| ((333, Reaction.LIKE), None, 999), # someone else's like on another person's comment | ||
| ((333, Reaction.DISLIKE), None, 999), | ||
| (None, None, None), # anonymous | ||
| ], | ||
| ) | ||
| 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: | ||
| user_id, reaction_type = reaction_data | ||
| comment_reaction(user_id, reaction_type) | ||
|
|
||
| response_comment = client.get(f'{url}/{comment.uuid}') | ||
| print("1") | ||
| assert response_comment.status_code == status.HTTP_200_OK | ||
| random_uuid = uuid.uuid4() | ||
| response = client.get(f'{url}/{random_uuid}') | ||
| assert response.status_code == status.HTTP_404_NOT_FOUND | ||
|
|
||
| if response_comment: | ||
| data = response_comment.json() | ||
| if expected_reaction: | ||
| assert data[expected_reaction] | ||
| else: | ||
| assert data["is_liked"] == False | ||
| assert data["is_disliked"] == False | ||
| else: | ||
| assert response_comment.status_code == status.HTTP_404_NOT_FOUND | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.