-
Notifications
You must be signed in to change notification settings - Fork 111
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
[PAY-2714] track_added_to_purchased_album noti test #8616
Merged
Merged
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
155 changes: 155 additions & 0 deletions
155
...tion_tests/queries/test_notifications/test_track_added_to_purchased_album_notification.py
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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import logging | ||
|
||
from integration_tests.utils import populate_mock_db | ||
from src.api.v1.utils.extend_notification import extend_notification | ||
from src.models.users.usdc_purchase import PurchaseType | ||
from src.queries.get_notifications import NotificationType, get_notifications | ||
from src.utils.db_session import get_db | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def test_get_track_added_to_purchased_album_notifications(app): | ||
with app.app_context(): | ||
db_mock = get_db() | ||
|
||
test_entities = { | ||
"users": [{"user_id": i + 1} for i in range(2)], | ||
"tracks": [{"track_id": 6, "owner_id": 1}], | ||
"playlists": [ | ||
{ | ||
"playlist_id": 5, | ||
"playlist_owner_id": 1, | ||
"playlist_name": "name", | ||
"description": "description", | ||
"is_album": True, | ||
"is_stream_gated": True, | ||
"stream_conditions": { | ||
"usdc_purchase": { | ||
"price": 100, | ||
"splits": { | ||
"7gfRGGdp89N9g3mCsZjaGmDDRdcTnZh9u3vYyBab2tRy": 1000000 | ||
}, | ||
} | ||
}, | ||
"playlist_contents": { | ||
"track_ids": [ | ||
{"track": 6, "time": 1}, | ||
] | ||
}, | ||
} | ||
], | ||
"usdc_purchases": [ | ||
{ | ||
"slot": 4, | ||
"buyer_user_id": 2, | ||
"seller_user_id": 1, | ||
"amount": 1000000, | ||
"content_type": PurchaseType.album, | ||
"content_id": 5, | ||
} | ||
], | ||
} | ||
populate_mock_db(db_mock, test_entities) | ||
|
||
test_actions = { | ||
"playlist_tracks": [ | ||
{"playlist_id": 5, "track_id": 6}, | ||
], | ||
} | ||
populate_mock_db(db_mock, test_actions) | ||
|
||
with db_mock.scoped_session() as session: | ||
args = { | ||
"limit": 10, | ||
"user_id": 2, | ||
"valid_types": [NotificationType.TRACK_ADDED_TO_PURCHASED_ALBUM], | ||
} | ||
u2_notifications = get_notifications(session, args) | ||
assert len(u2_notifications) == 1 | ||
assert ( | ||
u2_notifications[0]["group_id"] | ||
== "track_added_to_purchased_album:playlist_id:5:track_id:6" | ||
) | ||
assert u2_notifications[0]["is_seen"] == False | ||
assert len(u2_notifications[0]["actions"]) == 1 | ||
assert u2_notifications[0]["actions"][0]["data"] == { | ||
"track_id": 6, | ||
"playlist_id": 5, | ||
"playlist_owner_id": 1, | ||
} | ||
|
||
|
||
def test_extended_track_added_to_purchased_album_notification(app): | ||
with app.app_context(): | ||
db_mock = get_db() | ||
|
||
test_entities = { | ||
"users": [{"user_id": i + 1} for i in range(2)], | ||
"tracks": [{"track_id": 6, "owner_id": 1}], | ||
"playlists": [ | ||
{ | ||
"playlist_id": 5, | ||
"playlist_owner_id": 1, | ||
"playlist_name": "name", | ||
"description": "description", | ||
"is_album": True, | ||
"is_stream_gated": True, | ||
"stream_conditions": { | ||
"usdc_purchase": { | ||
"price": 100, | ||
"splits": { | ||
"7gfRGGdp89N9g3mCsZjaGmDDRdcTnZh9u3vYyBab2tRy": 1000000 | ||
}, | ||
} | ||
}, | ||
"playlist_contents": { | ||
"track_ids": [ | ||
{"track": 6, "time": 1}, | ||
] | ||
}, | ||
} | ||
], | ||
"usdc_purchases": [ | ||
{ | ||
"slot": 4, | ||
"buyer_user_id": 2, | ||
"seller_user_id": 1, | ||
"amount": 1000000, | ||
"content_type": PurchaseType.album, | ||
"content_id": 5, | ||
} | ||
], | ||
} | ||
populate_mock_db(db_mock, test_entities) | ||
|
||
test_actions = { | ||
"playlist_tracks": [ | ||
{"playlist_id": 5, "track_id": 6}, | ||
], | ||
} | ||
populate_mock_db(db_mock, test_actions) | ||
|
||
with db_mock.scoped_session() as session: | ||
args = { | ||
"limit": 10, | ||
"user_id": 2, | ||
"valid_types": [NotificationType.TRACK_ADDED_TO_PURCHASED_ALBUM], | ||
} | ||
u2_notifications = get_notifications(session, args) | ||
extended_notification = extend_notification(u2_notifications[0]) | ||
assert extended_notification["type"] == "track_added_to_purchased_album" | ||
assert ( | ||
extended_notification["group_id"] | ||
== "track_added_to_purchased_album:playlist_id:5:track_id:6" | ||
) | ||
assert extended_notification["actions"][0]["specifier"] == "ML51L" | ||
assert ( | ||
extended_notification["actions"][0]["type"] | ||
== "track_added_to_purchased_album" | ||
) | ||
assert extended_notification["actions"][0]["data"] == { | ||
"track_id": "AnlGe", | ||
"playlist_id": "pnagD", | ||
"playlist_owner_id": "7eP5n", | ||
} |
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
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.
should we be populating this from the
playlist_contents
fields in the playlists instead? seems annoying to have to manually populate both tablesThere 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.
hmm potentially... but i feel like there might be cases where we'd want separate control. kinda in favor of just sticking to existing patterns? most tests will explicitly use or not use
playlist_tracks
i think.