-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: query_simplified_user_actions and add test cases #15
Open
dtgoitia
wants to merge
1
commit into
txomon:master
Choose a base branch
from
dtgoitia:test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,12 +551,61 @@ def test_get_opposite_dub_action(input, output): | |
assert output == get_opposite_dub_action(input) | ||
|
||
|
||
@pytest.mark.parametrize('loops, output', ( | ||
(1, {Action.upvote, }), | ||
(2, {Action.downvote, }), | ||
(3, {Action.upvote, }), | ||
pytest.param(4, {Action.upvote, Action.skip}, marks=pytest.mark.xfail( | ||
reason='The query is not complete enough to only aggregate upvotes and downvotes')), | ||
@pytest.mark.parametrize('user_action, expected_result', ( | ||
([ | ||
{'user_id': 1, 'action': 'upvote'}, | ||
], { | ||
0: Action.upvote.name, | ||
}), | ||
([ | ||
{'user_id': 1, 'action': 'upvote'}, | ||
{'user_id': 1, 'action': 'downvote'}, | ||
], { | ||
0: Action.downvote.name, | ||
}), | ||
([ | ||
{'user_id': 1, 'action': 'upvote'}, | ||
{'user_id': 1, 'action': 'skip'}, | ||
], { | ||
0: Action.upvote.name, | ||
1: Action.skip.name, | ||
}), | ||
([ | ||
{'user_id': 1, 'action': 'upvote'}, | ||
{'user_id': 1, 'action': 'downvote'}, | ||
{'user_id': 1, 'action': 'skip'}, | ||
], { | ||
0: Action.downvote.name, | ||
1: Action.skip.name, | ||
}), | ||
([ | ||
{'user_id': 1, 'action': 'upvote'}, | ||
{'user_id': 2, 'action': 'upvote'}, | ||
], { | ||
0: Action.upvote.name, | ||
1: Action.upvote.name, | ||
}), | ||
([ | ||
{'user_id': 1, 'action': 'upvote'}, | ||
{'user_id': 2, 'action': 'upvote'}, | ||
{'user_id': 1, 'action': 'downvote'}, | ||
{'user_id': 1, 'action': 'skip'}, | ||
], { | ||
0: Action.upvote.name, | ||
1: Action.downvote.name, | ||
2: Action.skip.name, | ||
}), | ||
([ | ||
{'user_id': 2, 'action': 'upvote'}, | ||
{'user_id': 3, 'action': 'upvote'}, | ||
{'user_id': 4, 'action': 'downvote'}, | ||
{'user_id': 1, 'action': 'skip'}, | ||
], { | ||
0: Action.upvote.name, | ||
1: Action.upvote.name, | ||
2: Action.downvote.name, | ||
3: Action.skip.name, | ||
}), | ||
)) | ||
@pytest.mark.asyncio | ||
async def test_query_simplified_user_actions( | ||
|
@@ -565,16 +614,18 @@ async def test_query_simplified_user_actions( | |
user_generator, | ||
playback_generator, | ||
user_action_generator, | ||
loops, | ||
output | ||
): | ||
actions = ['upvote', 'downvote', 'upvote', 'skip'] | ||
user_action, | ||
expected_result): | ||
track = await track_generator() | ||
user = await user_generator() | ||
playback = await playback_generator(user=user, track=track) | ||
for _, action in zip(range(loops), actions): | ||
await user_action_generator(user=user, playback=playback, action=action) | ||
registered_user = await user_generator() | ||
await user_generator() | ||
await user_generator() | ||
await user_generator() | ||
playback = await playback_generator(user=registered_user, track=track) | ||
|
||
user_actions = await query_simplified_user_actions(playback_id=playback['id'], conn=db_conn) | ||
result = {ua['action'] for ua in user_actions} | ||
assert result == output | ||
for action in user_action: | ||
await user_action_generator(user={'id': action['user_id']}, playback=playback, action=action['action']) | ||
|
||
simplified_user_action = await query_simplified_user_actions(playback_id=playback['id'], conn=db_conn) | ||
actual_result = {i: user_action['action'] for i, user_action in enumerate(simplified_user_action)} | ||
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. I don't understand why compare a dict instead of the list of the result direclty. Why are you transforming the result to check it? |
||
assert expected_result == actual_result |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked a safer way to execute this query? you are literally rendering the parameter directly, instead of escaping it or using it as a parameter. I don't know if aiopg the library we are using can do it but please have a look
https://chartio.com/resources/tutorials/how-to-execute-raw-sql-in-sqlalchemy/