ЛР 2: мессенджер на PostgreSQL и сессии в Redis
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
def test_rejects_malformed_json(client):
|
||||
client.call(
|
||||
'POST', '/api/v1/users', 400, raw=b'{"username":',
|
||||
headers={'Content-Type': 'application/json'},
|
||||
)
|
||||
|
||||
|
||||
def test_rejects_duplicate_username(actors):
|
||||
client, alice, _, _, _ = actors
|
||||
client.call('POST', '/api/v1/users', 409, body=alice['registration'])
|
||||
|
||||
|
||||
def test_hides_chat_from_outsider(actors):
|
||||
client, _, _, eve, chat = actors
|
||||
client.call('GET', '/api/v1/chats/' + chat['id'], 404, actor=eve)
|
||||
|
||||
|
||||
def test_rejects_blank_message(actors):
|
||||
client, alice, _, _, chat = actors
|
||||
client.call(
|
||||
'POST', '/api/v1/chats/' + chat['id'] + '/messages', 400,
|
||||
actor=alice, body={'text': ' \t\n '},
|
||||
)
|
||||
|
||||
|
||||
def test_requires_user_header(client):
|
||||
client.call('GET', '/api/v1/users/me', 401)
|
||||
|
||||
|
||||
def test_rejects_invalid_chat_uuid(actors):
|
||||
client, alice, _, _, _ = actors
|
||||
client.call('GET', '/api/v1/chats/not-a-uuid', 400, actor=alice)
|
||||
|
||||
|
||||
def test_rejects_title_longer_than_100(actors):
|
||||
client, alice, _, _, _ = actors
|
||||
client.call(
|
||||
'POST', '/api/v1/chats', 400, actor=alice,
|
||||
body={'title': 'x' * 101, 'member_ids': [alice['id']]},
|
||||
)
|
||||
|
||||
|
||||
def test_rejects_display_name_longer_than_100(client):
|
||||
client.call(
|
||||
'POST', '/api/v1/users', 400,
|
||||
body={'username': 'long_display_name', 'display_name': 'x' * 101},
|
||||
)
|
||||
|
||||
|
||||
def test_rejects_chat_without_creator(actors):
|
||||
client, alice, _, eve, _ = actors
|
||||
client.call(
|
||||
'POST', '/api/v1/chats', 400, actor=alice,
|
||||
body={'title': 'Без создателя', 'member_ids': [eve['id']]},
|
||||
)
|
||||
|
||||
|
||||
def test_rejects_duplicate_chat_members(actors):
|
||||
client, alice, _, _, _ = actors
|
||||
client.call(
|
||||
'POST', '/api/v1/chats', 400, actor=alice,
|
||||
body={'title': 'Дубликат', 'member_ids': [alice['id'], alice['id']]},
|
||||
)
|
||||
|
||||
|
||||
def test_rejects_unexpected_json_field(client):
|
||||
client.call(
|
||||
'POST', '/api/v1/users', 400,
|
||||
body={'username': 'extra_field', 'display_name': 'Extra field', 'role': 'admin'},
|
||||
)
|
||||
|
||||
|
||||
def test_rejects_zero_page_limit(actors):
|
||||
client, alice, _, _, chat = actors
|
||||
client.call('GET', '/api/v1/chats/' + chat['id'] + '/messages?limit=0', 400, actor=alice)
|
||||
|
||||
|
||||
def test_rejects_invalid_cursor(actors):
|
||||
client, alice, _, _, chat = actors
|
||||
client.call(
|
||||
'GET', '/api/v1/chats/' + chat['id'] + '/messages?cursor=not-a-cursor', 400, actor=alice,
|
||||
)
|
||||
Reference in New Issue
Block a user