test_serializers.py 20.6 KB
Newer Older
1
import pytest
2
import uuid
3

Eliot Berriot's avatar
Eliot Berriot committed
4
from funkwhale_api.common import serializers as common_serializers
5
from funkwhale_api.federation import serializers as federation_serializers
Eliot Berriot's avatar
Eliot Berriot committed
6
from funkwhale_api.music import licenses
7
from funkwhale_api.music import models
8
from funkwhale_api.music import serializers
9
from funkwhale_api.music import tasks
10
11


Eliot Berriot's avatar
Eliot Berriot committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def test_license_serializer():
    """
    We serializer all licenses to ensure we have valid hardcoded data
    """
    for data in licenses.LICENSES:
        expected = {
            "id": data["identifiers"][0],
            "code": data["code"],
            "name": data["name"],
            "url": data["url"],
            "redistribute": data["redistribute"],
            "derivative": data["derivative"],
            "commercial": data["commercial"],
            "attribution": data["attribution"],
            "copyleft": data["copyleft"],
        }

        serializer = serializers.LicenseSerializer(data)

        assert serializer.data == expected


34
def test_artist_album_serializer(factories, to_api_date):
35
    track = factories["music.Track"](album__with_cover=True)
36
37
38
    album = track.album
    album = album.__class__.objects.with_tracks_count().get(pk=album.pk)
    expected = {
Eliot Berriot's avatar
Eliot Berriot committed
39
        "id": album.id,
Eliot Berriot's avatar
Eliot Berriot committed
40
        "fid": album.fid,
Eliot Berriot's avatar
Eliot Berriot committed
41
42
43
44
45
        "mbid": str(album.mbid),
        "title": album.title,
        "artist": album.artist.id,
        "creation_date": to_api_date(album.creation_date),
        "tracks_count": 1,
46
        "is_playable": None,
Eliot Berriot's avatar
Eliot Berriot committed
47
        "cover": common_serializers.AttachmentSerializer(album.attachment_cover).data,
Eliot Berriot's avatar
Eliot Berriot committed
48
        "release_date": to_api_date(album.release_date),
Eliot Berriot's avatar
Eliot Berriot committed
49
        "is_local": album.is_local,
50
51
52
53
54
55
56
    }
    serializer = serializers.ArtistAlbumSerializer(album)

    assert serializer.data == expected


def test_artist_with_albums_serializer(factories, to_api_date):
57
    actor = factories["federation.Actor"]()
58
59
60
    track = factories["music.Track"](
        album__artist__attributed_to=actor, album__artist__with_cover=True
    )
61
62
63
    artist = track.artist
    artist = artist.__class__.objects.with_albums().get(pk=artist.pk)
    album = list(artist.albums.all())[0]
64
    setattr(artist, "_prefetched_tracks", range(42))
65
    expected = {
Eliot Berriot's avatar
Eliot Berriot committed
66
        "id": artist.id,
Eliot Berriot's avatar
Eliot Berriot committed
67
        "fid": artist.fid,
Eliot Berriot's avatar
Eliot Berriot committed
68
69
        "mbid": str(artist.mbid),
        "name": artist.name,
Eliot Berriot's avatar
Eliot Berriot committed
70
        "is_local": artist.is_local,
71
        "content_category": artist.content_category,
Eliot Berriot's avatar
Eliot Berriot committed
72
73
        "creation_date": to_api_date(artist.creation_date),
        "albums": [serializers.ArtistAlbumSerializer(album).data],
74
        "tags": [],
75
        "attributed_to": federation_serializers.APIActorSerializer(actor).data,
76
        "tracks_count": 42,
77
        "cover": common_serializers.AttachmentSerializer(artist.attachment_cover).data,
78
79
80
81
82
83
84
85
        "channel": None,
    }
    serializer = serializers.ArtistWithAlbumsSerializer(artist)
    assert serializer.data == expected


def test_artist_with_albums_serializer_channel(factories, to_api_date):
    actor = factories["federation.Actor"]()
