Files
mtusi2026lab2/student_tests/test_access.py
T

48 lines
1.8 KiB
Python

import requests
from conftest import base_url, auth
def test_foreign_chat_get(base_url, eve, chat):
response = requests.get(f"{base_url}/api/v1/chats/{chat['id']}",
headers=auth(eve))
assert response.status_code == 404
assert response.json()["error"]["code"] == "not_found"
def test_foreign_chat_messages(base_url, eve, chat):
response = requests.get(f"{base_url}/api/v1/chats/{chat['id']}/messages",
headers=auth(eve))
assert response.status_code == 404
assert response.json()["error"]["code"] == "not_found"
def test_foreign_chat_send_messages(base_url, eve, chat):
response = requests.post(f"{base_url}/api/v1/chats/{chat['id']}/messages",
headers=auth(eve),
json={"text": "Hello, I miss you"},
)
assert response.status_code == 404
assert response.json()["error"]["code"] == "not_found"
def test_foreign_chat_not_in_list(base_url, eve, chat):
response = requests.get(f"{base_url}/api/v1/chats?limit=100", headers=auth(eve))
assert response.status_code == 200
chat_ids = [c["id"] for c in response.json()["items"]]
assert chat["id"] not in chat_ids
def test_invalid_chat_id_format(base_url, alice):
response = requests.get(f"{base_url}/api/v1/chats/wrong_id",
headers=auth(alice))
assert response.status_code == 400
assert response.json()["error"]["code"] == "invalid_request"
def test_nonexistent_chat(base_url, alice):
response = requests.get(f"{base_url}/api/v1/chats/00000000-0000-0000-0000-000000000000",
headers=auth(alice))
assert response.status_code == 404
assert response.json()["error"]["code"] == "not_found"