Verified Commit 799386c2 authored by Agate's avatar Agate 💬

See #297: removed a lot of unused variables

parent 9bea804f
......@@ -24,13 +24,6 @@ def scan_from_account_name(account_name):
except serializers.ValidationError:
return {"webfinger": {"errors": ["Invalid account string"]}}
system_library = actors.SYSTEM_ACTORS["library"].get_actor_instance()
library = (
models.Library.objects.filter(
actor__domain=domain, actor__preferred_username=username
)
.select_related("actor")
.first()
)
data["local"] = {"following": False, "awaiting_approval": False}
try:
follow = models.Follow.objects.get(
......
......@@ -21,7 +21,7 @@ from . import (
serializers,
tasks,
utils,
webfinger
webfinger,
)
......@@ -57,7 +57,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet):
handler = getattr(system_actor, "{}_inbox".format(request.method.lower()))
try:
data = handler(request.data, actor=request.actor)
handler(request.data, actor=request.actor)
except NotImplementedError:
return response.Response(status=405)
return response.Response({}, status=200)
......@@ -67,7 +67,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet):
system_actor = self.get_object()
handler = getattr(system_actor, "{}_outbox".format(request.method.lower()))
try:
data = handler(request.data, actor=request.actor)
handler(request.data, actor=request.actor)
except NotImplementedError:
return response.Response(status=405)
return response.Response({}, status=200)
......
......@@ -67,7 +67,6 @@ class Command(BaseCommand):
try:
audio_file = tf.get_audio_file()
if audio_file:
with audio_file as f:
data = utils.get_audio_file_data(audio_file)
tf.bitrate = data["bitrate"]
tf.duration = data["length"]
......
......@@ -67,7 +67,7 @@ class APIModelMixin(models.Model):
try:
cleaned_key, cleaned_value = mapping.from_musicbrainz(key, value)
cleaned_data[cleaned_key] = cleaned_value
except KeyError as e:
except KeyError:
pass
return cleaned_data
......@@ -134,9 +134,7 @@ def import_tracks(instance, cleaned_data, raw_data):
track_cleaned_data = Track.clean_musicbrainz_data(track_data["recording"])
track_cleaned_data["album"] = instance
track_cleaned_data["position"] = int(track_data["position"])
track = importers.load(
Track, track_cleaned_data, track_data, Track.import_hooks
)
importers.load(Track, track_cleaned_data, track_data, Track.import_hooks)
class AlbumQuerySet(models.QuerySet):
......
......@@ -457,9 +457,7 @@ class SubmitViewSet(viewsets.ViewSet):
import_request = self.get_import_request(data)
artist_data = api.artists.get(id=data["artistId"])["artist"]
cleaned_data = models.Artist.clean_musicbrainz_data(artist_data)
artist = importers.load(
models.Artist, cleaned_data, artist_data, import_hooks=[]
)
importers.load(models.Artist, cleaned_data, artist_data, import_hooks=[])
import_data = []
batch = None
......
......@@ -11,9 +11,9 @@ def test_get_activity(factories):
def test_get_activity_honors_privacy_level(factories, anonymous_user):
listening = factories["history.Listening"](user__privacy_level="me")
factories["history.Listening"](user__privacy_level="me")
favorite1 = factories["favorites.TrackFavorite"](user__privacy_level="everyone")
favorite2 = factories["favorites.TrackFavorite"](user__privacy_level="instance")
factories["favorites.TrackFavorite"](user__privacy_level="instance")
objects = list(utils.get_activity(anonymous_user))
assert objects == [favorite1]
......@@ -5,7 +5,7 @@ from funkwhale_api.activity import serializers, 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")
factories["favorites.TrackFavorite"](user__privacy_level="everyone")
factories["history.Listening"]()
url = reverse("api:v1:activity-list")
objects = utils.get_activity(anonymous_user)
......
......@@ -55,6 +55,5 @@ def test_broadcast_track_favorite_to_instance_activity_private(factories, mocker
favorite = factories["favorites.TrackFavorite"](user__privacy_level="me")
data = serializers.TrackFavoriteActivitySerializer(favorite).data
consumer = activities.broadcast_track_favorite_to_instance_activity
message = {"type": "event.send", "text": "", "data": data}
consumer(data=data, obj=favorite)
p.assert_not_called()
......@@ -48,9 +48,7 @@ def test_get_actor_refresh(factories, preferences, mocker):
payload = serializers.ActorSerializer(actor).data
# actor changed their username in the meantime
payload["preferredUsername"] = "New me"
get_data = mocker.patch(
"funkwhale_api.federation.actors.get_actor_data", return_value=payload
)
mocker.patch("funkwhale_api.federation.actors.get_actor_data", return_value=payload)
new_actor = actors.get_actor(actor.url)
assert new_actor == actor
......@@ -59,7 +57,7 @@ def test_get_actor_refresh(factories, preferences, mocker):
def test_get_library(db, settings, mocker):
get_key_pair = mocker.patch(
mocker.patch(
"funkwhale_api.federation.keys.get_key_pair",
return_value=(b"private", b"public"),
)
......@@ -92,7 +90,7 @@ def test_get_library(db, settings, mocker):
def test_get_test(db, mocker, settings):
get_key_pair = mocker.patch(
mocker.patch(
"funkwhale_api.federation.keys.get_key_pair",
return_value=(b"private", b"public"),
)
......@@ -240,7 +238,7 @@ def test_actor_is_system(username, domain, expected, nodb_factories, settings):
("test", "", actors.SYSTEM_ACTORS["test"]),
],
)
def test_actor_is_system(username, domain, expected, nodb_factories, settings):
def test_actor_system_conf(username, domain, expected, nodb_factories, settings):
if not domain:
domain = settings.FEDERATION_HOSTNAME
actor = nodb_factories["federation.Actor"](
......
......@@ -162,7 +162,7 @@ def test_follow_serializer_save(factories):
actor = factories["federation.Actor"]()
target = factories["federation.Actor"]()
data = expected = {
data = {
"id": "https://test.follow",
"type": "Follow",
"actor": actor.url,
......@@ -185,7 +185,7 @@ def test_follow_serializer_save_validates_on_context(factories):
target = factories["federation.Actor"]()
impostor = factories["federation.Actor"]()
data = expected = {
data = {
"id": "https://test.follow",
"type": "Follow",
"actor": actor.url,
......
......@@ -109,11 +109,11 @@ def test_clean_federation_music_cache_if_no_listen(preferences, factories):
lt1 = factories["federation.LibraryTrack"](with_audio_file=True)
lt2 = factories["federation.LibraryTrack"](with_audio_file=True)
lt3 = factories["federation.LibraryTrack"](with_audio_file=True)
tf1 = factories["music.TrackFile"](accessed_date=timezone.now(), library_track=lt1)
tf2 = factories["music.TrackFile"](
factories["music.TrackFile"](accessed_date=timezone.now(), library_track=lt1)
factories["music.TrackFile"](
accessed_date=timezone.now() - datetime.timedelta(minutes=61), library_track=lt2
)
tf3 = factories["music.TrackFile"](accessed_date=None, library_track=lt3)
factories["music.TrackFile"](accessed_date=None, library_track=lt3)
path1 = lt1.audio_file.path
path2 = lt2.audio_file.path
path3 = lt3.audio_file.path
......@@ -144,7 +144,7 @@ def test_clean_federation_music_cache_orphaned(settings, preferences, factories)
lt = factories["federation.LibraryTrack"](
with_audio_file=True, audio_file__path=keep_path
)
tf = factories["music.TrackFile"](library_track=lt, accessed_date=timezone.now())
factories["music.TrackFile"](library_track=lt, accessed_date=timezone.now())
tasks.clean_music_cache()
......
......@@ -3,7 +3,15 @@ from django.core.paginator import Paginator
from django.urls import reverse
from django.utils import timezone
from funkwhale_api.federation import activity, actors, models, serializers, utils, views, webfinger
from funkwhale_api.federation import (
activity,
actors,
models,
serializers,
utils,
views,
webfinger,
)
@pytest.mark.parametrize(
......@@ -152,7 +160,7 @@ def test_audio_file_list_actor_page_exclude_federated_files(
db, preferences, api_client, factories
):
preferences["federation__music_needs_approval"] = False
tfs = factories["music.TrackFile"].create_batch(size=5, federation=True)
factories["music.TrackFile"].create_batch(size=5, federation=True)
url = reverse("federation:music:files-list")
response = api_client.get(url)
......@@ -265,7 +273,7 @@ def test_can_list_system_actor_following(factories, superuser_api_client):
def test_can_list_system_actor_followers(factories, superuser_api_client):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
follow1 = factories["federation.Follow"](actor=library_actor)
factories["federation.Follow"](actor=library_actor)
follow2 = factories["federation.Follow"](target=library_actor)
url = reverse("api:v1:federation:libraries-followers")
......@@ -375,7 +383,7 @@ def test_can_update_follow_status(factories, superuser_api_client, mocker):
def test_can_filter_pending_follows(factories, superuser_api_client):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
follow = factories["federation.Follow"](target=library_actor, approved=True)
factories["federation.Follow"](target=library_actor, approved=True)
params = {"pending": True}
url = reverse("api:v1:federation:libraries-followers")
......@@ -389,7 +397,7 @@ def test_library_track_action_import(factories, superuser_api_client, mocker):
lt1 = factories["federation.LibraryTrack"]()
lt2 = factories["federation.LibraryTrack"](library=lt1.library)
lt3 = factories["federation.LibraryTrack"]()
lt4 = factories["federation.LibraryTrack"](library=lt3.library)
factories["federation.LibraryTrack"](library=lt3.library)
mocked_run = mocker.patch("funkwhale_api.music.tasks.import_batch_run.delay")
payload = {
......
......@@ -55,6 +55,5 @@ def test_broadcast_listening_to_instance_activity_private(factories, mocker):
listening = factories["history.Listening"](user__privacy_level="me")
data = serializers.ListeningActivitySerializer(listening).data
consumer = activities.broadcast_listening_to_instance_activity
message = {"type": "event.send", "text": "", "data": data}
consumer(data=data, obj=listening)
p.assert_not_called()
......@@ -6,7 +6,7 @@ from funkwhale_api.history import models
def test_can_create_listening(factories):
track = factories["music.Track"]()
user = factories["users.User"]()
l = models.Listening.objects.create(user=user, track=track)
models.Listening.objects.create(user=user, track=track)
def test_logged_in_user_can_create_listening_via_api(
......@@ -15,7 +15,7 @@ def test_logged_in_user_can_create_listening_via_api(
track = factories["music.Track"]()
url = reverse("api:v1:history:listenings-list")
response = logged_in_client.post(url, {"track": track.pk})
logged_in_client.post(url, {"track": track.pk})
listening = models.Listening.objects.latest("id")
......@@ -29,7 +29,7 @@ def test_adding_listening_calls_activity_record(
track = factories["music.Track"]()
url = reverse("api:v1:history:listenings-list")
response = logged_in_client.post(url, {"track": track.pk})
logged_in_client.post(url, {"track": track.pk})
listening = models.Listening.objects.latest("id")
......
from funkwhale_api.instance import stats
......@@ -54,7 +53,7 @@ def test_get(mocker):
"listenings",
"music_duration",
]
mocks = [
[
mocker.patch.object(stats, "get_{}".format(k), return_value=i)
for i, k in enumerate(keys)
]
......
......@@ -11,9 +11,7 @@ def test_permissions(assert_user_permission, view, permissions):
def test_nodeinfo_endpoint(db, api_client, mocker):
payload = {"test": "test"}
mocked_nodeinfo = mocker.patch(
"funkwhale_api.instance.nodeinfo.get", return_value=payload
)
mocker.patch("funkwhale_api.instance.nodeinfo.get", return_value=payload)
url = reverse("api:v1:instance:nodeinfo-2.0")
response = api_client.get(url)
ct = "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" # noqa
......
......@@ -47,7 +47,7 @@ def test_import_creates_an_import_with_correct_data(mocker, superuser_client):
mbid = "9968a9d6-8d92-4051-8f76-674e157b6eed"
video_id = "tPEE9ZwTmy0"
url = reverse("api:v1:submit-single")
response = superuser_client.post(
superuser_client.post(
url,
{
"import_url": "https://www.youtube.com/watch?v={0}".format(video_id),
......@@ -93,9 +93,7 @@ def test_can_import_whole_album(artists, albums, mocker, superuser_client):
],
}
url = reverse("api:v1:submit-album")
response = superuser_client.post(
url, json.dumps(payload), content_type="application/json"
)
superuser_client.post(url, json.dumps(payload), content_type="application/json")
batch = models.ImportBatch.objects.latest("id")
assert batch.jobs.count() == 3
......@@ -153,9 +151,7 @@ def test_can_import_whole_artist(artists, albums, mocker, superuser_client):
],
}
url = reverse("api:v1:submit-artist")
response = superuser_client.post(
url, json.dumps(payload), content_type="application/json"
)
superuser_client.post(url, json.dumps(payload), content_type="application/json")
batch = models.ImportBatch.objects.latest("id")
assert batch.jobs.count() == 3
......
......@@ -35,9 +35,7 @@ def test_create_import_can_bind_to_request(
],
}
url = reverse("api:v1:submit-album")
response = superuser_api_client.post(
url, json.dumps(payload), content_type="application/json"
)
superuser_api_client.post(url, json.dumps(payload), content_type="application/json")
batch = request.import_batches.latest("id")
assert batch.import_request == request
......@@ -160,7 +158,7 @@ def test_import_job_run_triggers_notifies_followers(factories, mocker, tmpfile):
)
batch = factories["music.ImportBatch"]()
job = factories["music.ImportJob"](finished=True, batch=batch)
track = factories["music.Track"](mbid=job.mbid)
factories["music.Track"](mbid=job.mbid)
batch.update_status()
batch.refresh_from_db()
......@@ -193,14 +191,14 @@ def test_import_batch_notifies_followers(factories, mocker):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
f1 = factories["federation.Follow"](approved=True, target=library_actor)
f2 = factories["federation.Follow"](approved=False, target=library_actor)
factories["federation.Follow"](approved=False, target=library_actor)
factories["federation.Follow"]()
mocked_deliver = mocker.patch("funkwhale_api.federation.activity.deliver")
batch = factories["music.ImportBatch"]()
job1 = factories["music.ImportJob"](finished=True, batch=batch)
job2 = factories["music.ImportJob"](finished=True, federation=True, batch=batch)
job3 = factories["music.ImportJob"](status="pending", batch=batch)
factories["music.ImportJob"](finished=True, federation=True, batch=batch)
factories["music.ImportJob"](status="pending", batch=batch)
batch.status = "finished"
batch.save()
......@@ -233,7 +231,7 @@ def test__do_import_in_place_mbid(factories, tmpfile):
path = os.path.join(DATA_DIR, "test.ogg")
job = factories["music.ImportJob"](in_place=True, source="file://{}".format(path))
track = factories["music.Track"](mbid=job.mbid)
factories["music.Track"](mbid=job.mbid)
tf = tasks._do_import(job, use_acoustid=False)
assert bool(tf.audio_file) is False
......
......@@ -104,7 +104,7 @@ def test_saving_job_updates_batch_status(status, factories, mocker):
assert batch.status == "pending"
job = factories["music.ImportJob"](batch=batch, status=status)
factories["music.ImportJob"](batch=batch, status=status)
batch.refresh_from_db()
......
......@@ -120,7 +120,7 @@ def test_can_get_or_create_track_from_api(artists, albums, tracks, mocker, db):
def test_album_tags_deduced_from_tracks_tags(factories, django_assert_num_queries):
tag = factories["taggit.Tag"]()
album = factories["music.Album"]()
tracks = factories["music.Track"].create_batch(5, album=album, tags=[tag])
factories["music.Track"].create_batch(5, album=album, tags=[tag])
album = models.Album.objects.prefetch_related("tracks__tags").get(pk=album.pk)
......@@ -132,7 +132,7 @@ def test_artist_tags_deduced_from_album_tags(factories, django_assert_num_querie
tag = factories["taggit.Tag"]()
album = factories["music.Album"]()
artist = album.artist
tracks = factories["music.Track"].create_batch(5, album=album, tags=[tag])
factories["music.Track"].create_batch(5, album=album, tags=[tag])
artist = models.Artist.objects.prefetch_related("albums__tracks__tags").get(
pk=artist.pk
......
......@@ -45,8 +45,8 @@ 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)
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)
mocker.patch("acoustid.match", return_value=payload)
tasks.set_acoustid_on_track_file(track_file_id=track_file.pk)
track_file.refresh_from_db()
assert track_file.acoustid_track_id is None
......@@ -170,7 +170,7 @@ def test_import_job_skip_if_already_exists(artists, albums, tracks, factories, m
def test_import_job_can_be_errored(factories, mocker, preferences):
path = os.path.join(DATA_DIR, "test.ogg")
mbid = "9968a9d6-8d92-4051-8f76-674e157b6eed"
track_file = factories["music.TrackFile"](track__mbid=mbid)
factories["music.TrackFile"](track__mbid=mbid)
class MyException(Exception):
pass
......@@ -226,7 +226,7 @@ def test_update_album_cover_file_data(factories, mocker):
return_value={"hello": "world"},
)
tasks.update_album_cover(album=album, track_file=tf)
md = data = tf.get_metadata()
tf.get_metadata()
mocked_get.assert_called_once_with(data={"hello": "world"})
......@@ -242,7 +242,7 @@ def test_update_album_cover_file_cover_separate_file(ext, mimetype, factories, m
mocked_get = mocker.patch("funkwhale_api.music.models.Album.get_image")
mocker.patch("funkwhale_api.music.metadata.Metadata.get_picture", return_value=None)
tasks.update_album_cover(album=album, track_file=tf)
md = data = tf.get_metadata()
tf.get_metadata()
mocked_get.assert_called_once_with(
data={"mimetype": mimetype, "content": image_content}
)
......@@ -105,7 +105,7 @@ def test_can_serve_track_file_as_remote_library(
):
preferences["common__api_authentication_required"] = True
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
follow = factories["federation.Follow"](
factories["federation.Follow"](
approved=True, actor=authenticated_actor, target=library_actor
)
......@@ -245,8 +245,8 @@ def test_can_list_import_jobs(factories, superuser_api_client):
def test_import_job_stats(factories, superuser_api_client):
job1 = factories["music.ImportJob"](status="pending")
job2 = factories["music.ImportJob"](status="errored")
factories["music.ImportJob"](status="pending")
factories["music.ImportJob"](status="errored")
url = reverse("api:v1:import-jobs-stats")
response = superuser_api_client.get(url)
......@@ -257,7 +257,7 @@ def test_import_job_stats(factories, superuser_api_client):
def test_import_job_stats_filter(factories, superuser_api_client):
job1 = factories["music.ImportJob"](status="pending")
job2 = factories["music.ImportJob"](status="errored")
factories["music.ImportJob"](status="errored")
url = reverse("api:v1:import-jobs-stats")
response = superuser_api_client.get(url, {"batch": job1.batch.pk})
......
......@@ -106,7 +106,7 @@ def test_remove_update_indexes(factories):
def test_can_insert_many(factories):
playlist = factories["playlists.Playlist"]()
existing = factories["playlists.PlaylistTrack"](playlist=playlist, index=0)
factories["playlists.PlaylistTrack"](playlist=playlist, index=0)
tracks = factories["music.Track"].create_batch(size=3)
plts = playlist.insert_many(tracks)
for i, plt in enumerate(plts):
......@@ -118,7 +118,7 @@ def test_can_insert_many(factories):
def test_insert_many_honor_max_tracks(preferences, factories):
preferences["playlists__max_tracks"] = 4
playlist = factories["playlists.Playlist"]()
plts = factories["playlists.PlaylistTrack"].create_batch(size=2, playlist=playlist)
factories["playlists.PlaylistTrack"].create_batch(size=2, playlist=playlist)
track = factories["music.Track"]()
with pytest.raises(exceptions.ValidationError):
playlist.insert_many([track, track, track])
......@@ -4,7 +4,7 @@ from funkwhale_api.playlists import models, serializers
def test_cannot_max_500_tracks_per_playlist(factories, preferences):
preferences["playlists__max_tracks"] = 2
playlist = factories["playlists.Playlist"]()
plts = factories["playlists.PlaylistTrack"].create_batch(size=2, playlist=playlist)
factories["playlists.PlaylistTrack"].create_batch(size=2, playlist=playlist)
track = factories["music.Track"]()
serializer = serializers.PlaylistTrackWriteSerializer(
data={"playlist": playlist.pk, "track": track.pk}
......
......@@ -17,7 +17,7 @@ def test_can_create_playlist_via_api(logged_in_api_client):
def test_serializer_includes_tracks_count(factories, logged_in_api_client):
playlist = factories["playlists.Playlist"]()
plt = factories["playlists.PlaylistTrack"](playlist=playlist)
factories["playlists.PlaylistTrack"](playlist=playlist)
url = reverse("api:v1:playlists-detail", kwargs={"pk": playlist.pk})
response = logged_in_api_client.get(url)
......@@ -160,7 +160,7 @@ def test_can_add_multiple_tracks_at_once_via_api(
def test_can_clear_playlist_from_api(factories, mocker, logged_in_api_client):
playlist = factories["playlists.Playlist"](user=logged_in_api_client.user)
plts = factories["playlists.PlaylistTrack"].create_batch(size=5, playlist=playlist)
factories["playlists.PlaylistTrack"].create_batch(size=5, playlist=playlist)
url = reverse("api:v1:playlists-clear", kwargs={"pk": playlist.pk})
response = logged_in_api_client.delete(url)
......@@ -170,7 +170,7 @@ def test_can_clear_playlist_from_api(factories, mocker, logged_in_api_client):
def test_update_playlist_from_api(factories, mocker, logged_in_api_client):
playlist = factories["playlists.Playlist"](user=logged_in_api_client.user)
plts = factories["playlists.PlaylistTrack"].create_batch(size=5, playlist=playlist)
factories["playlists.PlaylistTrack"].create_batch(size=5, playlist=playlist)
url = reverse("api:v1:playlists-detail", kwargs={"pk": playlist.pk})
response = logged_in_api_client.patch(url, {"name": "test"})
playlist.refresh_from_db()
......
......@@ -71,7 +71,7 @@ def test_can_get_choices_for_custom_radio(factories):
artist = factories["music.Artist"]()
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)
factories["music.TrackFile"].create_batch(5)
session = factories["radios.CustomRadioSession"](
custom_radio__config=[{"type": "artist", "ids": [artist.pk]}]
......@@ -110,7 +110,7 @@ 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)
factories["music.TrackFile"].create_batch(30)
user = factories["users.User"]()
radio = radios.RandomRadio()
session = radio.start_session(user)
......@@ -136,7 +136,7 @@ def test_can_restore_radio_from_previous_session(factories):
def test_can_start_radio_for_logged_in_user(logged_in_client):
url = reverse("api:v1:radios:sessions-list")
response = logged_in_client.post(url, {"radio_type": "random"})
logged_in_client.post(url, {"radio_type": "random"})
session = models.RadioSession.objects.latest("id")
assert session.radio_type == "random"
assert session.user == logged_in_client.user
......@@ -180,7 +180,7 @@ def test_related_object_radio_validate_related_object(factories):
def test_can_start_artist_radio(factories):
user = factories["users.User"]()
artist = factories["music.Artist"]()
wrong_files = factories["music.TrackFile"].create_batch(5)
factories["music.TrackFile"].create_batch(5)
good_files = factories["music.TrackFile"].create_batch(5, track__artist=artist)
good_tracks = [f.track for f in good_files]
......@@ -194,7 +194,7 @@ def test_can_start_artist_radio(factories):
def test_can_start_tag_radio(factories):
user = factories["users.User"]()
tag = factories["taggit.Tag"]()
wrong_files = factories["music.TrackFile"].create_batch(5)
factories["music.TrackFile"].create_batch(5)
good_files = factories["music.TrackFile"].create_batch(5, track__tags=[tag])
good_tracks = [f.track for f in good_files]
......
......@@ -21,7 +21,6 @@ def test_auth_with_salt(api_request, factories):
def test_auth_with_password_hex(api_request, factories):
salt = "salt"
user = factories["users.User"]()
user.subsonic_api_token = "password"
user.save()
......@@ -44,7 +43,6 @@ def test_auth_with_password_hex(api_request, factories):
def test_auth_with_password_cleartext(api_request, factories):
salt = "salt"
user = factories["users.User"]()
user.subsonic_api_token = "password"
user.save()
......@@ -57,7 +55,6 @@ def test_auth_with_password_cleartext(api_request, factories):
def test_auth_with_inactive_users(api_request, factories):
salt = "salt"
user = factories["users.User"](is_active=False)
user.subsonic_api_token = "password"
user.save()
......
......@@ -18,8 +18,8 @@ def test_can_create_track_from_file_metadata_no_mbid(db, mocker):
"TRACKNUMBER": ["4"],
"date": ["2012-08-15"],
}
m1 = mocker.patch("mutagen.File", return_value=metadata)
m2 = mocker.patch(
mocker.patch("mutagen.File", return_value=metadata)
mocker.patch(
"funkwhale_api.music.metadata.Metadata.get_file_type", return_value="OggVorbis"
)
track = tasks.import_track_data_from_path(os.path.join(DATA_DIR, "dummy_file.ogg"))
......@@ -68,8 +68,8 @@ def test_can_create_track_from_file_metadata_mbid(factories, mocker):
"musicbrainz_albumid": [album.mbid],
"musicbrainz_trackid": [track_data["recording"]["id"]],
}
m1 = mocker.patch("mutagen.File", return_value=metadata)
m2 = mocker.patch(
mocker.patch("mutagen.File", return_value=metadata)
mocker.patch(
"funkwhale_api.music.metadata.Metadata.get_file_type", return_value="OggVorbis"
)
track = tasks.import_track_data_from_path(os.path.join(DATA_DIR, "dummy_file.ogg"))
......@@ -83,7 +83,7 @@ def test_can_create_track_from_file_metadata_mbid(factories, mocker):
def test_management_command_requires_a_valid_username(factories, mocker):
path = os.path.join(DATA_DIR, "dummy_file.ogg")
user = factories["users.User"](username="me")
factories["users.User"](username="me")
mocker.patch(
"funkwhale_api.providers.audiofile.management.commands.import_files.Command.do_import", # noqa
return_value=(mocker.MagicMock(), []),
......@@ -94,7 +94,7 @@ def test_management_command_requires_a_valid_username(factories, mocker):
def test_in_place_import_only_from_music_dir(factories, settings):
user = factories["users.User"](username="me")
factories["users.User"](username="me")
settings.MUSIC_DIRECTORY_PATH = "/nope"
path = os.path.join(DATA_DIR, "dummy_file.ogg")
with pytest.raises(CommandError):
......@@ -126,7 +126,7 @@ def test_import_files_creates_a_batch_and_job(factories, mocker):
def test_import_files_skip_if_path_already_imported(factories, mocker):
user = factories["users.User"](username="me")
path = os.path.join(DATA_DIR, "dummy_file.ogg")
existing = factories["music.TrackFile"](source="file://{}".format(path))
factories["music.TrackFile"](source="file://{}".format(path))
call_command("import_files", path, username="me", async=False, interactive=False)
assert user.imports.count() == 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment