add tests
This commit is contained in:
68
cv/tests/test_views.py
Normal file
68
cv/tests/test_views.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""Интеграционные тесты Django views приложения `cv`."""
|
||||
|
||||
import logging
|
||||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
|
||||
from cv.models import Profile
|
||||
from resume.utils.logging import configure_root_logger
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
configure_root_logger()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_profile_view_context(client: Client) -> None:
|
||||
"""Контекст содержит profile при наличии записи.
|
||||
|
||||
Args:
|
||||
client (Client): Django тестовый клиент.
|
||||
"""
|
||||
logger.info("Создаём профиль и проверяем контекст главной страницы")
|
||||
Profile.objects.create(
|
||||
full_name="John Tester", role="QA", gender="male", summary="", location="", languages=[]
|
||||
)
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
assert "profile" in resp.context
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_download_pdf_ok(client: Client, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Выдача PDF c корректными заголовками.
|
||||
|
||||
Args:
|
||||
client (Client): Django тестовый клиент.
|
||||
monkeypatch (pytest.MonkeyPatch): Подмена рендера PDF.
|
||||
"""
|
||||
logger.info("Проверяем скачивание PDF с реальным роутом")
|
||||
Profile.objects.create(
|
||||
full_name="John Tester", role="QA", gender="male", summary="", location="", languages=[]
|
||||
)
|
||||
monkeypatch.setattr("cv.views.PdfRenderer.render", lambda _self, _p: BytesIO(b"%PDF"))
|
||||
resp = client.get(reverse("cv:resume-pdf"))
|
||||
assert resp.status_code == 200
|
||||
assert resp["Content-Type"] == "application/pdf"
|
||||
assert resp["Cache-Control"] == "no-store"
|
||||
assert "resume_John_Tester.pdf" in resp["Content-Disposition"]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_download_docx_ok(client: Client) -> None:
|
||||
"""Smoke: скачивание DOCX с корректными заголовками."""
|
||||
logger.info("Проверяем скачивание DOCX")
|
||||
Profile.objects.create(
|
||||
full_name="John Tester", role="QA", gender="male", summary="", location="", languages=[]
|
||||
)
|
||||
resp = client.get(reverse("cv:resume-docx"))
|
||||
assert resp.status_code == 200
|
||||
assert (
|
||||
resp["Content-Type"]
|
||||
== "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
)
|
||||
assert resp["Cache-Control"] == "no-store"
|
||||
assert "attachment; filename=" in resp["Content-Disposition"]
|
||||
assert "resume_John_Tester.docx" in resp["Content-Disposition"]
|
||||
Reference in New Issue
Block a user