Ejemplo n.º 1
0
    def test_create_music_with_invalid_tag(self, create_valid_data, user_info):
        session = get_session()

        with pytest.raises(Exception):
            music_services.insert_music(
                session, {
                    **create_valid_data, "user_id": user_info["id"],
                    "tag_id": 1
                })
Ejemplo n.º 2
0
    def test_insert_music_with_invalid_user_id(self, create_valid_data,
                                               create_invalid_data, user_info):
        session = get_session()

        with pytest.raises(Exception):
            music_services.insert_music(
                session,
                {
                    **create_valid_data,
                    "user_id": 17,
                },
                MusicRepository,
            )
Ejemplo n.º 3
0
    def test_insert_music_with_invalid_artist(self, create_valid_data,
                                              create_invalid_data, user_info):
        session = get_session()

        with pytest.raises(ValidationError):
            music_services.insert_music(
                session,
                {
                    **create_valid_data,
                    "artist": create_invalid_data["artist"],
                    "user_id": user_info["id"],
                },
                MusicRepository,
            )
Ejemplo n.º 4
0
    def test_list_musics_with_valid_data(self, create_valid_data_list,
                                         user_info):
        session = get_session()

        for music in create_valid_data_list:
            music_services.insert_music(session, music, MusicRepository)

        musics = music_services.list_user_musics(session, user_info["id"],
                                                 UserRepository)

        for music_arg, music_added in zip(create_valid_data_list, musics):
            assert music_arg["name"] == music_added.name
            assert music_arg["artist"] == music_added.artist
            assert music_arg["info"] == music_added.info
Ejemplo n.º 5
0
    def test_create_music_with_valid_tag(self, create_valid_data,
                                         create_valid_data_music_tag,
                                         user_info):
        session = get_session()

        tag = music_tag_services.create_music_tag(
            session,
            {
                **create_valid_data_music_tag, "user_id": user_info["id"]
            },
            MusicTagRepository,
        )

        music = music_services.insert_music(
            session,
            {
                **create_valid_data, "user_id": user_info["id"],
                "tag_id": tag.id
            },
            MusicRepository,
        )

        assert music.name == create_valid_data["name"]
        assert music.artist == create_valid_data["artist"]
        assert music.info == create_valid_data["info"]
        assert music.album == create_valid_data["album"]
        assert music.tag_id == tag.id
Ejemplo n.º 6
0
    def test_insert_music_with_valid_data(self, create_valid_data, user_info):
        session = get_session()

        music = music_services.insert_music(
            session, {
                **create_valid_data, "user_id": user_info["id"]
            }, MusicRepository)

        assert music.name == create_valid_data["name"]
        assert music.artist == create_valid_data["artist"]
        assert music.info == create_valid_data["info"]
Ejemplo n.º 7
0
def music_route():
    session = get_session()
    try:
        music = music_services.insert_music(
            session,
            {
                **dict(request.json), "user_id": request.user_info["id"]
            },
            MusicRepository,
        )
        return music.dict(), 200
    except ValidationError as e:
        error = CustomValidationError(e)
        return error.message, 400
    except Exception as error:
        return error.message, 400