コード例 #1
0
ファイル: test_utils.py プロジェクト: rgov/mopidy-pandora
def test_do_rpc_increments_id():
    requests.request = mock.PropertyMock()
    json.loads = mock.PropertyMock()

    current_id = utils.RPCClient.id
    t = utils.RPCClient._do_rpc('method_mock')
    t.join()
    assert utils.RPCClient.id == current_id + 1
コード例 #2
0
ファイル: test_uri.py プロジェクト: rgov/mopidy-pandora
def test_factory_returns_correct_station_uri_types():
    station_mock = mock.PropertyMock(spec=GenreStation)
    station_mock.id = 'G100'
    station_mock.token = 'G100'
    assert type(PandoraUri.factory(station_mock)) is GenreStationUri

    station_mock = mock.PropertyMock(spec=Station)
    station_mock.id = 'id_mock'
    station_mock.token = 'token_mock'
    assert type(PandoraUri.factory(station_mock)) is StationUri
コード例 #3
0
ファイル: test_uri.py プロジェクト: rgov/mopidy-pandora
def test_station_uri_parse_returns_correct_type():
    station_mock = mock.PropertyMock(spec=GenreStation)
    station_mock.id = 'G100'
    station_mock.token = 'G100'

    obj = StationUri._from_station(station_mock)

    assert type(obj) is GenreStationUri
コード例 #4
0
 def test_report_down_disabled(self, mc):
     with mock.patch.multiple(
             'srv.salt._modules.cephprocesses.SystemdUnit',
             is_disabled=mock.PropertyMock(return_value=True),
             _service_names=mock.Mock(return_value=[])):
         proc_name = 'ceph-mds'
         mc.up = []
         mc.down = [proc_name]
         assert mc.report() == {'up': {}, 'down': {}}
コード例 #5
0
ファイル: test_utils.py プロジェクト: rgov/mopidy-pandora
def test_do_rpc():
    utils.RPCClient.configure('host_mock', 'port_mock')
    assert utils.RPCClient.hostname == 'host_mock'
    assert utils.RPCClient.port == 'port_mock'

    response_mock = mock.PropertyMock(spec=requests.Response)
    response_mock.text = '{"result": "result_mock"}'
    requests.request = mock.PropertyMock(return_value=response_mock)

    q = queue.Queue()
    utils.RPCClient._do_rpc('method_mock',
                            params={
                                'param_mock_1': 'value_mock_1',
                                'param_mock_2': 'value_mock_2'
                            },
                            queue=q)

    assert q.get() == 'result_mock'
コード例 #6
0
    def test_only_execute_for_pandora_executes_for_pandora_uri(self):
        func_mock = mock.PropertyMock()
        func_mock.__name__ = str('func_mock')
        func_mock.return_value = True

        self.core.playback.play(tlid=self.tl_tracks[0].tlid).get()
        self.replay_events()
        frontend.only_execute_for_pandora_uris(func_mock)(self)

        assert func_mock.called
コード例 #7
0
    def test_only_execute_for_pandora_does_not_execute_for_non_pandora_uri(
            self):
        func_mock = mock.PropertyMock()
        func_mock.__name__ = str('func_mock')
        func_mock.return_value = True

        self.core.playback.play(tlid=self.tl_tracks[3].tlid)
        frontend.only_execute_for_pandora_uris(func_mock)(self)

        assert not func_mock.called
コード例 #8
0
ファイル: test_uri.py プロジェクト: rgov/mopidy-pandora
def test_genre_station_uri_from_genre_station_returns_correct_type():
    genre_station_mock = mock.PropertyMock(spec=GenreStation)
    genre_station_mock.id = 'G100'
    genre_station_mock.token = 'G100'

    obj = GenreStationUri._from_station(genre_station_mock)

    assert type(obj) is GenreStationUri

    assert obj.uri_type == 'genre_station'
    assert obj.station_id == 'G100'
    assert obj.token == 'G100'

    assert obj.uri == 'pandora:genre_station:G100:G100'
コード例 #9
0
ファイル: test_uri.py プロジェクト: rgov/mopidy-pandora
def test_genre_station_uri_from_station_returns_correct_type():
    genre_mock = mock.PropertyMock(spec=Station)
    genre_mock.id = 'id_mock'
    genre_mock.token = 'token_mock'

    obj = StationUri._from_station(genre_mock)

    assert type(obj) is StationUri

    assert obj.uri_type == 'station'
    assert obj.station_id == 'id_mock'
    assert obj.token == 'token_mock'

    assert obj.uri == 'pandora:station:id_mock:token_mock'
コード例 #10
0
    def test_only_execute_for_pandora_does_not_execute_for_malformed_pandora_uri(
            self):
        func_mock = mock.PropertyMock()
        func_mock.__name__ = str('func_mock')
        func_mock.return_value = True

        tl_track_mock = mock.Mock(spec=models.TlTrack)
        track_mock = mock.Mock(spec=models.Track)
        track_mock.uri = 'pandora:invalid_uri'
        tl_track_mock.track = track_mock
        frontend.only_execute_for_pandora_uris(func_mock)(
            self, tl_track=tl_track_mock)

        assert not func_mock.called
コード例 #11
0
    def setUpClass(cls):
        super(BaseRpcTestCase, cls).setUpClass()

        __import__('django_rpc.celery.tasks')
        # noinspection PyUnresolvedReferences
        p = mock.patch.object(Task,
                              'apply_async',
                              side_effect=celery_passthrough,
                              autospec=True)
        cls._apply_async_patcher = p
        p.start()
        p = mock.patch('django_rpc.celery.client.RpcClient._app',
                       new_callable=mock.PropertyMock(return_value=app.celery))
        cls._celery_app_patcher = p
        p.start()