예제 #1
0
class TestAPIClientExhaustive(TestCase):

    def setUp(self):
        self.transport = Mock()
        self.api = APIClient(self.transport, "puser", "ppass", "device")

    def test_register_ad(self):
        self.api.register_ad("sid", "tokens")
        self.transport.assert_called_with(
            "ad.registerAd", stationId="sid", adTrackingTokens="tokens")

    def test_share_music(self):
        self.api.share_music("token", "*****@*****.**")
        self.transport.assert_called_with(
            "music.shareMusic", musicToken="token", email="*****@*****.**")

    def test_transform_shared_station(self):
        self.api.transform_shared_station("token")
        self.transport.assert_called_with(
            "station.transformSharedStation", stationToken="token")

    def test_share_station(self):
        self.api.share_station("sid", "token", "*****@*****.**")
        self.transport.assert_called_with(
            "station.shareStation", stationId="sid", stationToken="token",
            emails=("*****@*****.**",))

    def test_sleep_song(self):
        self.api.sleep_song("token")
        self.transport.assert_called_with("user.sleepSong", trackToken="token")

    def test_set_quick_mix(self):
        self.api.set_quick_mix("id")
        self.transport.assert_called_with(
            "user.setQuickMix", quickMixStationIds=("id",))

    def test_explain_track(self):
        self.api.explain_track("token")
        self.transport.assert_called_with(
            "track.explainTrack", trackToken="token")

    def test_rename_station(self):
        self.api.rename_station("token", "name")
        self.transport.assert_called_with(
            "station.renameStation", stationToken="token", stationName="name")

    def test_delete_station(self):
        self.api.delete_station("token")
        self.transport.assert_called_with(
            "station.deleteStation", stationToken="token")

    def test_delete_music(self):
        self.api.delete_music("seed")
        self.transport.assert_called_with("station.deleteMusic", seedId="seed")

    def test_delete_feedback(self):
        self.api.delete_feedback("id")
        self.transport.assert_called_with(
            "station.deleteFeedback", feedbackId="id")

    def test_add_music(self):
        self.api.add_music("mt", "st")
        self.transport.assert_called_with(
            "station.addMusic", musicToken="mt", stationToken="st")

    def test_add_feedback(self):
        self.api.add_feedback("token", False)
        self.transport.assert_called_with(
            "station.addFeedback", trackToken="token", isPositive=False)

    def test_add_artist_bookmark(self):
        self.api.add_artist_bookmark("tt")
        self.transport.assert_called_with(
            "bookmark.addArtistBookmark", trackToken="tt")

    def test_add_song_bookmark(self):
        self.api.add_song_bookmark("tt")
        self.transport.assert_called_with(
            "bookmark.addSongBookmark", trackToken="tt")

    def test_delete_song_bookmark(self):
        self.api.delete_song_bookmark("bt")
        self.transport.assert_called_with(
            "bookmark.deleteSongBookmark", bookmarkToken="bt")

    def test_delete_artist_bookmark(self):
        self.api.delete_artist_bookmark("bt")
        self.transport.assert_called_with(
            "bookmark.deleteArtistBookmark", bookmarkToken="bt")

    def test_get_station_list_checksum(self):
        self.transport.return_value = {"checksum": "foo"}
        self.assertEqual("foo", self.api.get_station_list_checksum())
        self.transport.assert_called_with("user.getStationListChecksum")

    # The following methods use the bare minimum JSON required to construct the
    # models for more detailed model tests look at test_models instead

    def test_get_station_list(self):
        self.transport.return_value = {"stations": []}
        self.assertIsInstance(self.api.get_station_list(), StationList)
        self.transport.assert_called_with(
            "user.getStationList", includeStationArtUrl=True)

    def test_get_bookmarks(self):
        self.transport.return_value = {}
        self.assertIsInstance(self.api.get_bookmarks(), BookmarkList)
        self.transport.assert_called_with("user.getBookmarks")

    def test_get_station(self):
        self.transport.return_value = {}
        self.assertIsInstance(self.api.get_station("st"), Station)
        self.transport.assert_called_with(
            "station.getStation", stationToken="st",
            includeExtendedAttributes=True)

    def test_search(self):
        self.transport.return_value = {}
        self.assertIsInstance(self.api.search(
            "text", include_near_matches=True, include_genre_stations=True),
            SearchResult)
        self.transport.assert_called_with(
            "music.search", searchText="text", includeNearMatches=True,
            includeGenreStations=True)