86
    channel = factories["audio.Channel"](attributed_to=actor, artist__with_cover=True)
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    track = factories["music.Track"](album__artist=channel.artist)
    artist = track.artist
    artist = artist.__class__.objects.with_albums().get(pk=artist.pk)
    album = list(artist.albums.all())[0]
    setattr(artist, "_prefetched_tracks", range(42))
    expected = {
        "id": artist.id,
        "fid": artist.fid,
        "mbid": str(artist.mbid),
        "name": artist.name,
        "is_local": artist.is_local,
        "content_category": artist.content_category,
        "creation_date": to_api_date(artist.creation_date),
        "albums": [serializers.ArtistAlbumSerializer(album).data],
        "tags": [],
        "attributed_to": federation_serializers.APIActorSerializer(actor).data,
        "tracks_count": 42,
        "cover": common_serializers.AttachmentSerializer(artist.attachment_cover).data,
        "channel": {
            "uuid": str(channel.uuid),
            "actor": {
                "full_username": channel.actor.full_username,
                "preferred_username": channel.actor.preferred_username,
                "domain": channel.actor.domain_id,
            },
        },
113
114
115
116
117
    }
    serializer = serializers.ArtistWithAlbumsSerializer(artist)
    assert serializer.data == expected


Eliot Berriot's avatar
Eliot Berriot committed
118
119
def test_upload_serializer(factories, to_api_date):
    upload = factories["music.Upload"]()
120
121

    expected = {
Eliot Berriot's avatar
Eliot Berriot committed
122
123
124
125
126
127
128
129
        "uuid": str(upload.uuid),
        "filename": upload.filename,
        "track": serializers.TrackSerializer(upload.track).data,
        "duration": upload.duration,
        "mimetype": upload.mimetype,
        "bitrate": upload.bitrate,
        "size": upload.size,
        "library": serializers.LibraryForOwnerSerializer(upload.library).data,
130
        "creation_date": to_api_date(upload.creation_date),
131
132
        "import_date": None,
        "import_status": "pending",
133
    }
Eliot Berriot's avatar
Eliot Berriot committed
134
    serializer = serializers.UploadSerializer(upload)
135
136
137
    assert serializer.data == expected


Eliot Berriot's avatar
Eliot Berriot committed
138
139
def test_upload_owner_serializer(factories, to_api_date):
    upload = factories["music.Upload"](
140
141
142
143
144
145
146
147
148
        import_status="success",
        import_details={"hello": "world"},
        import_metadata={"import": "metadata"},
        import_reference="ref",
        metadata={"test": "metadata"},
        source="upload://test",
    )

    expected = {
Eliot Berriot's avatar
Eliot Berriot committed
149
150
151
152
153
154
155
156
        "uuid": str(upload.uuid),
        "filename": upload.filename,
        "track": serializers.TrackSerializer(upload.track).data,
        "duration": upload.duration,
        "mimetype": upload.mimetype,
        "bitrate": upload.bitrate,
        "size": upload.size,
        "library": serializers.LibraryForOwnerSerializer(upload.library).data,
157
        "creation_date": to_api_date(upload.creation_date),
158
159
160
161
162
163
164
165
        "metadata": {"test": "metadata"},
        "import_metadata": {"import": "metadata"},
        "import_date": None,
        "import_status": "success",
        "import_details": {"hello": "world"},
        "source": "upload://test",
        "import_reference": "ref",
    }
Eliot Berriot's avatar
Eliot Berriot committed
166
    serializer = serializers.UploadForOwnerSerializer(upload)
167
168
169
    assert serializer.data == expected


170
def test_album_serializer(factories, to_api_date):
171
    actor = factories["federation.Actor"]()
172
173
174
    track1 = factories["music.Track"](
        position=2, album__attributed_to=actor, album__with_cover=True
    )
175
    factories["music.Track"](position=1, album=track1.album)
