from urllib.parse import quote from tests.helpers import create_chat def test_walks_all_pages_without_duplicates(actors): client, alice, _, _, _ = actors chat = create_chat(client, alice, 'Пагинация') sent = [client.message(alice, chat, 'страница ' + str(i))['json']['id'] for i in range(5)] received, cursor = [], None while True: suffix = '?limit=2' if cursor: suffix += '&cursor=' + quote(cursor, safe='') page = client.call( 'GET', '/api/v1/chats/' + chat['id'] + '/messages' + suffix, actor=alice, schema='MessagePage', )['json'] received.extend(item['id'] for item in page['items']) cursor = page['next_cursor'] if cursor is None: break assert len(received) == 5 assert len(set(received)) == 5 assert set(received) == set(sent) def test_rejects_cursor_from_another_chat(actors): client, alice, _, _, _ = actors first = create_chat(client, alice, 'Первый чат') second = create_chat(client, alice, 'Второй чат') client.message(alice, first, 'первое') client.message(alice, first, 'второе') page = client.call( 'GET', '/api/v1/chats/' + first['id'] + '/messages?limit=1', actor=alice, schema='MessagePage', )['json'] assert page['next_cursor'] is not None client.call( 'GET', '/api/v1/chats/' + second['id'] + '/messages?cursor=' + quote(page['next_cursor'], safe=''), 400, actor=alice, )