Skip to content
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 1 commit into from
May 25, 2024
Merged
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
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",
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
t4 = t1 - timedelta(hours=3)


def test_get_repost_notifications(app):
def test_get_usdc_purchase_notifications(app):
with app.app_context():
db_mock = get_db()

Expand Down
12 changes: 12 additions & 0 deletions packages/discovery-provider/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from src.models.playlists.album_price_history import AlbumPriceHistory
from src.models.playlists.playlist import Playlist
from src.models.playlists.playlist_route import PlaylistRoute
from src.models.playlists.playlist_track import PlaylistTrack
from src.models.rewards.challenge import Challenge
from src.models.rewards.challenge_disbursement import ChallengeDisbursement
from src.models.rewards.reward_manager import RewardManagerTransaction
Expand Down Expand Up @@ -119,6 +120,7 @@ def populate_mock_db(db, entities, block_offset=None):

tracks = entities.get("tracks", [])
playlists = entities.get("playlists", [])
playlist_tracks = entities.get("playlist_tracks", [])
users = entities.get("users", [])
developer_apps = entities.get("developer_apps", [])
grants = entities.get("grants", [])
Expand Down Expand Up @@ -296,9 +298,19 @@ def populate_mock_db(db, entities, block_offset=None):
is_image_autogenerated=playlist_meta.get(
"is_image_autogenerated", False
),
is_stream_gated=playlist_meta.get("is_stream_gated", False),
stream_conditions=playlist_meta.get("stream_conditions", None),
)
session.add(playlist)
for i, playlist_track_meta in enumerate(playlist_tracks):
Copy link
Contributor

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 tables

Copy link
Contributor Author

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.

playlist_track = PlaylistTrack(
playlist_id=playlist_track_meta.get("playlist_id", i),
track_id=playlist_track_meta.get("track_id", i),
is_removed=playlist_track_meta.get("is_removed", False),
created_at=datetime.now(),
updated_at=datetime.now(),
)
session.add(playlist_track)

for i, user_meta in enumerate(users):
user = User(
Expand Down