This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ make test BASE_URL=http://localhost:8080
|
||||
python3 tests/smoke.py --base-url http://localhost:8080
|
||||
```
|
||||
|
||||
`smoke.py` выполняет **один сквозной сценарий**, автоматически выбирая профиль из `lab.json`: health → три пользователя → вход с lab2 → чат → сообщения → пагинация → ошибки доступа → идемпотентность с lab3 → файл с lab4 → thumbnail с lab5 → logout. Он проверяет JSON по используемому подмножеству схемы, коды/headers, Unicode, SHA-256 оригинала и фактические JPEG-размеры thumbnail. Это публичный минимум, не полный fuzz/security/load suite.
|
||||
`smoke.py` выполняет **один сквозной сценарий**, автоматически выбирая профиль из `lab.json`: health → три пользователя → вход с lab2 → несколько чатов и их keyset-пагинация → сообщения и пагинация истории → ошибки доступа → идемпотентность с lab3 → файл с lab4 → thumbnail с lab5 → logout. Он проверяет JSON по используемому подмножеству схемы, коды/headers, Unicode, отсутствие повторов/пропусков при пагинации, SHA-256 оригинала и фактические JPEG-размеры thumbnail. Это публичный минимум, не полный fuzz/security/load suite.
|
||||
|
||||
Каждый запуск создаёт уникальных синтетических пользователей, чат и сообщения. Данные автоматически не удаляются: в API курса нет delete. Для чистого повтора используйте отдельный тестовый стенд/volume и осознанный сброс своего окружения. Session tokens хранятся только в памяти процесса и не печатаются/не сохраняются.
|
||||
|
||||
|
||||
+48
-1
@@ -20,6 +20,54 @@ def main():
|
||||
check(any(x['id']==chat['id'] for x in listed['items']),'member cannot list chat')
|
||||
hidden = c.call('GET','/api/v1/chats?limit=100',actor=eve,schema='ChatPage')['json']
|
||||
check(all(x['id']!=chat['id'] for x in hidden['items']),'chat leaks to outsider')
|
||||
page_chats = [
|
||||
c.call(
|
||||
'POST',
|
||||
'/api/v1/chats',
|
||||
201,
|
||||
actor=alice,
|
||||
body={'title':'Pagination test %d' % index,'member_ids':[alice['id'],bob['id']]},
|
||||
schema='Chat',
|
||||
)['json']
|
||||
for index in range(4)
|
||||
]
|
||||
from urllib.parse import quote
|
||||
chat_pages, seen_cursors = [], set()
|
||||
cursor = None
|
||||
while True:
|
||||
query = '/api/v1/chats?limit=2'
|
||||
if cursor is not None:
|
||||
query += '&cursor=' + quote(cursor, safe='')
|
||||
page = c.call('GET',query,actor=alice,schema='ChatPage')['json']
|
||||
check(1 <= len(page['items']) <= 2,'chat page must contain at most the requested limit')
|
||||
chat_pages.extend(page['items'])
|
||||
cursor = page['next_cursor']
|
||||
if cursor is None:
|
||||
break
|
||||
check(cursor not in seen_cursors,'chat pagination cursor repeated')
|
||||
seen_cursors.add(cursor)
|
||||
check(len(seen_cursors) <= 3,'chat pagination did not finish within expected pages')
|
||||
chat_ids = [item['id'] for item in chat_pages]
|
||||
check(len(chat_ids)==len(set(chat_ids)),'chat pagination duplicated an item')
|
||||
check({item['id'] for item in page_chats + [chat]} <= set(chat_ids),'chat pagination lost a chat')
|
||||
ordered_chats = sorted(
|
||||
chat_pages,
|
||||
key=lambda item:(timestamp(item['created_at']),uuid.UUID(item['id']).int),
|
||||
)
|
||||
check(chat_pages==ordered_chats,'chat pagination is not ordered by (created_at, id)')
|
||||
check(
|
||||
chat_pages == c.call('GET','/api/v1/chats?limit=100',actor=alice,schema='ChatPage')['json']['items'],
|
||||
'chat pages differ from the complete chat list',
|
||||
)
|
||||
c.call('GET','/api/v1/chats?limit=2&cursor=not-a-valid-cursor',400,actor=alice)
|
||||
if page['next_cursor'] is None and seen_cursors:
|
||||
foreign_cursor = next(iter(seen_cursors))
|
||||
c.call(
|
||||
'GET',
|
||||
'/api/v1/chats?limit=2&cursor=' + quote(foreign_cursor,safe=''),
|
||||
400,
|
||||
actor=bob,
|
||||
)
|
||||
key = uuid.uuid4().hex
|
||||
first = c.message(alice,chat,'Привет, мир 👋',key=key)['json']
|
||||
second = c.message(bob,chat,'Сообщение Боба')['json']
|
||||
@@ -28,7 +76,6 @@ def main():
|
||||
check(first['text']=='Привет, мир 👋' and second['text']=='Сообщение Боба','message text changed')
|
||||
page1 = c.call('GET',path+'/messages?limit=1',actor=bob,schema='MessagePage')['json']
|
||||
check(len(page1['items'])==1 and page1['next_cursor'],'first page must have one item and cursor')
|
||||
from urllib.parse import quote
|
||||
page2 = c.call('GET',path+'/messages?limit=1&cursor='+quote(page1['next_cursor'],safe=''),actor=alice,schema='MessagePage')['json']
|
||||
check(len(page2['items'])==1 and page2['next_cursor'] is None,'second page must finish history')
|
||||
ordered = sorted([first,second],key=lambda x:(timestamp(x['created_at']),uuid.UUID(x['id']).int))
|
||||
|
||||
Reference in New Issue
Block a user