import pytest

from musixmatch import Musixmatch

from . import results


class TestMusixmatch:
    @classmethod
    def setup_class(cls):
        cls.musixmatch = Musixmatch("test")
        cls.url = "http://api.musixmatch.com/ws/1.1/"

    def test_get_url(self):
        assert (
            self.musixmatch._get_url(
                "chart.artists.get?" "page=1&page_size=1&country=us" "&format=json",
            )
            == f"{self.url}chart.artists.get?page=1&page_size=1&country=us&format=json&apikey=test"
        )

    def test_apikey(self):
        assert self.musixmatch._apikey == "test"

    def test_chart_artists(self, requests_mock):
        json = results.CHART_ARTISTS
        url = "http://api.musixmatch.com/ws/1.1/chart.artists.get?page=1&page_size=1&country=us&format=json"
        requests_mock.get(url=url, json=json)
        request = self.musixmatch.chart_artists(1, 1)
        assert json == request

    def test_chart_tracks_get(self, requests_mock):
        json = results.TRACKS
        url = "http://api.musixmatch.com/ws/1.1/chart.tracks.get?page=1&page_size=1&country=us&format=json&f_has_lyrics=1"
        requests_mock.get(url=url, json=json)
        request = self.musixmatch.chart_tracks_get(1, 1, 1)
        assert json == request

    @pytest.mark.skip("Refactor test")
    def test_track_search(self):
        self.assertEqual(
            self.musixmatch.track_search(
                q_track="Let Me Love You",
                q_artist="justinbieber",
                page_size=10,
                page=1,
                s_track_rating="desc",
            )["message"]["body"]["track_list"],
            [],
        )

    @pytest.mark.skip("Refactor test")
    def test_track_get(self):
        self.assertEqual(
            self.musixmatch.track_get(15445219)["message"]["body"]["track"][
                "artist_name"
            ],
            "Lady Gaga",
        )
        self.assertEqual(
            self.musixmatch.track_get(15445219)["message"]["body"]["track"][
                "album_name"
            ],
            "The Fame Monster",
        )

    def test_track_lyrics_get(self, requests_mock):
        json = results.TRACKS
        url = "http://api.musixmatch.com/ws/1.1/track.lyrics.get?track_id=12345"
        requests_mock.get(url=url, json=json)
        request = self.musixmatch.track_lyrics_get(12345)
        assert json == request

    def test_track_snippet_get(self, requests_mock):
        json = results.TRACK_SNIPPET
        url = "http://api.musixmatch.com/ws/1.1/track.snippet.get?track_id=12345"
        requests_mock.get(url=url, json=json)
        request = self.musixmatch.track_snippet_get(12345)
        assert json == request

    @pytest.mark.skip("Refactor test")
    def test_track_subtitle_get(self):
        self.assertEqual(
            self.musixmatch.track_subtitle_get(14201829)["message"]["body"],
            "",
        )

    @pytest.mark.skip("Refactor test")
    def test_track_richsync_get(self):
        self.assertEqual(
            self.musixmatch.track_richsync_get(114837357)["message"]["body"][
                "richsync"
            ]["richsync_id"],
            6,
        )
        self.assertEqual(
            self.musixmatch.track_richsync_get(114837357)["message"]["body"][
                "richsync"