176
177
    album = track1.album
    expected = {
Eliot Berriot's avatar
Eliot Berriot committed
178
        "id": album.id,
Eliot Berriot's avatar
Eliot Berriot committed
179
        "fid": album.fid,
Eliot Berriot's avatar
Eliot Berriot committed
180
181
        "mbid": str(album.mbid),
        "title": album.title,
182
        "artist": serializers.serialize_artist_simple(album.artist),
Eliot Berriot's avatar
Eliot Berriot committed
183
        "creation_date": to_api_date(album.creation_date),
184
        "is_playable": False,
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
        "cover": common_serializers.AttachmentSerializer(album.attachment_cover).data,
        "release_date": to_api_date(album.release_date),
        "tracks_count": 2,
        "is_local": album.is_local,
        "tags": [],
        "attributed_to": federation_serializers.APIActorSerializer(actor).data,
    }
    serializer = serializers.AlbumSerializer(
        album.__class__.objects.with_tracks_count().get(pk=album.pk)
    )

    assert serializer.data == expected


def test_track_album_serializer(factories, to_api_date):
    actor = factories["federation.Actor"]()
    track1 = factories["music.Track"](
        position=2, album__attributed_to=actor, album__with_cover=True
    )
    factories["music.Track"](position=1, album=track1.album)
    album = track1.album
    expected = {
        "id": album.id,
        "fid": album.fid,
        "mbid": str(album.mbid),
        "title": album.title,
        "artist": serializers.serialize_artist_simple(album.artist),
        "creation_date": to_api_date(album.creation_date),
        "is_playable": False,
Eliot Berriot's avatar
Eliot Berriot committed
214
        "cover": common_serializers.AttachmentSerializer(album.attachment_cover).data,
Eliot Berriot's avatar
Eliot Berriot committed
215
        "release_date": to_api_date(album.release_date),
216
        "tracks_count": 2,
Eliot Berriot's avatar
Eliot Berriot committed
217
        "is_local": album.is_local,
218
        "tags": [],
219
        "attributed_to": federation_serializers.APIActorSerializer(actor).data,
220
    }
221
222
223
    serializer = serializers.AlbumSerializer(
        album.__class__.objects.with_tracks_count().get(pk=album.pk)
    )
224
225
226
227
228

    assert serializer.data == expected


def test_track_serializer(factories, to_api_date):
229
    actor = factories["federation.Actor"]()
Eliot Berriot's avatar
Eliot Berriot committed
230
    upload = factories["music.Upload"](
231
232
233
234
        track__license="cc-by-4.0",
        track__copyright="test",
        track__disc_number=2,
        track__attributed_to=actor,
235
        track__with_cover=True,
Eliot Berriot's avatar
Eliot Berriot committed
236
    )
Eliot Berriot's avatar
Eliot Berriot committed
237
    track = upload.track
238
    setattr(track, "playable_uploads", [upload])
239
    expected = {
Eliot Berriot's avatar
Eliot Berriot committed
240
        "id": track.id,
Eliot Berriot's avatar
Eliot Berriot committed
241
        "fid": track.fid,
242
        "artist": serializers.serialize_artist_simple(track.artist),
Eliot Berriot's avatar
Eliot Berriot committed
243
244
245
246
        "album": serializers.TrackAlbumSerializer(track.album).data,
        "mbid": str(track.mbid),
        "title": track.title,
        "position": track.position,
247
        "disc_number": track.disc_number,
248
        "uploads": [serializers.serialize_upload(upload)],
Eliot Berriot's avatar
Eliot Berriot committed
249
        "creation_date": to_api_date(track.creation_date),
250
        "listen_url": track.listen_url,
Eliot Berriot's avatar
Eliot Berriot committed
251
252
        "license": upload.track.license.code,
        "copyright": upload.track.copyright,
Eliot Berriot's avatar
Eliot Berriot committed
253
        "is_local": upload.track.is_local,
254
        "tags": [],
255
        "attributed_to": federation_serializers.APIActorSerializer(actor).data,
256
        "cover": common_serializers.AttachmentSerializer(track.attachment_cover).data,
257
        "downloads_count": track.downloads_count,
258
259
260
    }
    serializer = serializers.TrackSerializer(track)
    assert serializer.data == expected
