Пример #1
0
    async def test_push_with_none_value_reverse_does_nothing(self):
        key = MagicMock()
        redis_list = RedisList(None, key)

        result = await redis_list.push(None, reverse=True)

        self.assertIsNone(result)
Пример #2
0
    async def test_enqueue_with_none_value_does_nothing(self):
        key = MagicMock()
        redis_list = RedisList(None, key)

        result = await redis_list.enqueue(None)

        self.assertIsNone(result)
Пример #3
0
    def test_get_range_passes_correct_defaults(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.get_range()

        redis.lrange.assert_called_once_with(key, 0, -1, encoding='utf-8')
        self.assertEqual(result, redis.lrange.return_value)
Пример #4
0
    def test_pop_with_block_and_default_timeout_blpops_with_zero_timeout(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.pop(block=True)

        redis.blpop.assert_called_once_with(key, timeout=0, encoding='utf-8')
        self.assertEqual(result, redis.blpop.return_value)
Пример #5
0
    def test_length_returns_length(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.length()

        redis.llen.assert_called_once_with(key)
        self.assertEqual(result, redis.llen.return_value)
Пример #6
0
    def test_pop_with_default_block_lpops(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.pop()

        redis.lpop.assert_called_once_with(key, encoding='utf-8')
        self.assertEqual(result, redis.lpop.return_value)
Пример #7
0
    async def test_find_index_when_value_not_present_returns_none(self):
        redis = AsyncMock()
        redis.lrange.return_value = ['test', 'this']
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = await redis_list.find_index('me')

        self.assertIsNone(result)
Пример #8
0
    def test_requeue_without_block_rpoplpushes(self):
        redis = MagicMock()
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.requeue(block=False, encoding=encoding)

        redis.rpoplpush.assert_called_once_with(key, key, encoding=encoding)
        self.assertEqual(result, redis.rpoplpush.return_value)
Пример #9
0
    def test_dequeue_with_no_block_rpops(self):
        redis = MagicMock()
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.dequeue(encoding=encoding)

        redis.rpop.assert_called_once_with(key, encoding=encoding)
        self.assertEqual(result, redis.rpop.return_value)
Пример #10
0
    def test_remove_with_no_count_removes_with_zero_count(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)
        value = MagicMock()

        result = redis_list.remove(value)

        redis.lrem.assert_called_once_with(key, 0, value)
        self.assertEqual(result, redis.lrem.return_value)
Пример #11
0
    async def test_find_index_uses_correct_defaults(self):
        redis = AsyncMock()
        redis.lrange.return_value = ['test', 'this', 'for', 'me']
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = await redis_list.find_index('this')

        redis.lrange.assert_awaited_once_with(key, 0, -1, encoding='utf-8')
        self.assertEqual(result, 1)
Пример #12
0
    def test_enqueue_with_values_lpushes(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)
        values = [MagicMock() for _ in range(8)]

        result = redis_list.enqueue(*values)

        redis.lpush.assert_called_once_with(key, *values)
        self.assertEqual(result, redis.lpush.return_value)
Пример #13
0
    async def test_find_index_with_non_zero_start_adds_start_to_index(self):
        redis = AsyncMock()
        redis.lrange.return_value = ['test', 'this', 'for', 'me']
        key = MagicMock()
        redis_list = RedisList(redis, key)
        start = 5

        result = await redis_list.find_index('me', start=start)

        self.assertEqual(result, 8)
Пример #14
0
    def test_pop_with_no_block_lpops(self):
        redis = MagicMock()
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.pop(block=False, encoding=encoding)

        redis.lpop.assert_called_once_with(key, encoding=encoding)
        self.assertEqual(result, redis.lpop.return_value)
Пример #15
0
    def test_pop_with_reverse_and_default_block_rpops(self):
        redis = MagicMock()
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.pop(reverse=True, encoding=encoding)

        redis.rpop.assert_called_once_with(key, encoding=encoding)
        self.assertEqual(result, redis.rpop.return_value)
Пример #16
0
    def test_push_with_values_and_reverse_rpushes(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)
        values = [MagicMock() for _ in range(8)]

        result = redis_list.push(*values, reverse=True)

        redis.rpush.assert_called_once_with(key, *values)
        self.assertEqual(result, redis.rpush.return_value)
Пример #17
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')
Пример #18
0
    def test_dequeue_with_block_and_default_timeout_brpops_with_zero_timeout(
            self):
        redis = MagicMock()
        key = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.dequeue(block=True, encoding=encoding)

        redis.brpop.assert_called_once_with(key, timeout=0, encoding=encoding)
        self.assertEqual(result, redis.brpop.return_value)
Пример #19
0
    def test_requeue_with_block_default_timeout_brpoplpushes_with_default_timeout(
            self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.requeue(block=True)

        redis.brpoplpush.assert_called_once_with(key,
                                                 key,
                                                 timeout=0,
                                                 encoding='utf-8')
        self.assertEqual(result, redis.brpoplpush.return_value)
Пример #20
0
    async def test_find_index_with_stop_uses_stop(self):
        redis = AsyncMock()
        redis.lrange.side_effect = [['test', 'this', 'for', 'me'], ['because']]
        key = MagicMock()
        redis_list = RedisList(redis, key)
        start = 5
        stop = 9

        result = await redis_list.find_index('something',
                                             start=start,
                                             stop=stop,
                                             batch_size=4)

        self.assertIsNone(result)
Пример #21
0
    async def test_find_index_with_stop_finds_result(self):
        redis = AsyncMock()
        redis.lrange.side_effect = [['test', 'this', 'for', 'me'],
                                    ['because', 'something', 'happened']]
        key = MagicMock()
        redis_list = RedisList(redis, key)
        start = 5
        stop = 12

        result = await redis_list.find_index('something',
                                             start=start,
                                             stop=stop,
                                             batch_size=4)

        self.assertEqual(result, 10)
Пример #22
0
    def test_get_range_works_correctly(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)
        start = MagicMock()
        stop = MagicMock()
        encoding = MagicMock()

        result = redis_list.get_range(start, stop, encoding=encoding)

        redis.lrange.assert_called_once_with(key,
                                             start,
                                             stop,
                                             encoding=encoding)
        self.assertEqual(result, redis.lrange.return_value)
Пример #23
0
    def test_dequeue_with_block_brpops(self):
        redis = MagicMock()
        key = MagicMock()
        timeout = MagicMock()
        encoding = MagicMock()
        redis_list = RedisList(redis, key)

        result = redis_list.dequeue(block=True,
                                    timeout_seconds=timeout,
                                    encoding=encoding)

        redis.brpop.assert_called_once_with(key,
                                            timeout=timeout,
                                            encoding=encoding)
        self.assertEqual(result, redis.brpop.return_value)
Пример #24
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)
Пример #25
0
    def test_move_with_block_brpoplpushes(self):
        redis = MagicMock()
        key = MagicMock()
        redis_list = RedisList(redis, key)
        destination_key = MagicMock()
        timeout = MagicMock()
        encoding = MagicMock()

        result = redis_list.move(destination_key,
                                 block=True,
                                 timeout_seconds=timeout,
                                 encoding=encoding)

        redis.brpoplpush.assert_called_once_with(key,
                                                 destination_key,
                                                 timeout=timeout,
                                                 encoding=encoding)
        self.assertEqual(result, redis.brpoplpush.return_value)
Пример #26
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)
        ])
Пример #27
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)
        ])
Пример #28
0
    async def test_find_index_when_value_present_returns_index(self):
        redis = AsyncMock()
        redis.lrange.side_effect = [['test', 'this'], ['for', 'me']]
        key = MagicMock()
        redis_list = RedisList(redis, key)
        start = 0
        stop = 3
        batch_size = 2
        encoding = MagicMock()

        result = await redis_list.find_index('for',
                                             start=start,
                                             stop=stop,
                                             batch_size=batch_size,
                                             encoding=encoding)

        self.assertEqual(result, 2)
        redis.lrange.assert_has_awaits([
            call(key, 0, 1, encoding=encoding),
            call(key, 2, 3, encoding=encoding)
        ])
Пример #29
0
    def test_init_succeeds(self):
        redis_list = RedisList(MagicMock(), MagicMock())

        self.assertIsInstance(redis_list, RedisList)