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): ...@@ -24,13 +24,6 @@ def scan_from_account_name(account_name):
except serializers.ValidationError: except serializers.ValidationError:
return {"webfinger": {"errors": ["Invalid account string"]}} return {"webfinger": {"errors": ["Invalid account string"]}}
system_library = actors.SYSTEM_ACTORS["library"].get_actor_instance() 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} data["local"] = {"following": False, "awaiting_approval": False}
try: try:
follow = models.Follow.objects.get( follow = models.Follow.objects.get(
......
...@@ -21,7 +21,7 @@ from . import ( ...@@ -21,7 +21,7 @@ from . import (
serializers, serializers,
tasks, tasks,
utils, utils,
webfinger webfinger,
) )
...@@ -57,7 +57,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet): ...@@ -57,7 +57,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet):
handler = getattr(system_actor, "{}_inbox".format(request.method.lower())) handler = getattr(system_actor, "{}_inbox".format(request.method.lower()))
try: try:
data = handler(request.data, actor=request.actor) handler(request.data, actor=request.actor)
except NotImplementedError: except NotImplementedError:
return response.Response(status=405) return response.Response(status=405)
return response.Response({}, status=200) return response.Response({}, status=200)
...@@ -67,7 +67,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet): ...@@ -67,7 +67,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet):
system_actor = self.get_object() system_actor = self.get_object()
handler = getattr(system_actor, "{}_outbox".format(request.method.lower())) handler = getattr(system_actor, "{}_outbox".format(request.method.lower()))
try: try:
data = handler(request.data, actor=request.actor) handler(request.data, actor=request.actor)
except NotImplementedError: except NotImplementedError:
return response.Response(status=405) return response.Response(status=405)
return response.Response({}, status=200) return response.Response({}, status=200)
......
...@@ -67,8 +67,7 @@ class Command(BaseCommand): ...@@ -67,8 +67,7 @@ class Command(BaseCommand):
try: try:
audio_file = tf.get_audio_file() audio_file = tf.get_audio_file()
if audio_file: if audio_file:
with audio_file as f: data = utils.get_audio_file_data(audio_file)
data = utils.get_audio_file_data(audio_file)
tf.bitrate = data["bitrate"] tf.bitrate = data["bitrate"]
tf.duration = data["length"] tf.duration = data["length"]
tf.save(update_fields=["duration", "bitrate"]) tf.save(update_fields=["duration", "bitrate"])
......
...@@ -67,7 +67,7 @@ class APIModelMixin(models.Model): ...@@ -67,7 +67,7 @@ class APIModelMixin(models.Model):
try: try:
cleaned_key, cleaned_value = mapping.from_musicbrainz(key, value) cleaned_key, cleaned_value = mapping.from_musicbrainz(key, value)
cleaned_data[cleaned_key] = cleaned_value cleaned_data[cleaned_key] = cleaned_value
except KeyError as e: except KeyError:
pass pass
return cleaned_data return cleaned_data
...@@ -134,9 +134,7 @@ def import_tracks(instance, cleaned_data, raw_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 = Track.clean_musicbrainz_data(track_data["recording"])
track_cleaned_data["album"] = instance track_cleaned_data["album"] = instance
track_cleaned_data["position"] = int(track_data["position"]) track_cleaned_data["position"] = int(track_data["position"])
track = importers.load( importers.load(Track, track_cleaned_data, track_data, Track.import_hooks)
Track, track_cleaned_data, track_data, Track.import_hooks
)
class AlbumQuerySet(models.QuerySet): class AlbumQuerySet(models.QuerySet):
......
...@@ -457,9 +457,7 @@ class SubmitViewSet(viewsets.ViewSet): ...@@ -457,9 +457,7 @@ class SubmitViewSet(viewsets.ViewSet):
import_request = self.get_import_request(data) import_request = self.get_import_request(data)
artist_data = api.artists.get(id=data["artistId"])["artist"] artist_data = api.artists.get(id=data["artistId"])["artist"]
cleaned_data = models.Artist.clean_musicbrainz_data(artist_data) cleaned_data = models.Artist.clean_musicbrainz_data(artist_data)
artist = importers.load( importers.load(models.Artist, cleaned_data, artist_data, import_hooks=[])
models.Artist, cleaned_data, artist_data, import_hooks=[]
)
import_data = [] import_data = []
batch = None batch = None
......
...@@ -11,9 +11,9 @@ def test_get_activity(factories): ...@@ -11,9 +11,9 @@ def test_get_activity(factories):
def test_get_activity_honors_privacy_level(factories, anonymous_user): 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") 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)) objects = list(utils.get_activity(anonymous_user))
assert objects == [favorite1] assert objects == [favorite1]
...@@ -5,7 +5,7 @@ from funkwhale_api.activity import serializers, utils ...@@ -5,7 +5,7 @@ from funkwhale_api.activity import serializers, utils
def test_activity_view(factories, api_client, preferences, anonymous_user): def test_activity_view(factories, api_client, preferences, anonymous_user):
preferences["common__api_authentication_required"] = False preferences["common__api_authentication_required"] = False
favorite = factories["favorites.TrackFavorite"](user__privacy_level="everyone") factories["favorites.TrackFavorite"](user__privacy_level="everyone")
factories["history.Listening"]() factories["history.Listening"]()
url = reverse("api:v1:activity-list") url = reverse("api:v1:activity-list")
objects = utils.get_activity(anonymous_user) objects = utils.get_activity(anonymous_user)
......
...@@ -55,6 +55,5 @@ def test_broadcast_track_favorite_to_instance_activity_private(factories, mocker ...@@ -55,6 +55,5 @@ def test_broadcast_track_favorite_to_instance_activity_private(factories, mocker
favorite = factories["favorites.TrackFavorite"](user__privacy_level="me") favorite = factories["favorites.TrackFavorite"](user__privacy_level="me")
data = serializers.TrackFavoriteActivitySerializer(favorite).data data = serializers.TrackFavoriteActivitySerializer(favorite).data
consumer = activities.broadcast_track_favorite_to_instance_activity consumer = activities.broadcast_track_favorite_to_instance_activity
message = {"type": "event.send", "text": "", "data": data}
consumer(data=data, obj=favorite) consumer(data=data, obj=favorite)
p.assert_not_called() p.assert_not_called()
...@@ -48,9 +48,7 @@ def test_get_actor_refresh(factories, preferences, mocker): ...@@ -48,9 +48,7 @@ def test_get_actor_refresh(factories, preferences, mocker):
payload = serializers.ActorSerializer(actor).data payload = serializers.ActorSerializer(actor).data
# actor changed their username in the meantime # actor changed their username in the meantime
payload["preferredUsername"] = "New me" payload["preferredUsername"] = "New me"
get_data = mocker.patch( mocker.patch("funkwhale_api.federation.actors.get_actor_data", return_value=payload)
"funkwhale_api.federation.actors.get_actor_data", return_value=payload
)
new_actor = actors.get_actor(actor.url) new_actor = actors.get_actor(actor.url)
assert new_actor == actor assert new_actor == actor
...@@ -59,7 +57,7 @@ def test_get_actor_refresh(factories, preferences, mocker): ...@@ -59,7 +57,7 @@ def test_get_actor_refresh(factories, preferences, mocker):
def test_get_library(db, settings, mocker): def test_get_library(db, settings, mocker):
get_key_pair = mocker.patch( mocker.patch(
"funkwhale_api.federation.keys.get_key_pair", "funkwhale_api.federation.keys.get_key_pair",
return_value=(b"private", b"public"), return_value=(b"private", b"public"),
) )
...@@ -92,7 +90,7 @@ def test_get_library(db, settings, mocker): ...@@ -92,7 +90,7 @@ def test_get_library(db, settings, mocker):
def test_get_test(db, mocker, settings): def test_get_test(db, mocker, settings):
get_key_pair = mocker.patch( mocker.patch(
"funkwhale_api.federation.keys.get_key_pair", "funkwhale_api.federation.keys.get_key_pair",
return_value=(b"private", b"public"), return_value=(b"private", b"public"),
) )
...@@ -240,7 +238,7 @@ def test_actor_is_system(username, domain, expected, nodb_factories, settings): ...@@ -240,7 +238,7 @@ def test_actor_is_system(username, domain, expected, nodb_factories, settings):
("test", "", actors.SYSTEM_ACTORS["test"]), ("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: if not domain:
domain = settings.FEDERATION_HOSTNAME domain = settings.FEDERATION_HOSTNAME
actor = nodb_factories["federation.Actor"]( actor = nodb_factories["federation.Actor"](
......
...@@ -162,7 +162,7 @@ def test_follow_serializer_save(factories): ...@@ -162,7 +162,7 @@ def test_follow_serializer_save(factories):
actor = factories["federation.Actor"]() actor = factories["federation.Actor"]()
target = factories["federation.Actor"]() target = factories["federation.Actor"]()
data = expected = { data = {
"id": "https://test.follow", "id": "https://test.follow",
"type": "Follow", "type": "Follow",
"actor": actor.url, "actor": actor.url,
...@@ -185,7 +185,7 @@ def test_follow_serializer_save_validates_on_context(factories): ...@@ -185,7 +185,7 @@ def test_follow_serializer_save_validates_on_context(factories):
target = factories["federation.Actor"]() target = factories["federation.Actor"]()
impostor = factories["federation.Actor"]() impostor = factories["federation.Actor"]()
data = expected = { data = {
"id": "https://test.follow", "id": "https://test.follow",
"type": "Follow", "type": "Follow",
"actor": actor.url, "actor": actor.url,
......
...@@ -109,11 +109,11 @@ def test_clean_federation_music_cache_if_no_listen(preferences, factories): ...@@ -109,11 +109,11 @@ def test_clean_federation_music_cache_if_no_listen(preferences, factories):
lt1 = factories["federation.LibraryTrack"](with_audio_file=True) lt1 = factories["federation.LibraryTrack"](with_audio_file=True)
lt2 = factories["federation.LibraryTrack"](with_audio_file=True) lt2 = factories["federation.LibraryTrack"](with_audio_file=True)
lt3 = 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) factories["music.TrackFile"](accessed_date=timezone.now(), library_track=lt1)
tf2 = factories["music.TrackFile"]( factories["music.TrackFile"](
accessed_date=timezone.now() - datetime.timedelta(minutes=61), library_track=lt2 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 path1 = lt1.audio_file.path
path2 = lt2.audio_file.path path2 = lt2.audio_file.path
path3 = lt3.audio_file.path path3 = lt3.audio_file.path
...@@ -144,7 +144,7 @@ def test_clean_federation_music_cache_orphaned(settings, preferences, factories) ...@@ -144,7 +144,7 @@ def test_clean_federation_music_cache_orphaned(settings, preferences, factories)
lt = factories["federation.LibraryTrack"]( lt = factories["federation.LibraryTrack"](
with_audio_file=True, audio_file__path=keep_path 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() tasks.clean_music_cache()
......
...@@ -3,7 +3,15 @@ from django.core.paginator import Paginator ...@@ -3,7 +3,15 @@ from django.core.paginator import Paginator
from django.urls import reverse from django.urls import reverse
from django.utils import timezone 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( @pytest.mark.parametrize(
...@@ -152,7 +160,7 @@ def test_audio_file_list_actor_page_exclude_federated_files( ...@@ -152,7 +160,7 @@ def test_audio_file_list_actor_page_exclude_federated_files(
db, preferences, api_client, factories db, preferences, api_client, factories
): ):
preferences["federation__music_needs_approval"] = False 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") url = reverse("federation:music:files-list")
response = api_client.get(url) response = api_client.get(url)
...@@ -265,7 +273,7 @@ def test_can_list_system_actor_following(factories, superuser_api_client): ...@@ -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): def test_can_list_system_actor_followers(factories, superuser_api_client):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance() 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) follow2 = factories["federation.Follow"](target=library_actor)
url = reverse("api:v1:federation:libraries-followers") url = reverse("api:v1:federation:libraries-followers")
...@@ -375,7 +383,7 @@ def test_can_update_follow_status(factories, superuser_api_client, mocker): ...@@ -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): def test_can_filter_pending_follows(factories, superuser_api_client):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance() 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} params = {"pending": True}
url = reverse("api:v1:federation:libraries-followers") url = reverse("api:v1:federation:libraries-followers")
...@@ -389,7 +397,7 @@ def test_library_track_action_import(factories, superuser_api_client, mocker): ...@@ -389,7 +397,7 @@ def test_library_track_action_import(factories, superuser_api_client, mocker):
lt1 = factories["federation.LibraryTrack"]() lt1 = factories["federation.LibraryTrack"]()
lt2 = factories["federation.LibraryTrack"](library=lt1.library) lt2 = factories["federation.LibraryTrack"](library=lt1.library)
lt3 = factories["federation.LibraryTrack"]() 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") mocked_run = mocker.patch("funkwhale_api.music.tasks.import_batch_run.delay")
payload = { payload = {
......
...@@ -55,6 +55,5 @@ def test_broadcast_listening_to_instance_activity_private(factories, mocker): ...@@ -55,6 +55,5 @@ def test_broadcast_listening_to_instance_activity_private(factories, mocker):
listening = factories["history.Listening"](user__privacy_level="me") listening = factories["history.Listening"](user__privacy_level="me")
data = serializers.ListeningActivitySerializer(listening).data data = serializers.ListeningActivitySerializer(listening).data
consumer = activities.broadcast_listening_to_instance_activity consumer = activities.broadcast_listening_to_instance_activity
message = {"type": "event.send", "text": "", "data": data}
consumer(data=data, obj=listening) consumer(data=data, obj=listening)
p.assert_not_called() p.assert_not_called()
...@@ -6,7 +6,7 @@ from funkwhale_api.history import models ...@@ -6,7 +6,7 @@ from funkwhale_api.history import models
def test_can_create_listening(factories): def test_can_create_listening(factories):
track = factories["music.Track"]() track = factories["music.Track"]()
user = factories["users.User"]() 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( def test_logged_in_user_can_create_listening_via_api(
...@@ -15,7 +15,7 @@ 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"]() track = factories["music.Track"]()
url = reverse("api:v1:history:listenings-list") 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") listening = models.Listening.objects.latest("id")
...@@ -29,7 +29,7 @@ def test_adding_listening_calls_activity_record( ...@@ -29,7 +29,7 @@ def test_adding_listening_calls_activity_record(
track = factories["music.Track"]() track = factories["music.Track"]()
url = reverse("api:v1:history:listenings-list") 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") listening = models.Listening.objects.latest("id")
......
from funkwhale_api.instance import stats from funkwhale_api.instance import stats
...@@ -54,7 +53,7 @@ def test_get(mocker): ...@@ -54,7 +53,7 @@ def test_get(mocker):
"listenings", "listenings",
"music_duration", "music_duration",
] ]
mocks = [ [
mocker.patch.object(stats, "get_{}".format(k), return_value=i) mocker.patch.object(stats, "get_{}".format(k), return_value=i)
for i, k in enumerate(keys) for i, k in enumerate(keys)
] ]
......
...@@ -11,9 +11,7 @@ def test_permissions(assert_user_permission, view, permissions): ...@@ -11,9 +11,7 @@ def test_permissions(assert_user_permission, view, permissions):
def test_nodeinfo_endpoint(db, api_client, mocker): def test_nodeinfo_endpoint(db, api_client, mocker):
payload = {"test": "test"} payload = {"test": "test"}
mocked_nodeinfo = mocker.patch( mocker.patch("funkwhale_api.instance.nodeinfo.get", return_value=payload)
"funkwhale_api.instance.nodeinfo.get", return_value=payload
)
url = reverse("api:v1:instance:nodeinfo-2.0") url = reverse("api:v1:instance:nodeinfo-2.0")
response = api_client.get(url) response = api_client.get(url)
ct = "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" # noqa 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): ...@@ -47,7 +47,7 @@ def test_import_creates_an_import_with_correct_data(mocker, superuser_client):
mbid = "9968a9d6-8d92-4051-8f76-674e157b6eed" mbid = "9968a9d6-8d92-4051-8f76-674e157b6eed"
video_id = "tPEE9ZwTmy0" video_id = "tPEE9ZwTmy0"
url = reverse("api:v1:submit-single") url = reverse("api:v1:submit-single")
response = superuser_client.post( superuser_client.post(
url, url,
{ {
"import_url": "https://www.youtube.com/watch?v={0}".format(video_id), "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): ...@@ -93,9 +93,7 @@ def test_can_import_whole_album(artists, albums, mocker, superuser_client):
], ],
} }
url = reverse("api:v1:submit-album") url = reverse("api:v1:submit-album")
response = superuser_client.post( superuser_client.post(url, json.dumps(payload), content_type="application/json")
url, json.dumps(payload), content_type="application/json"
)
batch = models.ImportBatch.objects.latest("id") batch = models.ImportBatch.objects.latest("id")
assert batch.jobs.count() == 3 assert batch.jobs.count() == 3
...@@ -153,9 +151,7 @@ def test_can_import_whole_artist(artists, albums, mocker, superuser_client): ...@@ -153,9 +151,7 @@ def test_can_import_whole_artist(artists, albums, mocker, superuser_client):
], ],
} }
url = reverse("api:v1:submit-artist") url = reverse("api:v1:submit-artist")
response = superuser_client.post( superuser_client.post(url, json.dumps(payload), content_type="application/json")
url, json.dumps(payload), content_type="application/json"
)
batch = models.ImportBatch.objects.latest("id") batch = models.ImportBatch.objects.latest("id")
assert batch.jobs.count() == 3 assert batch.jobs.count() == 3
......
...@@ -35,9 +35,7 @@ def test_create_import_can_bind_to_request( ...@@ -35,9 +35,7 @@ def test_create_import_can_bind_to_request(
], ],
} }
url = reverse("api:v1:submit-album") url = reverse("api:v1:submit-album")
response = superuser_api_client.post( superuser_api_client.post(url, json.dumps(payload), content_type="application/json")
url, json.dumps(payload), content_type="application/json"
)
batch = request.import_batches.latest("id") batch = request.import_batches.latest("id")
assert batch.import_request == request assert batch.import_request == request
...@@ -160,7 +158,7 @@ def test_import_job_run_triggers_notifies_followers(factories, mocker, tmpfile): ...@@ -160,7 +158,7 @@ def test_import_job_run_triggers_notifies_followers(factories, mocker, tmpfile):
) )
batch = factories["music.ImportBatch"]() batch = factories["music.ImportBatch"]()
job = factories["music.ImportJob"](finished=True, batch=batch) 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.update_status()
batch.refresh_from_db() batch.refresh_from_db()
...@@ -193,14 +191,14 @@ def test_import_batch_notifies_followers(factories, mocker): ...@@ -193,14 +191,14 @@ def test_import_batch_notifies_followers(factories, mocker):
library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance() library_actor = actors.SYSTEM_ACTORS["library"].get_actor_instance()
f1 = factories["federation.Follow"](approved=True, target=library_actor) 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"]() factories["federation.Follow"]()
mocked_deliver = mocker.patch("funkwhale_api.federation.activity.deliver") mocked_deliver = mocker.patch("funkwhale_api.federation.activity.deliver")
batch = factories["music.ImportBatch"]() batch = factories["music.ImportBatch"]()
job1 = factories["music.ImportJob"](finished=True, batch=batch) job1 = factories["music.ImportJob"](finished=True, batch=batch)
job2 = factories["music.ImportJob"](finished=True, federation=True, batch=batch) factories["music.ImportJob"](finished=True, federation=True, batch=batch)
job3 = factories["music.ImportJob"](status="pending", batch=batch) factories["music.ImportJob"](status="pending", batch=batch)
batch.status = "finished" batch.status = "finished"
batch.save() batch.save()
...@@ -233,7 +231,7 @@ def test__do_import_in_place_mbid(factories, tmpfile): ...@@ -233,7 +231,7 @@ def test__do_import_in_place_mbid(factories, tmpfile):
path = os.path.join(DATA_DIR, "test.ogg") path = os.path.join(DATA_DIR, "test.ogg")
job = factories["music.ImportJob"](in_place=True, source="file://{}".format(path)) 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) tf = tasks._do_import(job, use_acoustid=False)
assert bool(tf.audio_file) is False assert bool(tf.audio_file) is False
......
...@@ -104,7 +104,7 @@ def test_saving_job_updates_batch_status(status, factories, mocker): ...@@ -104,7 +104,7 @@ def test_saving_job_updates_batch_status(status, factories, mocker):
assert batch.status == "pending" assert batch.status == "pending"
job = factories["music.ImportJob"](batch=batch, status=status) factories["music.ImportJob"](batch=batch, status=status)
batch.refresh_from_db() batch.refresh_from_db()
......
...@@ -120,7 +120,7 @@ def test_can_get_or_create_track_from_api(artists, albums, tracks, mocker, 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): def test_album_tags_deduced_from_tracks_tags(factories, django_assert_num_queries):
tag = factories["taggit.Tag"]() tag = factories["taggit.Tag"]()
album = factories["music.Album"]() 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) 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 ...@@ -132,7 +132,7 @@ def test_artist_tags_deduced_from_album_tags(factories, django_assert_num_querie
tag = factories["taggit.Tag"]() tag = factories["taggit.Tag"]()
album = factories["music.Album"]() album = factories["music.Album"]()
artist = album.artist 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( artist = models.Artist.objects.prefetch_related("albums__tracks__tags").get(
pk=artist.pk pk=artist.pk
......
...@@ -45,8 +45,8 @@ def test_set_acoustid_on_track_file(factories, mocker, preferences): ...@@ -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): def test_set_acoustid_on_track_file_required_high_score(factories, mocker):
track_file = factories["music.TrackFile"](acoustid_track_id=None) track_file = factories["music.TrackFile"](acoustid_track_id=None)
payload = {"results": [{"score": 0.79}], "status": "ok"} payload = {"results": [{"score": 0.79}], "status": "ok"}
m = mocker.patch("acoustid.match", return_value=payload) mocker.patch("acoustid.match", return_value=payload)
r = tasks.set_acoustid_on_track_file(track_file_id=track_file.pk) tasks.set_acoustid_on_track_file(track_file_id=track_file.pk)
track_file.refresh_from_db() track_file.refresh_from_db()
assert track_file.acoustid_track_id is None 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 ...@@ -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): def test_import_job_can_be_errored(factories, mocker, preferences):
path = os.path.join(DATA_DIR, "test.ogg") path = os.path.join(DATA_DIR, "test.ogg")
mbid = "9968a9d6-8d92-4051-8f76-674e157b6eed" mbid = "9968a9d6-8d92-4051-8f76-674e157b6eed"
track_file = factories["music.TrackFile"](track__mbid=mbid) factories["music.TrackFile"](track__mbid=mbid)
class MyException(Exception): class MyException(Exception):
pass pass
...@@ -226,7 +226,7 @@ def test_update_album_cover_file_data(factories, mocker): ...@@ -226,7 +226,7 @@ def test_update_album_cover_file_data(factories, mocker):
return_value={"hello": "world"}, return_value={"hello": "world"},
) )
tasks.update_album_cover(album=album, track_file=tf) 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"}) 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 ...@@ -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")