261
262
263
264
265
266


def test_user_cannot_bind_file_to_a_not_owned_library(factories):
    user = factories["users.User"]()
    library = factories["music.Library"]()

Eliot Berriot's avatar
Eliot Berriot committed
267
    s = serializers.UploadForOwnerSerializer(
268
269
270
271
272
273
274
275
276
277
        data={"library": library.uuid, "source": "upload://test"},
        context={"user": user},
    )
    assert s.is_valid() is False
    assert "library" in s.errors


def test_user_can_create_file_in_own_library(factories, uploaded_audio_file):
    user = factories["users.User"]()
    library = factories["music.Library"](actor__user=user)
Eliot Berriot's avatar
Eliot Berriot committed
278
    s = serializers.UploadForOwnerSerializer(
279
280
281
282
283
284
285
286
        data={
            "library": library.uuid,
            "source": "upload://test",
            "audio_file": uploaded_audio_file,
        },
        context={"user": user},
    )
    assert s.is_valid(raise_exception=True) is True
Eliot Berriot's avatar
Eliot Berriot committed
287
    upload = s.save()
288

Eliot Berriot's avatar
Eliot Berriot committed
289
    assert upload.library == library
290
291
292
293
294
295
296
297
298
299
300


def test_create_file_checks_for_user_quota(
    factories, preferences, uploaded_audio_file, mocker
):
    mocker.patch(
        "funkwhale_api.users.models.User.get_quota_status",
        return_value={"remaining": 0},
    )
    user = factories["users.User"]()
    library = factories["music.Library"](actor__user=user)
Eliot Berriot's avatar
Eliot Berriot committed
301
    s = serializers.UploadForOwnerSerializer(
302
303
304
305
306
307
308
309
310
311
312
        data={
            "library": library.uuid,
            "source": "upload://test",
            "audio_file": uploaded_audio_file,
        },
        context={"user": user},
    )
    assert s.is_valid() is False
    assert s.errors["non_field_errors"] == ["upload_quota_reached"]


Eliot Berriot's avatar
Eliot Berriot committed
313
314
315
316
317
318
319
def test_manage_upload_action_delete(factories, queryset_equal_list, mocker):
    dispatch = mocker.patch("funkwhale_api.federation.routes.outbox.dispatch")
    library1 = factories["music.Library"]()
    library2 = factories["music.Library"]()
    library1_uploads = factories["music.Upload"].create_batch(size=3, library=library1)
    library2_uploads = factories["music.Upload"].create_batch(size=3, library=library2)
    s = serializers.UploadActionSerializer(queryset=None)
320

Eliot Berriot's avatar
Eliot Berriot committed
321
    s.handle_delete(library1_uploads[0].__class__.objects.all())
322

Eliot Berriot's avatar
Eliot Berriot committed
323
324
325
326
327
328
329
330
331
    assert library1_uploads[0].__class__.objects.count() == 0
    dispatch.assert_any_call(
        {"type": "Delete", "object": {"type": "Audio"}},
        context={"uploads": library1_uploads},
    )
    dispatch.assert_any_call(
        {"type": "Delete", "object": {"type": "Audio"}},
        context={"uploads": library2_uploads},
    )
332
333


Eliot Berriot's avatar
Eliot Berriot committed
334
def test_manage_upload_action_relaunch_import(factories, mocker):
335
336
337
    m = mocker.patch("funkwhale_api.common.utils.on_commit")

    # this one is finished and should stay as is
Eliot Berriot's avatar
Eliot Berriot committed
338
    finished = factories["music.Upload"](import_status="finished")
339
    draft = factories["music.Upload"](import_status="draft")
340
341

    to_relaunch = [
Eliot Berriot's avatar
Eliot Berriot committed
342
343
344
        factories["music.Upload"](import_status="pending"),
        factories["music.Upload"](import_status="skipped"),
        factories["music.Upload"](import_status="errored"),
345
    ]
