Exemplo n.º 1
0
    async def test_enumerate_with_batch_size_zero_gets_the_list_at_once(self):
        items = [MagicMock() for _ in range(12)]
        redis = AsyncMock()
        redis.lrange.return_value = items
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = [item async for item in redis_list.enumerate()]

        self.assertEqual(result, items)
        redis.lrange.assert_awaited_once_with(key, 0, -1, encoding='utf-8')
Exemplo n.º 2
0
    async def test_enumerate_with_stop_and_no_batch_size_gets_all_at_once(
            self):
        items = [MagicMock() for _ in range(10)]
        redis = AsyncMock()
        stop = 6
        redis.lrange.return_value = items[:stop + 1]
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = [
            item async for item in redis_list.enumerate(stop=stop,
                                                        encoding=encoding)
        ]

        self.assertEqual(result, items[:stop + 1])
        redis.lrange.assert_awaited_once_with(key, 0, stop, encoding=encoding)
Exemplo n.º 3
0
    async def test_enumerate_gets_correct_batches(self):
        items = [MagicMock() for _ in range(9)]
        redis = AsyncMock()
        redis.lrange.side_effect = lambda _, start, stop, **__: items[start:
                                                                      stop + 1]
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = [
            item async for item in redis_list.enumerate(batch_size=5,
                                                        encoding=encoding)
        ]

        self.assertEqual(result, items)
        redis.lrange.assert_has_awaits([
            call(key, 0, 4, encoding=encoding),
            call(key, 5, 9, encoding=encoding)
        ])
Exemplo n.º 4
0
    async def test_enumerate_with_start_and_stop_returns_correct_result(self):
        items = [MagicMock() for _ in range(11)]
        redis = AsyncMock()
        redis.lrange.side_effect = lambda _, start, stop, **__: items[start:
                                                                      stop + 1]
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = [
            item async for item in redis_list.enumerate(
                start=3, stop=9, batch_size=5, encoding=encoding)
        ]

        self.assertEqual(result, items[3:10])
        redis.lrange.assert_has_awaits([
            call(key, 3, 7, encoding=encoding),
            call(key, 8, 9, encoding=encoding)
        ])