Exemplo n.º 1
0
    async def test_extract_replay_id_on_previous_id_older(self):
        self.replay_storage.set_replay_marker = mock.CoroutineMock()
        prev_marker = ReplayMarker(date=(datetime.now(timezone.utc) -
                                         timedelta(seconds=1)).isoformat(),
                                   replay_id="old_id")
        self.replay_storage.get_replay_marker = mock.CoroutineMock(
            return_value=prev_marker)
        date = datetime.now(timezone.utc).isoformat()
        self.replay_storage.get_message_date = \
            mock.MagicMock(return_value=date)
        id_value = "id"
        message = {
            "channel": "/foo/bar",
            "data": {
                "event": {
                    "createdDate": date,
                    "replayId": id_value
                }
            }
        }

        await self.replay_storage.extract_replay_id(message)

        self.replay_storage.set_replay_marker.assert_called_with(
            message["channel"], ReplayMarker(date=date, replay_id=id_value))
        self.replay_storage.get_message_date.assert_called()
Exemplo n.º 2
0
    async def test_set_replay_marker(self):
        self.storage.mapping = mock.MagicMock()
        subscription = "/foo/bar"
        marker = ReplayMarker(date="", replay_id="id")

        await self.storage.set_replay_marker(subscription, marker)

        self.storage.mapping.__setitem__.assert_called_with(
            subscription, marker)
Exemplo n.º 3
0
    async def test_get_replay_id_returns_marker_id(self):
        marker = ReplayMarker(date="", replay_id="id")
        subscription = "/foo/bar"
        self.storage.get_replay_marker = mock.CoroutineMock(
            return_value=marker)

        result = await self.storage.get_replay_id(subscription)

        self.assertEqual(result, marker.replay_id)
        self.storage.get_replay_marker.assert_called_with(subscription)
Exemplo n.º 4
0
    async def test_get_replay_marker(self):
        subscription = "/foo/bar"
        marker = ReplayMarker(date="", replay_id="id")
        self.storage.mapping = mock.MagicMock()
        self.storage.mapping.__getitem__.return_value = marker

        result = await self.storage.get_replay_marker(subscription)

        self.assertEqual(result, marker)
        self.storage.mapping.__getitem__.assert_called_with(subscription)
Exemplo n.º 5
0
 async def test_set_replay_marker(self):
     marker = ReplayMarker(date="", replay_id="id")
     await self.replay_storage.set_replay_marker("subscription", marker)