Ejemplo n.º 1
0
    async def test_publish_error(self):
        response = {"channel": "/channel1", "successful": False, "id": "1"}
        data = {}
        self.client._transport = mock.MagicMock()
        self.client._transport.publish = mock.CoroutineMock(
            return_value=response)
        self.client._check_server_disconnected = mock.CoroutineMock()
        self.client._closed = False
        error = ServerError("Publish request failed.", response)

        with self.assertRaisesRegex(ServerError, str(error)):
            await self.client.publish("channel1", data)

        self.client._transport.publish.assert_called_with("channel1", data)
        self.client._check_server_disconnected.assert_called()
Ejemplo n.º 2
0
    async def test_unsubscribe_error(self):
        response = {
            "channel": MetaChannel.UNSUBSCRIBE,
            "successful": False,
            "subscription": "channel1",
            "id": "1"
        }
        self.client._transport = mock.MagicMock()
        self.client._transport.unsubscribe = mock.CoroutineMock(
            return_value=response)
        self.client._check_server_disconnected = mock.CoroutineMock()
        self.client._closed = False
        error = ServerError("Unsubscribe request failed.", response)

        with self.assertRaisesRegex(ServerError, str(error)):
            await self.client.unsubscribe("channel1")

        self.client._transport.unsubscribe.assert_called_with("channel1")
        self.client._check_server_disconnected.assert_called()
Ejemplo n.º 3
0
    async def test_subscribe_error_with_fallback_and_storage(
            self, super_subscribe):
        channel = "/foo/bar"
        self.client.replay_fallback = object()
        self.client.replay_storage = mock.MagicMock()
        error = ServerError("message", {"error": "400::server_message"})
        super_subscribe.side_effect = [error, None]

        with self.assertLogs("aiosfstream.client", "WARNING") as log:
            await self.client.subscribe(channel)

        super_subscribe.assert_has_calls([mock.call(channel)] * 2)
        self.assertEqual(self.client.replay_storage.replay_fallback,
                         self.client.replay_fallback)
        self.assertEqual(log.output, [
            "WARNING:aiosfstream.client:"
            "Subscription failed with message: {!r}, "
            "retrying subscription with {!r}.".format(
                "server_message", self.client.replay_fallback)
        ])