Eliot Berriot's avatar
Eliot Berriot committed
346
    s = serializers.UploadActionSerializer(queryset=None)
347

Eliot Berriot's avatar
Eliot Berriot committed
348
    s.handle_relaunch_import(models.Upload.objects.all())
349
350
351
352

    for obj in to_relaunch:
        obj.refresh_from_db()
        assert obj.import_status == "pending"
353
        m.assert_any_call(tasks.process_upload.delay, upload_id=obj.pk)
354
355
356

    finished.refresh_from_db()
    assert finished.import_status == "finished"
357
358
    draft.refresh_from_db()
    assert draft.import_status == "draft"
359
    assert m.call_count == 3
360
361


362
363
364
365
366
367
368
369
370
371
372
373
374
def test_manage_upload_action_publish(factories, mocker):
    m = mocker.patch("funkwhale_api.common.utils.on_commit")

    draft = factories["music.Upload"](import_status="draft")
    s = serializers.UploadActionSerializer(queryset=None)

    s.handle_publish(models.Upload.objects.all())

    draft.refresh_from_db()
    assert draft.import_status == "pending"
    m.assert_any_call(tasks.process_upload.delay, upload_id=draft.pk)


375
def test_serialize_upload(factories):
376
377
378
379
380
381
382
383
384
385
    upload = factories["music.Upload"]()

    expected = {
        "listen_url": upload.listen_url,
        "uuid": str(upload.uuid),
        "size": upload.size,
        "bitrate": upload.bitrate,
        "mimetype": upload.mimetype,
        "extension": upload.extension,
        "duration": upload.duration,
386
        "is_local": False,
387
388
    }

389
390
    data = serializers.serialize_upload(upload)
    assert data == expected
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415


@pytest.mark.parametrize(
    "field,before,after",
    [
        ("privacy_level", "me", "everyone"),
        ("name", "Before", "After"),
        ("description", "Before", "After"),
    ],
)
def test_update_library_privacy_level_broadcasts_to_followers(
    factories, field, before, after, mocker
):
    dispatch = mocker.patch("funkwhale_api.federation.routes.outbox.dispatch")
    library = factories["music.Library"](**{field: before})

    serializer = serializers.LibraryForOwnerSerializer(
        library, data={field: after}, partial=True
    )
    assert serializer.is_valid(raise_exception=True)
    serializer.save()

    dispatch.assert_called_once_with(
        {"type": "Update", "object": {"type": "Library"}}, context={"library": library}
    )
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525


def test_upload_with_channel(factories, uploaded_audio_file):
    channel = factories["audio.Channel"](attributed_to__local=True)
    user = channel.attributed_to.user
    data = {
        "channel": channel.uuid,
        "audio_file": uploaded_audio_file,
        "import_status": "draft",
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )
    assert serializer.is_valid(raise_exception=True) is True
    upload = serializer.save()

    assert upload.library == channel.library


def test_upload_with_not_owned_channel_fails(factories, uploaded_audio_file):
    channel = factories["audio.Channel"]()
    user = factories["users.User"]()
    data = {
        "channel": channel.uuid,
        "audio_file": uploaded_audio_file,
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )
    assert serializer.is_valid() is False
    assert "channel" in serializer.errors


def test_upload_with_not_owned_library_fails(factories, uploaded_audio_file):
    library = factories["music.Library"]()
    user = factories["users.User"]()
    data = {
        "library": library.uuid,
        "audio_file": uploaded_audio_file,
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )
    assert serializer.is_valid() is False
    assert "library" in serializer.errors


def test_upload_requires_library_or_channel(factories, uploaded_audio_file):
    user = factories["users.User"]()
    data = {
        "audio_file": uploaded_audio_file,
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )

    with pytest.raises(
        serializers.serializers.ValidationError,
        match=r"You need to specify a channel or a library",
    ):
        serializer.is_valid(raise_exception=True)


