Skip to content

Commit

Permalink
[PAY-2714] track_added_to_purchased_album noti test (#8616)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored May 25, 2024
1 parent 45d3409 commit 8289783
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 1 deletion.
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):
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

0 comments on commit 8289783

Please sign in to comment.