예제 #2
0
class TestAPIClientExhaustive(TestCase):
    def setUp(self):
        self.transport = Mock()
        self.api = APIClient(self.transport, "puser", "ppass", "device")

    def test_register_ad(self):
        self.api.register_ad("sid", "tokens")
        self.transport.assert_called_with(
            "ad.registerAd", stationId="sid", adTrackingTokens="tokens"
        )

    def test_share_music(self):
        self.api.share_music("token", "*****@*****.**")
        self.transport.assert_called_with(
            "music.shareMusic", musicToken="token", email="*****@*****.**"
        )

    def test_transform_shared_station(self):
        self.api.transform_shared_station("token")
        self.transport.assert_called_with(
            "station.transformSharedStation", stationToken="token"
        )

    def test_share_station(self):
        self.api.share_station("sid", "token", "*****@*****.**")
        self.transport.assert_called_with(
            "station.shareStation",
            stationId="sid",
            stationToken="token",
            emails=("*****@*****.**",),
        )

    def test_sleep_song(self):
        self.api.sleep_song("token")
        self.transport.assert_called_with("user.sleepSong", trackToken="token")

    def test_set_quick_mix(self):
        self.api.set_quick_mix("id")
        self.transport.assert_called_with(
            "user.setQuickMix", quickMixStationIds=("id",)
        )

    def test_explain_track(self):
        self.api.explain_track("token")
        self.transport.assert_called_with(
            "track.explainTrack", trackToken="token"
        )

    def test_rename_station(self):
        self.api.rename_station("token", "name")
        self.transport.assert_called_with(
            "station.renameStation", stationToken="token", stationName="name"
        )

    def test_delete_station(self):
        self.api.delete_station("token")
        self.transport.assert_called_with(
            "station.deleteStation", stationToken="token"
        )

    def test_delete_music(self):
        self.api.delete_music("seed")
        self.transport.assert_called_with("station.deleteMusic", seedId="seed")

    def test_delete_feedback(self):
        self.api.delete_feedback("id")
        self.transport.assert_called_with(
            "station.deleteFeedback", feedbackId="id"
        )

    def test_add_music(self):
        self.api.add_music("mt", "st")
        self.transport.assert_called_with(
            "station.addMusic", musicToken="mt", stationToken="st"
        )

    def test_add_feedback(self):
        self.api.add_feedback("token", False)
        self.transport.assert_called_with(
            "station.addFeedback", trackToken="token", isPositive=False
        )

    def test_add_artist_bookmark(self):
        self.api.add_artist_bookmark("tt")
        self.transport.assert_called_with(
            "bookmark.addArtistBookmark", trackToken="tt"
        )

    def test_add_song_bookmark(self):
        self.api.add_song_bookmark("tt")
        self.transport.assert_called_with(
            "bookmark.addSongBookmark", trackToken="tt"
        )

    def test_delete_song_bookmark(self):
        self.api.delete_song_bookmark("bt")
        self.transport.assert_called_with(
            "bookmark.deleteSongBookmark", bookmarkToken="bt"
        )

    def test_delete_artist_bookmark(self):
        self.api.delete_artist_bookmark("bt")
        self.transport.assert_called_with(
            "bookmark.deleteArtistBookmark", bookmarkToken="bt"
        )

    def test_get_station_list_checksum(self):
        self.transport.return_value = {"checksum": "foo"}
        self.assertEqual("foo", self.api.get_station_list_checksum())
        self.transport.assert_called_with("user.getStationListChecksum")

    # The following methods use the bare minimum JSON required to construct the
    # models for more detailed model tests look at test_models instead

    def test_get_station_list(self):
        self.transport.return_value = {"stations": []}
        self.assertIsInstance(self.api.get_station_list(), StationList)
        self.transport.assert_called_with(
            "user.getStationList", includeStationArtUrl=True
        )

    def test_get_bookmarks(self):
        self.transport.return_value = {}
        self.assertIsInstance(self.api.get_bookmarks(), BookmarkList)
        self.transport.assert_called_with("user.getBookmarks")

    def test_get_station(self):
        self.transport.return_value = {}
        self.assertIsInstance(self.api.get_station("st"), Station)
        self.transport.assert_called_with(
            "station.getStation",
            stationToken="st",
            includeExtendedAttributes=True,
        )

    def test_search(self):
        self.transport.return_value = {}
        self.assertIsInstance(
            self.api.search(
                "text", include_near_matches=True, include_genre_stations=True
            ),
            SearchResult,
        )
        self.transport.assert_called_with(
            "music.search",
            searchText="text",
            includeNearMatches=True,
            includeGenreStations=True,
        )