Skip to content

Commit

Permalink
Fix unlisted tracks in track upload challenge (#2382)
Browse files Browse the repository at this point in the history
* Fix unlisted tracks in track upload challenge

* PR revisions

* Fix lint
  • Loading branch information
piazzatron committed Jan 25, 2022
1 parent 1087b76 commit d54f329
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,37 @@ def test_track_upload_challenge(app):
updated_at=today,
)

unlisted_track = Track(
blockhash="0x3",
blocknumber=30000001,
txhash="cba",
owner_id=1,
track_id=5,
route_id="5",
track_segments=[],
is_unlisted=True,
is_current=True,
is_delete=False,
created_at=today,
updated_at=today,
)

stem = Track(
blockhash="0x3",
blocknumber=30000001,
txhash="stem",
owner_id=1,
track_id=6,
route_id="6",
track_segments=[],
is_unlisted=False,
is_current=True,
is_delete=False,
created_at=today,
updated_at=today,
stem_of={"parent_track_id": 4, "category": "bass"},
)

with db.scoped_session() as session:
bus = ChallengeEventBus(redis_conn)

Expand Down Expand Up @@ -135,6 +166,21 @@ def test_track_upload_challenge(app):
assert user_challenge.current_step_count == 1
assert not user_challenge.is_complete

# Ensure unlisted tracks and stems are not counted
session.add(unlisted_track)
bus.dispatch(ChallengeEvent.track_upload, 30000001, 1)
session.add(stem)
bus.dispatch(ChallengeEvent.track_upload, 30000001, 1)
bus.flush()
bus.process_events(session)
user_challenge = track_upload_challenge_manager.get_user_challenge_state(
session, ["1"]
)[0]

# Ensure stem is not counted

assert user_challenge.current_step_count == 1

# Process two more dummy events to reach the step count (i.e. 3) for completion
session.add(track3)
bus.dispatch(ChallengeEvent.track_upload, 30000001, 1)
Expand Down
2 changes: 2 additions & 0 deletions discovery-provider/src/challenges/track_upload_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _get_num_track_uploads_by_user(
Track.blocknumber >= block_number,
Track.is_current == True,
Track.is_delete == False,
Track.is_unlisted == False,
Track.stem_of == None,
)
.all()
)
Expand Down

0 comments on commit d54f329

Please sign in to comment.