コード例 #1
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
 def test_failing_request_but_no_retries_returns_failed(self):
     fail = failed_response()
     success = ok_response()
     sender = mock_sender(fail, success)
     s = RetryingSender(sender=sender)
     r = s.send(mock_request())
     assert r is fail
コード例 #2
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    def test_retry_returns_on_first_success(self):
        fail = failed_response()
        success = ok_response()
        sender = mock_sender(fail, fail, success, fail, success)

        s = RetryingSender(retries=5, sender=sender)
        with patch(module + '.time', MagicMock()):
            s.send(mock_request())
        assert sender.send.call_count == 3
コード例 #3
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    def test_rate_limited_request_retried_after_set_seconds(self):
        time = MagicMock()
        fail = rate_limit_response()
        success = ok_response()
        sender = mock_sender(fail, success)

        s = RetryingSender(sender=sender)
        with patch(module + '.time', time):
            s.send(mock_request())
            time.sleep.assert_called_once_with(1 + 1)
コード例 #4
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    def test_default_retry_after_is_one(self):
        time = MagicMock()
        fail = rate_limit_response()
        del fail.headers['Retry-After']
        success = ok_response()
        sender = mock_sender(fail, success)

        s = RetryingSender(sender=sender)
        with patch(module + '.time', time):
            s.send(mock_request())
            time.sleep.assert_called_once_with(1 + 1)
コード例 #5
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    def test_rate_limited_retry_doesnt_decrease_retry_count(self):
        fail = failed_response()
        rate = rate_limit_response()
        success = ok_response()
        sender = mock_sender(fail, rate, fail, success)

        s = RetryingSender(retries=2, sender=sender)
        with patch(module + '.time', MagicMock()):
            s.send(mock_request())

        assert sender.send.call_count == 4
コード例 #6
0
    def __init__(self, config, app=None):
        self.config = config
        self.loop = asyncio.get_event_loop()
        self.app = app
        self.device = None
        self.user_pause = False
        self.task = None
        self.active = False
        self.running = True
        self.info = {}
        self.user_info = {}
        self.token = None
        self.spotify = Spotify()
        self.last_update = None
        self.credentials = Credentials(self.config.client_id,
                                       self.config.client_secret,
                                       self.config.client_redirect_uri)
        self.sender = RetryingSender(sender=AsyncSender())

        self.playback_device_name = self.config.default_device

        self.user_info = {}
        self.now_playing_data = {}
        self.loop.run_until_complete(self.load_auth())

        self.backup_playlist = self.loop.run_until_complete(
            self.load_and_confirm('backup_playlist'))
        self.user_playlist = self.loop.run_until_complete(
            self.load_and_confirm('user_playlist'))
        self.recent_picks = self.loop.run_until_complete(
            self.load_and_confirm('recent_picks'))
        self.blacklist = self.loop.run_until_complete(self.load_blacklist())
        self.idle_timeout = 300
        self.current_track_user = None
コード例 #7
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    async def test_async_retry_returns_on_first_success(self):
        fail = failed_response()
        success = ok_response()
        sender = mock_sender(fail, fail, success, fail, is_async=True)

        s = RetryingSender(retries=5, sender=sender)
        with patch(module + '.asyncio', AsyncMock()):
            await s.send(mock_request())
        assert sender.send.call_count == 3
コード例 #8
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    async def test_async_failing_request_retried_max_times(self):
        fail = failed_response()
        success = ok_response()
        sender = mock_sender(fail, fail, fail, success, is_async=True)

        s = RetryingSender(retries=2, sender=sender)
        with patch(module + '.asyncio', AsyncMock()):
            await s.send(mock_request())
        assert sender.send.call_count == 3
コード例 #9
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    async def test_async_rate_limited_request_retried_after_set_seconds(self):
        asyncio = AsyncMock()
        fail = rate_limit_response()
        success = ok_response()
        sender = mock_sender(fail, success, is_async=True)

        s = RetryingSender(sender=sender)
        with patch(module + '.asyncio', asyncio):
            await s.send(mock_request())
            asyncio.sleep.assert_called_once_with(1 + 1)
コード例 #10
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    async def test_async_default_retry_after_is_one(self):
        asyncio = AsyncMock()
        fail = rate_limit_response()
        del fail.headers['Retry-After']
        success = ok_response()
        sender = mock_sender(fail, success, is_async=True)

        s = RetryingSender(sender=sender)
        with patch(module + '.asyncio', asyncio):
            await s.send(mock_request())
            asyncio.sleep.assert_called_once_with(1 + 1)
コード例 #11
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
    async def test_async_rate_limited_retry_doesnt_decrease_retry_count(self):
        fail = failed_response()
        rate = rate_limit_response()
        success = ok_response()
        sender = mock_sender(fail, rate, fail, success, is_async=True)

        s = RetryingSender(retries=2, sender=sender)
        with patch(module + '.asyncio', AsyncMock()):
            await s.send(mock_request())

        assert sender.send.call_count == 4
コード例 #12
0
ファイル: retrying.py プロジェクト: oroddlokken/tekore
 def test_repr(self):
     s = RetryingSender()
     assert repr(s).startswith('RetryingSender(')