예제 #1
0
    def test_handle_missing_params_exception_due_to_missing_ad_tokens(self):
        with patch.object(APIClient, 'get_playlist') as get_playlist_mock:
            with patch.object(APIClient, 'register_ad', side_effect=ParameterMissing("ParameterMissing")):

                station = Station.from_json(self.client, {'stationToken': 'token_mock'})
                ad_mock = AdItem.from_json(self.client, {'station_id': 'id_mock'})
                get_playlist_mock.return_value=iter([ad_mock])

                station_iter = iterate_forever(station.get_playlist)

                next_track = next(station_iter)
                self.assertEqual(ad_mock, next_track)
예제 #2
0
    def test_prepare_playback(self):
        with patch.object(PlaylistModel, 'prepare_playback') as super_mock:

            self.result.register_ad = Mock()
            self.result.prepare_playback()
            assert self.result.register_ad.called
            assert super_mock.called
예제 #3
0
    def test_prepare_playback(self):
        with patch.object(PlaylistModel, 'prepare_playback') as super_mock:

            self.result.register_ad = Mock()
            self.result.prepare_playback()
            assert self.result.register_ad.called
            assert super_mock.called
예제 #4
0
    def test_handle_missing_params_exception_due_to_missing_ad_tokens(self):
        with patch.object(APIClient, 'get_playlist') as get_playlist_mock:
            with patch.object(
                    APIClient,
                    'register_ad',
                    side_effect=ParameterMissing("ParameterMissing")):

                station = Station.from_json(self.client,
                                            {'stationToken': 'token_mock'})
                ad_mock = AdItem.from_json(self.client,
                                           {'station_id': 'id_mock'})
                get_playlist_mock.return_value = iter([ad_mock])

                station_iter = iterate_forever(station.get_playlist)

                next_track = next(station_iter)
                self.assertEqual(ad_mock, next_track)
예제 #5
0
    def test_prepare_playback_raises_paramater_missing(self):
        with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock:

            self.result.register_ad = Mock(side_effect=ParameterMissing(
                'No ad tracking tokens provided for registration.'))
            self.assertRaises(ParameterMissing, self.result.prepare_playback)
            assert self.result.register_ad.called
            assert not super_mock.called
예제 #6
0
    def test_prepare_playback_handles_paramater_missing_if_no_tokens(self):
        with patch.object(PlaylistModel, 'prepare_playback') as super_mock:

            self.result.tracking_tokens = []
            self.result.register_ad = Mock(side_effect=ParameterMissing('No ad tracking tokens provided for '
                                                                        'registration.'))
            self.result.prepare_playback()
            assert self.result.register_ad.called
            assert super_mock.called
예제 #7
0
    def test_prepare_playback_raises_paramater_missing(self):
        with patch.object(PlaylistModel, 'prepare_playback') as super_mock:

            self.result.register_ad = Mock(side_effect=ParameterMissing('No ad tracking tokens provided for '
                                                                        'registration.')
                                           )
            self.assertRaises(ParameterMissing, self.result.prepare_playback)
            assert self.result.register_ad.called
            assert not super_mock.called
예제 #8
0
    def test_prepare_playback_handles_paramater_missing_if_no_tokens(self):
        with patch.object(pm.PlaylistModel, 'prepare_playback') as super_mock:

            self.result.tracking_tokens = []
            self.result.register_ad = Mock(side_effect=ParameterMissing(
                'No ad tracking tokens provided for registration.'))
            self.result.prepare_playback()
            assert self.result.register_ad.called
            assert super_mock.called
예제 #9
0
    def test_reraise_missing_params_exception(self):
        with patch.object(APIClient, 'get_playlist', side_effect=ParameterMissing("ParameterMissing")) as get_playlist_mock:
                with self.assertRaises(ParameterMissing):

                    station = Station.from_json(self.client, {'stationToken': 'token_mock'})
                    track_mock = PlaylistItem.from_json(self.client, {'token': 'token_mock'})
                    get_playlist_mock.return_value=iter([track_mock])

                    station_iter = iterate_forever(station.get_playlist)
                    next(station_iter)
예제 #10
0
    def test_warning(self):
        class Bar(object):
            @util.deprecated("1.0", "2.0", "Don't use this")
            def foo(self):
                pass

        with patch.object(warnings, "warn") as wmod:
            Bar().foo()

            wmod.assert_called_with(
                ("foo is deprecated as of version 1.0 and will be removed in "
                 "version 2.0. Don't use this"), DeprecationWarning)
예제 #11
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)])
예제 #12
0
    def test_reraise_missing_params_exception(self):
        plmock = patch.object(APIClient,
                              'get_playlist',
                              side_effect=ParameterMissing("ParameterMissing"))

        with plmock as get_playlist_mock:
            with self.assertRaises(ParameterMissing):
                station = Station.from_json(self.client,
                                            {'stationToken': 'token_mock'})
                track_mock = PlaylistItem.from_json(self.client,
                                                    {'token': 'token_mock'})
                get_playlist_mock.return_value = iter([track_mock])

                station_iter = iterate_forever(station.get_playlist)
                next(station_iter)
예제 #13
0
    def test_get_ad_item_(self):
        with patch.object(APIClient, '__call__',
                return_value=TestAdItem.JSON_DATA) as ad_metadata_mock:
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

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

            ad_item = client.get_ad_item('id_mock', 'token_mock')
            assert ad_item.station_id == 'id_mock'
            assert ad_item.ad_token == 'token_mock'

            ad_metadata_mock.assert_has_calls([call("ad.getAdMetadata",
                                                    adToken='token_mock',
                                                    returnAdTrackingTokens=True,
                                                    supportAudioAds=True)])
예제 #14
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)
            ])
예제 #15
0
    def test_get_ad_item_(self):
        with patch.object(
                APIClient, '__call__',
                return_value=TestAdItem.JSON_DATA) as ad_metadata_mock:
            transport = Mock(side_effect=[errors.InvalidAuthToken(), None])

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

            ad_item = client.get_ad_item('id_mock', 'token_mock')
            assert ad_item.station_id == 'id_mock'
            assert ad_item.ad_token == 'token_mock'

            ad_metadata_mock.assert_has_calls([
                call("ad.getAdMetadata",
                     adToken='token_mock',
                     returnAdTrackingTokens=True,
                     supportAudioAds=True)
            ])