Beispiel #1
0
def test_upload_owner_serializer(factories, to_api_date):
    upload = factories["music.Upload"](
        import_status="success",
        import_details={"hello": "world"},
        import_metadata={"import": "metadata"},
        import_reference="ref",
        metadata={"test": "metadata"},
        source="upload://test",
    )

    expected = {
        "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,
        "creation_date": upload.creation_date.isoformat().split("+")[0] + "Z",
        "metadata": {"test": "metadata"},
        "import_metadata": {"import": "metadata"},
        "import_date": None,
        "import_status": "success",
        "import_details": {"hello": "world"},
        "source": "upload://test",
        "import_reference": "ref",
    }
    serializer = serializers.UploadForOwnerSerializer(upload)
    assert serializer.data == expected
Beispiel #2
0
def test_user_can_get_his_favorites(api_request, factories, logged_in_client,
                                    client):
    r = api_request.get("/")
    favorite = factories["favorites.TrackFavorite"](user=logged_in_client.user)
    factories["favorites.TrackFavorite"]()
    url = reverse("api:v1:favorites:tracks-list")
    response = logged_in_client.get(url, {"user": logged_in_client.user.pk})
    expected = [{
        "user":
        users_serializers.UserBasicSerializer(favorite.user,
                                              context={
                                                  "request": r
                                              }).data,
        "track":
        music_serializers.TrackSerializer(favorite.track,
                                          context={
                                              "request": r
                                          }).data,
        "id":
        favorite.id,
        "creation_date":
        favorite.creation_date.isoformat().replace("+00:00", "Z"),
    }]
    expected[0]["track"]["is_playable"] = False
    assert response.status_code == 200
    assert response.data["results"] == expected
Beispiel #3
0
def test_track_serializer(factories, to_api_date):
    actor = factories["federation.Actor"]()
    upload = factories["music.Upload"](
        track__license="cc-by-4.0",
        track__copyright="test",
        track__disc_number=2,
        track__attributed_to=actor,
        track__with_cover=True,
    )
    track = upload.track
    setattr(track, "playable_uploads", [upload])
    expected = {
        "id": track.id,
        "fid": track.fid,
        "artist": serializers.serialize_artist_simple(track.artist),
        "album": serializers.TrackAlbumSerializer(track.album).data,
        "mbid": str(track.mbid),
        "title": track.title,
        "position": track.position,
        "disc_number": track.disc_number,
        "uploads": [serializers.serialize_upload(upload)],
        "creation_date": to_api_date(track.creation_date),
        "listen_url": track.listen_url,
        "license": upload.track.license.code,
        "copyright": upload.track.copyright,
        "is_local": upload.track.is_local,
        "tags": [],
        "attributed_to": federation_serializers.APIActorSerializer(actor).data,
        "cover":
        common_serializers.AttachmentSerializer(track.attachment_cover).data,
        "downloads_count": track.downloads_count,
    }
    serializer = serializers.TrackSerializer(track)
    assert serializer.data == expected
Beispiel #4
0
def test_listening_serializer(factories, to_api_date):
    listening = factories["history.Listening"]()
    actor = listening.user.create_actor()

    expected = {
        "id": listening.pk,
        "creation_date": to_api_date(listening.creation_date),
        "track": music_serializers.TrackSerializer(listening.track).data,
        "actor": federation_serializers.APIActorSerializer(actor).data,
        "user": users_serializers.UserBasicSerializer(listening.user).data,
    }
    serializer = serializers.ListeningSerializer(listening)

    assert serializer.data == expected
Beispiel #5
0
def test_track_favorite_serializer(factories, to_api_date):
    favorite = factories["favorites.TrackFavorite"]()
    actor = favorite.user.create_actor()

    expected = {
        "id": favorite.pk,
        "creation_date": to_api_date(favorite.creation_date),
        "track": music_serializers.TrackSerializer(favorite.track).data,
        "actor": federation_serializers.APIActorSerializer(actor).data,
        "user": users_serializers.UserBasicSerializer(favorite.user).data,
    }
    serializer = serializers.UserTrackFavoriteSerializer(favorite)

    assert serializer.data == expected
Beispiel #6
0
def test_upload_serializer(factories, to_api_date):
    upload = factories["music.Upload"]()

    expected = {
        "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,
        "creation_date": upload.creation_date.isoformat().split("+")[0] + "Z",
        "import_date": None,
        "import_status": "pending",
    }
    serializer = serializers.UploadSerializer(upload)
    assert serializer.data == expected
Beispiel #7
0
def test_track_list_serializer(api_request, factories, logged_in_api_client):
    track = factories["music.Upload"](library__privacy_level="everyone",
                                      import_status="finished").track
    request = api_request.get("/")
    qs = track.__class__.objects.all()
    serializer = serializers.TrackSerializer(qs,
                                             many=True,
                                             context={"request": request})
    expected = {
        "count": 1,
        "next": None,
        "previous": None,
        "results": serializer.data
    }
    expected["results"][0]["is_playable"] = True
    url = reverse("api:v1:tracks-list")
    response = logged_in_api_client.get(url)

    assert response.status_code == 200
    assert response.data == expected
Beispiel #8
0
def test_track_serializer(factories, to_api_date):
    upload = factories["music.Upload"]()
    track = upload.track

    expected = {
        "id": track.id,
        "artist": serializers.ArtistSimpleSerializer(track.artist).data,
        "album": serializers.TrackAlbumSerializer(track.album).data,
        "mbid": str(track.mbid),
        "title": track.title,
        "position": track.position,
        "is_playable": None,
        "creation_date": to_api_date(track.creation_date),
        "lyrics": track.get_lyrics_url(),
        "listen_url": track.listen_url,
        "duration": None,
        "size": None,
        "bitrate": None,
        "mimetype": None,
    }
    serializer = serializers.TrackSerializer(track)
    assert serializer.data == expected