Fix aggregator tests to use users and time-machine
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
from datetime import timedelta
|
||||
from django.contrib.auth import get_user_model
|
||||
from datetime import timedelta, datetime
|
||||
|
||||
import pytest
|
||||
import time_machine
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from music.aggregators import scrobble_counts, top_tracks, week_of_scrobbles
|
||||
from scrobbles.models import Scrobble
|
||||
from profiles.models import UserProfile
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
|
||||
def build_scrobbles(client, request_data, num=7, spacing=2):
|
||||
@ -23,14 +24,16 @@ def build_scrobbles(client, request_data, num=7, spacing=2):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@time_machine.travel(datetime(2022, 3, 4, 1, 24))
|
||||
def test_scrobble_counts_data(client, mopidy_track_request_data):
|
||||
build_scrobbles(client, mopidy_track_request_data)
|
||||
count_dict = scrobble_counts()
|
||||
user = get_user_model().objects.first()
|
||||
count_dict = scrobble_counts(user)
|
||||
assert count_dict == {
|
||||
'alltime': 7,
|
||||
'month': 7,
|
||||
'month': 2,
|
||||
'today': 1,
|
||||
'week': 2,
|
||||
'week': 3,
|
||||
'year': 7,
|
||||
}
|
||||
|
||||
@ -38,7 +41,8 @@ def test_scrobble_counts_data(client, mopidy_track_request_data):
|
||||
@pytest.mark.django_db
|
||||
def test_week_of_scrobbles_data(client, mopidy_track_request_data):
|
||||
build_scrobbles(client, mopidy_track_request_data, 7, 1)
|
||||
week = week_of_scrobbles()
|
||||
user = get_user_model().objects.first()
|
||||
week = week_of_scrobbles(user)
|
||||
assert list(week.values()) == [1, 1, 1, 1, 1, 1, 1]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user