ЛР 2: PostgreSQL, Redis-сессии и проверки на оценку 4
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Human-readable demonstration. Passwords and session tokens stay in memory."""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
|
||||
from client import Client
|
||||
|
||||
c = Client()
|
||||
alice, bob, eve, chat = c.bootstrap()
|
||||
print('1. Readiness 200; registered three users; Basic login returned Bearer sessions.')
|
||||
print('2. Created chat:', chat['id'], '; members: Alice and Bob.')
|
||||
message = c.message(alice, chat, 'Привет, Боб! Это лабораторная 2.')['json']
|
||||
print('3. POST message -> 201; message id:', message['id'])
|
||||
page = c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages', actor=bob, schema='MessagePage')['json']
|
||||
assert page['items'] == [message]
|
||||
print('4. Bob reads Alice\'s committed message -> 200:', message['text'])
|
||||
c.call('GET', '/api/v1/chats/' + chat['id'], 404, actor=eve)
|
||||
print('5. Eve is authenticated but not a chat member -> 404.')
|
||||
c.call('GET', '/api/v1/users/me', 401, headers={'X-User-Id': alice['id']})
|
||||
print('6. X-User-Id without Bearer -> 401.')
|
||||
c.call('DELETE', '/api/v1/auth/sessions/current', 204, actor=alice)
|
||||
c.call('GET', '/api/v1/users/me', 401, actor=alice)
|
||||
print('7. Logout -> 204; previous token -> 401. Demo PASS.')
|
||||
Reference in New Issue
Block a user