Update TODOs and fix tests
This commit is contained in:
@ -2,6 +2,10 @@ import json
|
||||
import pytest
|
||||
|
||||
from scrobbles.models import Scrobble
|
||||
from rest_framework.authtoken.models import Token
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class MopidyRequest:
|
||||
@ -55,6 +59,12 @@ class MopidyRequest:
|
||||
return json.dumps(self.request_data)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def valid_auth_token():
|
||||
user = User.objects.create(email='test@exmaple.com')
|
||||
return Token.objects.create(user=user).key
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mopidy_track_request_data():
|
||||
return MopidyRequest().request_json
|
||||
|
||||
@ -8,15 +8,19 @@ from music.models import Track
|
||||
from podcasts.models import Episode
|
||||
|
||||
|
||||
def test_get_not_allowed_from_mopidy(client):
|
||||
@pytest.mark.django_db
|
||||
def test_get_not_allowed_from_mopidy(client, valid_auth_token):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
response = client.get(url)
|
||||
headers = {'Authorization': f'Token {valid_auth_token}'}
|
||||
response = client.get(url, headers=headers)
|
||||
assert response.status_code == 405
|
||||
|
||||
|
||||
def test_bad_mopidy_request_data(client):
|
||||
@pytest.mark.django_db
|
||||
def test_bad_mopidy_request_data(client, valid_auth_token):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
response = client.post(url)
|
||||
headers = {'Authorization': f'Token {valid_auth_token}'}
|
||||
response = client.post(url, headers)
|
||||
assert response.status_code == 400
|
||||
assert (
|
||||
response.data['detail']
|
||||
@ -25,10 +29,16 @@ def test_bad_mopidy_request_data(client):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_scrobble_mopidy_track(client, mopidy_track_request_data):
|
||||
def test_scrobble_mopidy_track(
|
||||
client, mopidy_track_request_data, valid_auth_token
|
||||
):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
headers = {'Authorization': f'Token {valid_auth_token}'}
|
||||
response = client.post(
|
||||
url, mopidy_track_request_data, content_type='application/json'
|
||||
url,
|
||||
mopidy_track_request_data,
|
||||
content_type='application/json',
|
||||
headers=headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data == {'scrobble_id': 1}
|
||||
@ -40,11 +50,18 @@ def test_scrobble_mopidy_track(client, mopidy_track_request_data):
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_scrobble_mopidy_same_track_different_album(
|
||||
client, mopidy_track_request_data, mopidy_track_diff_album_request_data
|
||||
client,
|
||||
mopidy_track_request_data,
|
||||
mopidy_track_diff_album_request_data,
|
||||
valid_auth_token,
|
||||
):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
headers = {'Authorization': f'Token {valid_auth_token}'}
|
||||
response = client.post(
|
||||
url, mopidy_track_request_data, content_type='application/json'
|
||||
url,
|
||||
mopidy_track_request_data,
|
||||
content_type='application/json',
|
||||
headers=headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data == {'scrobble_id': 1}
|
||||
@ -64,10 +81,16 @@ def test_scrobble_mopidy_same_track_different_album(
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_scrobble_mopidy_podcast(client, mopidy_podcast_request_data):
|
||||
def test_scrobble_mopidy_podcast(
|
||||
client, mopidy_podcast_request_data, valid_auth_token
|
||||
):
|
||||
url = reverse('scrobbles:mopidy-websocket')
|
||||
headers = {'Authorization': f'Token {valid_auth_token}'}
|
||||
response = client.post(
|
||||
url, mopidy_podcast_request_data, content_type='application/json'
|
||||
url,
|
||||
mopidy_podcast_request_data,
|
||||
content_type='application/json',
|
||||
headers=headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data == {'scrobble_id': 1}
|
||||
|
||||
21
todos.org
21
todos.org
@ -2,7 +2,7 @@
|
||||
|
||||
A fun way to keep track of things in the project to fix or improve.
|
||||
|
||||
* TODO Move to using more robust mopidy-webhooks pacakge form pypi :improve:
|
||||
* TODO Move to using more robust mopidy-webhooks pacakge form pypi :improvement:
|
||||
** Example payloads from mopidy-webhooks
|
||||
*** Podcast playback ended
|
||||
#+begin_src json
|
||||
@ -293,4 +293,21 @@ A fun way to keep track of things in the project to fix or improve.
|
||||
}
|
||||
}
|
||||
#+end_src
|
||||
* TODO Fix Jellyfin scrobbling N+1 past 90 completion perecnt :bug:
|
||||
* TODO Fix Jellyfin music scrobbling N+1 past 90 completion perecnt :bug:
|
||||
* TODO Adjust cancel/finish task to use javascript to submit :improvement:
|
||||
* TODO Implement keeping track of week/month/year chart-toppers :improvement:
|
||||
|
||||
Maloja does this cool thing where artists and tracks get recorded as the top
|
||||
track of a given week, month or year. They get gold, silver or bronze stars for
|
||||
their place in the time period.
|
||||
|
||||
I could see this being implemented as a separate Chart table which gets
|
||||
populated at the end of a time period and has a start and end date that defines
|
||||
a period, along with a one, two, three instance.
|
||||
|
||||
Of course, it could also be a data model without a table, where it runs some fun
|
||||
calculations, stores it's values in Redis as a long-term lookup table and just
|
||||
has to re-populate when the server restarts.
|
||||
* TODO Implement a detail view for TV shows :improvement:
|
||||
* TODO Implement a detail view for Moviews :improvement:
|
||||
* TODO Consider a purge command for duplicated and stuck in-progress scrobbles :improvement:
|
||||
|
||||
@ -131,8 +131,8 @@ def scrobble_endpoint(request):
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@api_view(['POST'])
|
||||
def jellyfin_websocket(request):
|
||||
data_dict = request.data
|
||||
|
||||
@ -157,8 +157,8 @@ def jellyfin_websocket(request):
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@api_view(['POST'])
|
||||
def mopidy_websocket(request):
|
||||
try:
|
||||
data_dict = json.loads(request.data)
|
||||
@ -183,8 +183,8 @@ def mopidy_websocket(request):
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@api_view(['GET'])
|
||||
def scrobble_finish(request, uuid):
|
||||
user = request.user
|
||||
if not user.is_authenticated:
|
||||
@ -201,8 +201,8 @@ def scrobble_finish(request, uuid):
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@api_view(['GET'])
|
||||
def scrobble_cancel(request, uuid):
|
||||
user = request.user
|
||||
if not user.is_authenticated:
|
||||
|
||||
Reference in New Issue
Block a user