37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Тесты общего предпросмотра сообщений."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def _client(client_factory) -> TestClient:
|
|
return client_factory()
|
|
|
|
|
|
def test_preview_renders_tags(client_factory, csrf_token) -> None:
|
|
client = _client(client_factory)
|
|
token = csrf_token(client.get("/send").text)
|
|
|
|
response = client.post("/preview", data={"text": "Привет, {nick}!", "csrf_token": token})
|
|
|
|
assert response.status_code == 200
|
|
assert "ТестовыйНик" in response.text
|
|
assert "<iframe" in response.text
|
|
|
|
|
|
def test_preview_reports_unknown_tag(client_factory, csrf_token) -> None:
|
|
client = _client(client_factory)
|
|
token = csrf_token(client.get("/send").text)
|
|
|
|
response = client.post("/preview", data={"text": "Привет, {unknown_tag}!", "csrf_token": token})
|
|
|
|
assert response.status_code == 200
|
|
assert "Неизвестные теги" in response.text
|
|
|
|
|
|
def test_preview_requires_csrf(client_factory) -> None:
|
|
response = _client(client_factory).post("/preview", data={"text": "Привет"})
|
|
|
|
assert response.status_code == 400
|