def test_upload_requires_library_or_channel_but_not_both(
    factories, uploaded_audio_file
):
    channel = factories["audio.Channel"](attributed_to__local=True)
    library = channel.library
    user = channel.attributed_to.user
    data = {
        "audio_file": uploaded_audio_file,
        "library": library.uuid,
        "channel": channel.uuid,
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )
    with pytest.raises(
        serializers.serializers.ValidationError,
        match=r"You may specify a channel or a library, not both",
    ):
        serializer.is_valid(raise_exception=True)


def test_upload_import_metadata_serializer_simple():
    serializer = serializers.ImportMetadataSerializer(data={"title": "hello"})

    assert serializer.is_valid(raise_exception=True) is True
    assert serializer.validated_data == {"title": "hello"}


def test_upload_import_metadata_serializer_full():
    licenses.load(licenses.LICENSES)
    data = {
        "title": "hello",
        "mbid": "3220fd02-5237-4952-8394-b7e64b0204a6",
        "tags": ["politics", "gender"],
        "license": "cc-by-sa-4.0",
        "copyright": "My work",
        "position": 42,
    }
    expected = data.copy()
    expected["license"] = models.License.objects.get(code=data["license"])
    expected["mbid"] = uuid.UUID(data["mbid"])
    serializer = serializers.ImportMetadataSerializer(data=data)

    assert serializer.is_valid(raise_exception=True) is True
    assert serializer.validated_data == expected


526
527
528
529
530
531
532
533
534
535
536
537
def test_upload_import_metadata_serializer_channel_checks_owned_album(factories):
    channel = factories["audio.Channel"]()
    album = factories["music.Album"]()
    data = {"title": "hello", "album": album.pk}
    serializer = serializers.ImportMetadataSerializer(
        data=data, context={"channel": channel}
    )

    with pytest.raises(serializers.serializers.ValidationError):
        serializer.is_valid(raise_exception=True)


538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
def test_upload_with_channel_keeps_import_metadata(factories, uploaded_audio_file):
    channel = factories["audio.Channel"](attributed_to__local=True)
    user = channel.attributed_to.user
    data = {
        "channel": channel.uuid,
        "audio_file": uploaded_audio_file,
        "import_metadata": {"title": "hello"},
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )
    assert serializer.is_valid(raise_exception=True) is True
    upload = serializer.save()

    assert upload.import_metadata == data["import_metadata"]


def test_upload_with_channel_validates_import_metadata(factories, uploaded_audio_file):
    channel = factories["audio.Channel"](attributed_to__local=True)
    user = channel.attributed_to.user
    data = {
        "channel": channel.uuid,
        "audio_file": uploaded_audio_file,
        "import_metadata": {"title": None},
    }
    serializer = serializers.UploadForOwnerSerializer(
        data=data, context={"user": user},
    )
    with pytest.raises(serializers.serializers.ValidationError):
        assert serializer.is_valid(raise_exception=True)
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585


@pytest.mark.parametrize(
    "factory_name, serializer_class",
    [
        ("music.Artist", serializers.ArtistWithAlbumsSerializer),
        ("music.Album", serializers.AlbumSerializer),
        ("music.Track", serializers.TrackSerializer),
    ],
)
def test_detail_serializers_with_description_description(
    factory_name, serializer_class, factories
):
    content = factories["common.Content"]()
    obj = factories[factory_name](description=content)
    expected = common_serializers.ContentSerializer(content).data
    serializer = serializer_class(obj, context={"description": True})
    assert serializer.data["description"] == expected
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606


def test_sort_uploads_for_listen(factories):
    local_upload = factories["music.Upload"](library__local=True)
    new_local_upload = factories["music.Upload"](library__local=True)
    remote_upload = factories["music.Upload"](audio_file__from_path=None)
    remote_upload_with_local_version = factories["music.Upload"]()

    unsorted = [
        remote_upload_with_local_version,
        new_local_upload,
        remote_upload,
        local_upload,
    ]
    expected = [
        local_upload,
        new_local_upload,
        remote_upload,
        remote_upload_with_local_version,
    ]
    assert serializers.sort_uploads_for_listen(unsorted) == expected