Verified Commit 639882bd authored by Agate's avatar Agate 💬

See #297: removed unused variables

parent 2b1c4631
......@@ -41,7 +41,6 @@ class Command(BaseCommand):
script["entrypoint"](self, **options)
def show_help(self):
indentation = 4
self.stdout.write("")
self.stdout.write("Available scripts:")
self.stdout.write("Launch with: python manage.py <script_name>")
......
......@@ -40,7 +40,6 @@ class ActionSerializer(serializers.Serializer):
return value
def validate_objects(self, value):
qs = None
if value == "all":
return self.queryset.all().order_by("id")
if type(value) in [list, tuple]:
......
import os
import json
from urllib.parse import quote_plus
import youtube_dl
from django.conf import settings
import glob
def download(
......
import datetime
import logging
import uuid
import xml
from django.conf import settings
......@@ -155,7 +154,6 @@ class SystemActor(object):
return handler(data, actor)
def handle_follow(self, ac, sender):
system_actor = self.get_actor_instance()
serializer = serializers.FollowSerializer(
data=ac, context={"follow_actor": sender}
)
......@@ -325,7 +323,6 @@ class TestActor(SystemActor):
reply_url = "https://{}/activities/note/{}".format(
settings.FEDERATION_HOSTNAME, now.timestamp()
)
reply_content = "{} Pong!".format(sender.mention_username)
reply_activity = {
"@context": [
"https://www.w3.org/ns/activitystreams",
......
......@@ -687,7 +687,7 @@ class AudioSerializer(serializers.Serializer):
def validate_url(self, v):
try:
url = v["href"]
v["href"]
except (KeyError, TypeError):
raise serializers.ValidationError("Missing href")
......
......@@ -47,7 +47,7 @@ def verify_django(django_request, public_key):
v = request.headers[h]
if v:
request.headers[h] = str(v)
prepared_request = request.prepare()
request.prepare()
return verify(request, public_key)
......
......@@ -249,7 +249,7 @@ class LibraryViewSet(
def create(self, request, *args, **kwargs):
serializer = serializers.APILibraryCreateSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
library = serializer.save()
serializer.save()
return response.Response(serializer.data, status=201)
......
......@@ -12,7 +12,6 @@ memo = memoize.Memoizer(store, namespace="instance:stats")
def get():
share_stats = preferences.get("instance__nodeinfo_stats_enabled")
private = preferences.get("instance__nodeinfo_private")
data = {
"version": "2.0",
"software": {"name": "funkwhale", "version": funkwhale_api.__version__},
......
import urllib.request
import html.parser
from bs4 import BeautifulSoup
......
import cacheops
import os
from django.db import transaction
from django.db.models import Q
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.db import migrations, models
from funkwhale_api.common.utils import rename_file
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.db import migrations, models
from funkwhale_api.common.utils import rename_file
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.db import migrations, models
from funkwhale_api.music.utils import guess_mimetype
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.db import migrations, models
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import uuid
from django.db import migrations, models
......
import os
import io
import arrow
import datetime
import tempfile
......
import ffmpeg
import os
import json
import logging
import subprocess
import unicodedata
import urllib
......
......@@ -178,7 +178,6 @@ class Command(BaseCommand):
async = options["async"]
import_handler = tasks.import_job_run.delay if async else tasks.import_job_run
batch = user.imports.create(source="shell")
total = len(paths)
errors = []
for i, path in list(enumerate(paths)):
try:
......
import acoustid
import os
import datetime
from django.core.files import File
from django.db import transaction
......
......@@ -147,7 +147,7 @@ class TagRadio(RelatedObjectRadio):
def get_queryset(self, **kwargs):
qs = super().get_queryset(**kwargs)
return Track.objects.filter(tags__in=[self.session.related_object])
return qs.filter(tags__in=[self.session.related_object])
@registry.register(name="artist")
......
......@@ -108,7 +108,7 @@ class RadioSessionTrackViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet)
assert request.user == session.user
except AssertionError:
return Response(status=status.HTTP_403_FORBIDDEN)
track = session.radio.pick()
session.radio.pick()
session_track = session.session_tracks.all().latest("id")
# self.perform_create(serializer)
# dirty override here, since we use a different serializer for creation and detail
......
......@@ -12,7 +12,6 @@ MAPPING = {
class SubsonicContentNegociation(negotiation.DefaultContentNegotiation):
def select_renderer(self, request, renderers, format_suffix=None):
path = request.path
data = request.GET or request.POST
requested_format = data.get("f", "xml")
try:
......
......@@ -158,7 +158,6 @@ class SubsonicViewSet(viewsets.GenericViewSet):
)
@find_object(music_models.Artist.objects.all())
def get_artist_info2(self, request, *args, **kwargs):
artist = kwargs.pop("obj")
payload = {"artist-info2": {}}
return response.Response(payload, status=200)
......
......@@ -7,7 +7,7 @@ from funkwhale_api.activity import utils
def test_activity_view(factories, api_client, preferences, anonymous_user):
preferences["common__api_authentication_required"] = False
favorite = factories["favorites.TrackFavorite"](user__privacy_level="everyone")
listening = factories["history.Listening"]()
factories["history.Listening"]()
url = reverse("api:v1:activity-list")
objects = utils.get_activity(anonymous_user)
serializer = serializers.AutoSerializer(objects, many=True)
......
......@@ -26,14 +26,14 @@ def string_list_pref(preferences):
],
)
def test_string_list_serializer_to_db(input, output):
s = common_preferences.StringListSerializer.to_db(input) == output
common_preferences.StringListSerializer.to_db(input) == output
@pytest.mark.parametrize(
"input,output", [("a,b,c", ["a", "b", "c"]), (None, []), ("", [])]
)
def test_string_list_serializer_to_python(input, output):
s = common_preferences.StringListSerializer.to_python(input) == output
common_preferences.StringListSerializer.to_python(input) == output
def test_string_list_pref_default(string_list_pref, preferences):
......
......@@ -47,7 +47,7 @@ def test_action_serializer_validates_objects():
def test_action_serializers_objects_clean_ids(factories):
user1 = factories["users.User"]()
user2 = factories["users.User"]()
factories["users.User"]()
data = {"objects": [user1.pk], "action": "test"}
serializer = TestSerializer(data, queryset=models.User.objects.all())
......@@ -69,8 +69,8 @@ def test_action_serializers_objects_clean_all(factories):
def test_action_serializers_save(factories, mocker):
handler = mocker.spy(TestSerializer, "handle_test")
user1 = factories["users.User"]()
user2 = factories["users.User"]()
factories["users.User"]()
factories["users.User"]()
data = {"objects": "all", "action": "test"}
serializer = TestSerializer(data, queryset=models.User.objects.all())
......@@ -82,7 +82,7 @@ def test_action_serializers_save(factories, mocker):
def test_action_serializers_filterset(factories):
user1 = factories["users.User"](is_active=False)
factories["users.User"](is_active=False)
user2 = factories["users.User"](is_active=True)
data = {"objects": "all", "action": "test", "filters": {"is_active": True}}
......
......@@ -186,7 +186,6 @@ def fake_request():
@pytest.fixture
def activity_registry():
r = record.registry
state = list(record.registry.items())
yield record.registry
record.registry.clear()
......
import uuid
from funkwhale_api.federation import activity
from funkwhale_api.federation import serializers
......
import arrow
import pytest
import uuid
from django.urls import reverse
from django.utils import timezone
......@@ -350,7 +349,7 @@ def test_library_actor_handles_follow_manual_approval(preferences, mocker, facto
def test_library_actor_handles_follow_auto_approval(preferences, mocker, factories):
preferences["federation__music_needs_approval"] = False
actor = factories["federation.Actor"]()
accept_follow = mocker.patch("funkwhale_api.federation.activity.accept_follow")
mocker.patch("funkwhale_api.federation.activity.accept_follow")
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
data = {
"actor": actor.url,
......
import pytest
import uuid
from django import db
......
import cryptography.exceptions
import io
import pytest
import requests_http_signature
......
......@@ -159,7 +159,6 @@ def test_audio_file_list_actor_page_exclude_federated_files(
db, preferences, api_client, factories
):
preferences["federation__music_needs_approval"] = False
library = actors.SYSTEM_ACTORS["library"].get_actor_instance()
tfs = factories["music.TrackFile"].create_batch(size=5, federation=True)
url = reverse("federation:music:files-list")
......@@ -188,7 +187,6 @@ def test_audio_file_list_actor_page_error_too_far(
def test_library_actor_includes_library_link(db, preferences, api_client):
actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
url = reverse("federation:instance-actors-detail", kwargs={"actor": "library"})
response = api_client.get(url)
expected_links = [
......@@ -263,7 +261,7 @@ def test_follow_library(superuser_api_client, mocker, factories, r_mock):
def test_can_list_system_actor_following(factories, superuser_api_client):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
follow1 = factories["federation.Follow"](actor=library_actor)
follow2 = factories["federation.Follow"]()
factories["federation.Follow"]()
url = reverse("api:v1:federation:libraries-following")
response = superuser_api_client.get(url)
......
import random
import json
from django.urls import reverse
from django.core.exceptions import ValidationError
from django.utils import timezone
......@@ -10,7 +8,6 @@ from funkwhale_api.history import models
def test_can_create_listening(factories):
track = factories["music.Track"]()
user = factories["users.User"]()
now = timezone.now()
l = models.Listening.objects.create(user=user, track=track)
......
......@@ -49,7 +49,6 @@ def test_fix_track_files_size(factories, mocker):
def test_fix_track_files_mimetype(factories, mocker):
name = "test.mp3"
mp3_path = os.path.join(DATA_DIR, "test.mp3")
ogg_path = os.path.join(DATA_DIR, "test.ogg")
tf1 = factories["music.TrackFile"](
......
......@@ -195,7 +195,7 @@ def test_import_batch_notifies_followers(factories, mocker):
f1 = factories["federation.Follow"](approved=True, target=library_actor)
f2 = factories["federation.Follow"](approved=False, target=library_actor)
f3 = factories["federation.Follow"]()
factories["federation.Follow"]()
mocked_deliver = mocker.patch("funkwhale_api.federation.activity.deliver")
batch = factories["music.ImportBatch"]()
......
import json
from django.urls import reverse
from funkwhale_api.music import models
......
......@@ -44,7 +44,6 @@ def test_set_acoustid_on_track_file(factories, mocker, preferences):
def test_set_acoustid_on_track_file_required_high_score(factories, mocker):
track_file = factories["music.TrackFile"](acoustid_track_id=None)
id = "e475bf79-c1ce-4441-bed7-1e33f226c0a2"
payload = {"results": [{"score": 0.79}], "status": "ok"}
m = mocker.patch("acoustid.match", return_value=payload)
r = tasks.set_acoustid_on_track_file(track_file_id=track_file.pk)
......@@ -159,7 +158,6 @@ def test_import_job_skip_if_already_exists(artists, albums, tracks, factories, m
)
job = factories["music.FileImportJob"](audio_file__path=path)
f = job.audio_file
tasks.import_job_run(import_job_id=job.pk)
job.refresh_from_db()
......@@ -219,7 +217,6 @@ def test_update_album_cover_mbid(factories, mocker):
def test_update_album_cover_file_data(factories, mocker):
path = os.path.join(DATA_DIR, "test.mp3")
album = factories["music.Album"](cover="", mbid=None)
tf = factories["music.TrackFile"](track__album=album)
......@@ -236,7 +233,6 @@ def test_update_album_cover_file_data(factories, mocker):
@pytest.mark.parametrize("ext,mimetype", [("jpg", "image/jpeg"), ("png", "image/png")])
def test_update_album_cover_file_cover_separate_file(ext, mimetype, factories, mocker):
mocker.patch("funkwhale_api.music.tasks.IMAGE_TYPES", [(ext, mimetype)])
path = os.path.join(DATA_DIR, "test.mp3")
image_path = os.path.join(DATA_DIR, "cover.{}".format(ext))
with open(image_path, "rb") as f:
image_content = f.read()
......
......@@ -334,7 +334,7 @@ def test_import_job_viewset_get_queryset_upload_filters_user(
logged_in_api_client.user.permission_upload = True
logged_in_api_client.user.save()
job = factories["music.ImportJob"]()
factories["music.ImportJob"]()
url = reverse("api:v1:import-jobs-list")
response = logged_in_api_client.get(url)
......@@ -347,7 +347,7 @@ def test_import_batch_viewset_get_queryset_upload_filters_user(
logged_in_api_client.user.permission_upload = True
logged_in_api_client.user.save()
job = factories["music.ImportBatch"]()
factories["music.ImportBatch"]()
url = reverse("api:v1:import-batches-list")
response = logged_in_api_client.get(url)
......
import json
from django.urls import reverse
from funkwhale_api.music import models
......
import json
from django.urls import reverse
from funkwhale_api.musicbrainz import api
......
......@@ -53,7 +53,7 @@ def test_update_insert_is_called_when_index_is_provided(factories, mocker):
second = factories["playlists.PlaylistTrack"](playlist=playlist, index=1)
insert = mocker.spy(models.Playlist, "insert")
factories["playlists.Playlist"]()
track = factories["music.Track"]()
factories["music.Track"]()
serializer = serializers.PlaylistTrackWriteSerializer(
second, data={"playlist": playlist.pk, "track": second.track.pk, "index": 0}
)
......
import json
import pytest
from django.urls import reverse
......@@ -13,7 +12,7 @@ def test_can_create_playlist_via_api(logged_in_api_client):
url = reverse("api:v1:playlists-list")
data = {"name": "test", "privacy_level": "everyone"}
response = logged_in_api_client.post(url, data)
logged_in_api_client.post(url, data)
playlist = logged_in_api_client.user.playlists.latest("id")
assert playlist.name == "test"
......@@ -38,7 +37,7 @@ def test_playlist_inherits_user_privacy(logged_in_api_client):
data = {"name": "test"}
response = logged_in_api_client.post(url, data)
logged_in_api_client.post(url, data)
playlist = user.playlists.latest("id")
assert playlist.privacy_level == user.privacy_level
......@@ -80,7 +79,7 @@ def test_only_can_add_track_on_own_playlist_via_api(factories, logged_in_api_cli
def test_deleting_plt_updates_indexes(mocker, factories, logged_in_api_client):
remove = mocker.spy(models.Playlist, "remove")
track = factories["music.Track"]()
factories["music.Track"]()
plt = factories["playlists.PlaylistTrack"](
index=0, playlist__user=logged_in_api_client.user
)
......
......@@ -15,7 +15,7 @@ class NoopFilter(filters.RadioFilter):
def test_most_simple_radio_does_not_filter_anything(factories):
tracks = factories["music.Track"].create_batch(3)
factories["music.Track"].create_batch(3)
radio = factories["radios.Radio"](config=[{"type": "noop"}])
assert radio.version == 0
......
......@@ -75,7 +75,6 @@ def test_can_get_choices_for_custom_radio(factories):
files = factories["music.TrackFile"].create_batch(5, track__artist=artist)
tracks = [f.track for f in files]
wrong_files = factories["music.TrackFile"].create_batch(5)
wrong_tracks = [f.track for f in wrong_files]
session = factories["radios.CustomRadioSession"](
custom_radio__config=[{"type": "artist", "ids": [artist.pk]}]
......@@ -115,13 +114,12 @@ def test_can_start_custom_radio_from_api(logged_in_client, factories):
def test_can_use_radio_session_to_filter_choices(factories):
files = factories["music.TrackFile"].create_batch(30)
tracks = [f.track for f in files]
user = factories["users.User"]()
radio = radios.RandomRadio()
session = radio.start_session(user)
for i in range(30):
p = radio.pick()
radio.pick()
# ensure 30 differents tracks have been suggested
tracks_id = [
......@@ -186,7 +184,6 @@ def test_can_start_artist_radio(factories):
user = factories["users.User"]()
artist = factories["music.Artist"]()
wrong_files = factories["music.TrackFile"].create_batch(5)
wrong_tracks = [f.track for f in wrong_files]
good_files = factories["music.TrackFile"].create_batch(5, track__artist=artist)
good_tracks = [f.track for f in good_files]
......@@ -201,7 +198,6 @@ def test_can_start_tag_radio(factories):
user = factories["users.User"]()
tag = factories["taggit.Tag"]()
wrong_files = factories["music.TrackFile"].create_batch(5)
wrong_tracks = [f.track for f in wrong_files]
good_files = factories["music.TrackFile"].create_batch(5, track__tags=[tag])
good_tracks = [f.track for f in good_files]
......@@ -236,7 +232,7 @@ def test_can_start_less_listened_radio(factories):
good_files = factories["music.TrackFile"].create_batch(5)
good_tracks = [f.track for f in good_files]
radio = radios.LessListenedRadio()
session = radio.start_session(user)
radio.start_session(user)
for i in range(5):
assert radio.pick() in good_tracks
......@@ -25,7 +25,6 @@ def test_auth_with_password_hex(api_request, factories):
user = factories["users.User"]()
user.subsonic_api_token = "password"
user.save()
token = authentication.get_token(salt, "password")
request = api_request.get(
"/",
{
......@@ -49,7 +48,6 @@ def test_auth_with_password_cleartext(api_request, factories):
user = factories["users.User"]()
user.subsonic_api_token = "password"
user.save()
token = authentication.get_token(salt, "password")
request = api_request.get("/", {"u": user.username, "p": "password"})
authenticator = authentication.SubsonicAuthentication()
......@@ -63,7 +61,6 @@ def test_auth_with_inactive_users(api_request, factories):
user = factories["users.User"](is_active=False)
user.subsonic_api_token = "password"
user.save()
token = authentication.get_token(salt, "password")
request = api_request.get("/", {"u": user.username, "p": "password"})
authenticator = authentication.SubsonicAuthentication()
......
......@@ -5,8 +5,6 @@ import pytest
from django.utils import timezone
from django.urls import reverse
from rest_framework.response import Response
from funkwhale_api.music import models as music_models
from funkwhale_api.music import views as music_views
from funkwhale_api.subsonic import renderers
......@@ -80,7 +78,7 @@ def test_ping(f, db, api_client):
def test_get_artists(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-get-artists")
assert url.endswith("getArtists") is True
artists = factories["music.Artist"].create_batch(size=10)
factories["music.Artist"].create_batch(size=10)
expected = {
"artists": serializers.GetArtistsSerializer(
music_models.Artist.objects.all()
......@@ -97,7 +95,7 @@ def test_get_artist(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-get-artist")
assert url.endswith("getArtist") is True
artist = factories["music.Artist"]()
albums = factories["music.Album"].create_batch(size=3, artist=artist)
factories["music.Album"].create_batch(size=3, artist=artist)
expected = {"artist": serializers.GetArtistSerializer(artist).data}
response = logged_in_api_client.get(url, {"id": artist.pk})
......@@ -124,7 +122,7 @@ def test_get_album(f, db, logged_in_api_client, factories):
assert url.endswith("getAlbum") is True
artist = factories["music.Artist"]()
album = factories["music.Album"](artist=artist)
tracks = factories["music.Track"].create_batch(size=3, album=album)
factories["music.Track"].create_batch(size=3, album=album)
expected = {"album": serializers.GetAlbumSerializer(album).data}
response = logged_in_api_client.get(url, {"f": f, "id": album.pk})
......@@ -166,7 +164,7 @@ def test_unstar(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-unstar")
assert url.endswith("unstar") is True
track = factories["music.Track"]()
favorite = factories["favorites.TrackFavorite"](
factories["favorites.TrackFavorite"](
track=track, user=logged_in_api_client.user
)
response = logged_in_api_client.get(url, {"f": f, "id": track.pk})
......@@ -283,7 +281,7 @@ def test_update_playlist(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-update-playlist")
assert url.endswith("updatePlaylist") is True
playlist = factories["playlists.Playlist"](user=logged_in_api_client.user)
plt = factories["playlists.PlaylistTrack"](index=0, playlist=playlist)
factories["playlists.PlaylistTrack"](index=0, playlist=playlist)
new_track = factories["music.Track"]()
response = logged_in_api_client.get(
url,
......@@ -350,7 +348,7 @@ def test_get_music_folders(f, db, logged_in_api_client, factories):
def test_get_indexes(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-get-indexes")
assert url.endswith("getIndexes") is True
artists = factories["music.Artist"].create_batch(size=10)
factories["music.Artist"].create_batch(size=10)
expected = {
"indexes": serializers.GetArtistsSerializer(
music_models.Artist.objects.all()
......@@ -384,5 +382,5 @@ def test_scrobble(factories, logged_in_api_client):
assert response.status_code == 200
l = logged_in_api_client.user.listenings.latest("id")