Пример #1
0
    def test_with_enum(self):
        with patch.object(APIClient, "__call__") as playlist_mock:
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            urls = [
                AdditionalAudioUrl.HTTP_128_MP3,
                AdditionalAudioUrl.HTTP_24_AACPLUS_ADTS,
            ]

            desired = "HTTP_128_MP3,HTTP_24_AACPLUS_ADTS"

            client.get_playlist("token_mock", additional_urls=urls)

            playlist_mock.assert_has_calls(
                [
                    call(
                        "station.getPlaylist",
                        additionalAudioUrl=desired,
                        audioAdPodCapable=True,
                        includeTrackLength=True,
                        stationToken="token_mock",
                        xplatformAdCapable=True,
                    )
                ]
            )
Пример #2
0
    def test_non_iterable_string(self):
        with self.assertRaises(TypeError):
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            client.get_playlist('token_mock', additional_urls='')
Пример #3
0
    def test_non_iterable_string(self):
        with self.assertRaises(TypeError):
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            client.get_playlist("token_mock", additional_urls="")
Пример #4
0
    def test_non_iterable_other(self):
        with self.assertRaises(TypeError):
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            client.get_playlist('token_mock',
                                additional_urls=AdditionalAudioUrl.HTTP_32_WMA)
Пример #5
0
    def test_ad_support_enabled_parameters(self):
        with patch.object(APIClient, '__call__') as playlist_mock:
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            client.get_playlist('token_mock')

            playlist_mock.assert_has_calls([call("station.getPlaylist",
                                             audioAdPodCapable=True,
                                             includeTrackLength=True,
                                             stationToken='token_mock',
                                             xplatformAdCapable=True)])
Пример #6
0
    def test_ad_support_enabled_parameters(self):
        with patch.object(APIClient, '__call__') as playlist_mock:
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            client.get_playlist('token_mock')

            playlist_mock.assert_has_calls([
                call("station.getPlaylist",
                     audioAdPodCapable=True,
                     includeTrackLength=True,
                     stationToken='token_mock',
                     xplatformAdCapable=True)
            ])
Пример #7
0
    def test_with_enum(self):
        with patch.object(APIClient, '__call__') as playlist_mock:
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

            client = APIClient(transport, None, None, None, None)
            client._authenticate = Mock()

            urls = [AdditionalAudioUrl.HTTP_128_MP3,
                    AdditionalAudioUrl.HTTP_24_AACPLUS_ADTS]

            desired = 'HTTP_128_MP3,HTTP_24_AACPLUS_ADTS'

            client.get_playlist('token_mock', additional_urls=urls)

            playlist_mock.assert_has_calls([call("station.getPlaylist",
                                                 additionalAudioUrl=desired,
                                                 audioAdPodCapable=True,
                                                 includeTrackLength=True,
                                                 stationToken='token_mock',
                                                 xplatformAdCapable=True)])
Пример #8
0
    def test_playlist_fetches_ads(self):
        fake_playlist = {"items": [
            {"songName": "test"},
            {"adToken": "foo"},
            {"songName": "test"},
        ]}
        with patch.object(APIClient, '__call__', return_value=fake_playlist):
            client = APIClient(Mock(), None, None, None, None)
            client._authenticate = Mock()

            items = client.get_playlist('token_mock')
            self.assertIsInstance(items[1], AdItem)
Пример #9
0
    def test_playlist_fetches_ads(self):
        fake_playlist = {
            "items": [
                {"songName": "test"},
                {"adToken": "foo"},
                {"songName": "test"},
            ]
        }
        with patch.object(APIClient, "__call__", return_value=fake_playlist):
            client = APIClient(Mock(), None, None, None, None)
            client._authenticate = Mock()

            items = client.get_playlist("token_mock")
            self.assertIsInstance(items[1], AdItem)