Files
resume/cv/tests/test_views.py
Pavel Sobolev 80911bd538 add tests
2025-11-13 21:30:45 +03:00

69 lines
2.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Интеграционные тесты 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"]