Beispiel #1
0
def test_manage_user_request_serializer(factories, to_api_date):
    user_request = factories["moderation.UserRequest"](signup=True,
                                                       metadata={
                                                           "foo": "bar"
                                                       },
                                                       assigned=True)
    expected = {
        "id":
        user_request.id,
        "uuid":
        str(user_request.uuid),
        "creation_date":
        to_api_date(user_request.creation_date),
        "handled_date":
        None,
        "status":
        user_request.status,
        "type":
        user_request.type,
        "submitter":
        serializers.ManageBaseActorSerializer(user_request.submitter).data,
        "assigned_to":
        serializers.ManageBaseActorSerializer(user_request.assigned_to).data,
        "metadata": {
            "foo": "bar"
        },
        "notes": [],
    }
    s = serializers.ManageUserRequestSerializer(user_request)

    assert s.data == expected
Beispiel #2
0
def test_manage_album_serializer(factories, now, to_api_date):
    album = factories["music.Album"](attributed=True, with_cover=True)
    factories["music.Track"](album=album)
    setattr(album, "_tracks_count", 42)
    expected = {
        "id":
        album.id,
        "domain":
        album.domain_name,
        "is_local":
        album.is_local,
        "fid":
        album.fid,
        "title":
        album.title,
        "mbid":
        album.mbid,
        "creation_date":
        to_api_date(album.creation_date),
        "release_date":
        album.release_date.isoformat(),
        "cover":
        common_serializers.AttachmentSerializer(album.attachment_cover).data,
        "artist":
        serializers.ManageNestedArtistSerializer(album.artist).data,
        "attributed_to":
        serializers.ManageBaseActorSerializer(album.attributed_to).data,
        "tags": [],
        "tracks_count":
        1,
    }
    s = serializers.ManageAlbumSerializer(album)

    assert s.data == expected
Beispiel #3
0
def test_manage_report_serializer(factories, to_api_date):
    artist = factories["music.Artist"](attributed=True)
    report = factories["moderation.Report"](target=artist,
                                            target_state={
                                                "hello": "world"
                                            },
                                            assigned=True)
    expected = {
        "id":
        report.id,
        "uuid":
        str(report.uuid),
        "fid":
        report.fid,
        "creation_date":
        to_api_date(report.creation_date),
        "handled_date":
        None,
        "summary":
        report.summary,
        "is_handled":
        report.is_handled,
        "type":
        report.type,
        "submitter_email":
        None,
        "submitter":
        serializers.ManageBaseActorSerializer(report.submitter).data,
        "assigned_to":
        serializers.ManageBaseActorSerializer(report.assigned_to).data,
        "target": {
            "type": "artist",
            "id": artist.pk
        },
        "target_owner":
        serializers.ManageBaseActorSerializer(artist.attributed_to).data,
        "target_state":
        report.target_state,
        "notes": [],
    }
    s = serializers.ManageReportSerializer(report)

    assert s.data == expected
Beispiel #4
0
def test_manage_channel_serializer(factories, now, to_api_date):
    channel = factories["audio.Channel"]()
    expected = {
        "id":
        channel.id,
        "uuid":
        channel.uuid,
        "artist":
        serializers.ManageArtistSerializer(channel.artist).data,
        "actor":
        serializers.ManageBaseActorSerializer(channel.actor).data,
        "attributed_to":
        serializers.ManageBaseActorSerializer(channel.attributed_to).data,
        "creation_date":
        to_api_date(channel.creation_date),
        "rss_url":
        channel.get_rss_url(),
        "metadata":
        channel.metadata,
    }
    s = serializers.ManageChannelSerializer(channel)

    assert s.data == expected
Beispiel #5
0
def test_manage_note_serializer(factories, to_api_date):
    actor = factories["federation.Actor"]()
    note = factories["moderation.Note"](target=actor)

    expected = {
        "id": note.id,
        "uuid": str(note.uuid),
        "summary": note.summary,
        "creation_date": to_api_date(note.creation_date),
        "author": serializers.ManageBaseActorSerializer(note.author).data,
        "target": {
            "type": "account",
            "full_username": actor.full_username
        },
    }
    s = serializers.ManageNoteSerializer(note)

    assert s.data == expected
Beispiel #6
0
def test_manage_track_serializer(factories, now, to_api_date):
    track = factories["music.Track"](attributed=True, with_cover=True)
    setattr(track, "uploads_count", 44)
    expected = {
        "id":
        track.id,
        "domain":
        track.domain_name,
        "is_local":
        track.is_local,
        "fid":
        track.fid,
        "title":
        track.title,
        "mbid":
        track.mbid,
        "disc_number":
        track.disc_number,
        "position":
        track.position,
        "copyright":
        track.copyright,
        "license":
        track.license,
        "creation_date":
        to_api_date(track.creation_date),
        "artist":
        serializers.ManageNestedArtistSerializer(track.artist).data,
        "album":
        serializers.ManageTrackAlbumSerializer(track.album).data,
        "attributed_to":
        serializers.ManageBaseActorSerializer(track.attributed_to).data,
        "uploads_count":
        44,
        "tags": [],
        "cover":
        common_serializers.AttachmentSerializer(track.attachment_cover).data,
    }
    s = serializers.ManageTrackSerializer(track)

    assert s.data == expected
Beispiel #7
0
def test_manage_artist_serializer(factories, now, to_api_date):
    artist = factories["music.Artist"](attributed=True, with_cover=True)
    channel = factories["audio.Channel"](artist=artist)
    # put channel in cache
    artist.get_channel()
    setattr(artist, "_tracks_count", 12)
    setattr(artist, "_albums_count", 13)
    expected = {
        "id":
        artist.id,
        "domain":
        artist.domain_name,
        "is_local":
        artist.is_local,
        "fid":
        artist.fid,
        "name":
        artist.name,
        "mbid":
        artist.mbid,
        "creation_date":
        to_api_date(artist.creation_date),
        "tracks_count":
        12,
        "albums_count":
        13,
        "attributed_to":
        serializers.ManageBaseActorSerializer(artist.attributed_to).data,
        "tags": [],
        "channel":
        str(channel.uuid),
        "content_category":
        artist.content_category,
        "cover":
        common_serializers.AttachmentSerializer(artist.attachment_cover).data,
    }
    s = serializers.ManageArtistSerializer(artist)

    assert s.data == expected
Beispiel #8
0
def test_manage_library_serializer(factories, now, to_api_date):
    library = factories["music.Library"]()
    setattr(library, "followers_count", 42)
    setattr(library, "_uploads_count", 44)
    expected = {
        "id": library.id,
        "fid": library.fid,
        "url": library.url,
        "uuid": str(library.uuid),
        "followers_url": library.followers_url,
        "domain": library.domain_name,
        "is_local": library.is_local,
        "name": library.name,
        "description": library.description,
        "privacy_level": library.privacy_level,
        "creation_date": to_api_date(library.creation_date),
        "actor": serializers.ManageBaseActorSerializer(library.actor).data,
        "uploads_count": 44,
        "followers_count": 42,
    }
    s = serializers.ManageLibrarySerializer(library)

    assert s.data == expected