Exemple #1
0
    def test_init(self):
        connection_timeout = 20
        max_pending_count = 1
        json_dumps = object()
        json_loads = object()
        loop = object()
        replay_storage_policy = object()

        with self.assertLogs("aiosfstream.client", "DEBUG") as log:
            client = Client(self.authenticator,
                            connection_timeout=connection_timeout,
                            max_pending_count=max_pending_count,
                            replay_storage_policy=replay_storage_policy,
                            json_dumps=json_dumps,
                            json_loads=json_loads,
                            loop=loop)

        self.assertEqual(client.url, "")
        self.assertEqual(client.auth, self.authenticator)
        self.assertEqual(client.connection_timeout, connection_timeout)
        self.assertEqual(client._max_pending_count, max_pending_count)
        self.assertEqual(client._json_dumps, json_dumps)
        self.assertEqual(client._json_loads, json_loads)
        self.assertEqual(client._loop, loop)
        self.assertEqual(log.output, [
            "DEBUG:aiosfstream.client:"
            "Client created with replay storage: {!r}, "
            "replay fallback: {!r}".format(client.replay_storage,
                                           client.replay_fallback)
        ])
        self.assertEqual(client.replay_storage_policy, replay_storage_policy)
        self.assertEqual(client.auth.json_dumps, json_dumps)
        self.assertEqual(client.auth.json_loads, json_loads)
Exemple #2
0
    def test_returns_constant_replay_id_storage_for_replay_option(self):
        replay = ReplayOption.ALL_EVENTS

        result = Client.create_replay_storage(replay)

        self.assertIsInstance(result, ConstantReplayId)
        self.assertIs(result.default_id, replay)
Exemple #3
0
    def test_returns_mapping_storage_for_dict(self):
        replay = {}

        result = Client.create_replay_storage(replay)

        self.assertIsInstance(result, MappingStorage)
        self.assertIs(result.mapping, replay)
Exemple #4
0
    def test_get(self):
        instance_url = "instance"

        result = Client.get_cometd_url(instance_url)

        self.assertEqual(result,
                         instance_url + "/" + COMETD_PATH + "/" + API_VERSION)
Exemple #5
0
    async def test_receive_doesn_extracts_replay_id_on_manual_policy(
            self, super_receive):
        super_receive.return_value = object()
        client = Client(self.authenticator,
                        replay_storage_policy=ReplayMarkerStoragePolicy.MANUAL)
        client.replay_storage.extract_replay_id = mock.CoroutineMock()

        result = await client.receive()

        self.assertEqual(result, super_receive.return_value)
        super_receive.assert_called()
        client.replay_storage.extract_replay_id.assert_not_called()
Exemple #6
0
    def test_init_creates_replay_storage(self, create_replay_storage):
        replay_param = object()
        create_replay_storage.return_value = mock.create_autospec(
            ReplayMarkerStorage)()

        client = Client(self.authenticator, replay=replay_param)

        self.assertEqual(client.auth, self.authenticator)
        self.assertEqual(client.extensions,
                         [create_replay_storage.return_value])
        self.assertEqual(client.replay_storage,
                         create_replay_storage.return_value)
        self.assertIsNone(client.replay_fallback)
        create_replay_storage.assert_called_with(replay_param)
Exemple #7
0
 def test_init_verifies_replay(self):
     with self.assertRaisesRegex(
             TypeError, "'str' is not a valid type for the replay "
             "parameter."):
         Client(self.authenticator, replay="fake")
Exemple #8
0
 def test_init_verifies_authenticator(self):
     with self.assertRaisesRegex(
             TypeError, f"authenticator should be an instance of "
             f"{AuthenticatorBase.__name__}."):
         Client(object())
Exemple #9
0
    def test_init_translates_errors(self, super_init):
        super_init.side_effect = AiocometdException()

        with self.assertRaises(AiosfstreamException):
            Client(self.authenticator)
Exemple #10
0
    def test_returns_none_for_invalid_param(self):
        replay = 5

        result = Client.create_replay_storage(replay)

        self.assertIsNone(result)
Exemple #11
0
    def test_returns_replay_storage(self):
        replay = mock.create_autospec(ReplayMarkerStorage)()

        result = Client.create_replay_storage(replay)

        self.assertIs(result, replay)
Exemple #12
0
 def setUp(self):
     self.authenticator = mock.create_autospec(AuthenticatorBase)
     self.client = Client(self.authenticator)