/
donafisha
/
content-engine-service
Обзор
Документация
Войти
/
donafisha
/
content-engine-service
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
tests/test_admin_api.py
91 строка
3 KB
xnpelur
feat: categories
09 июн 2026, 18:05
09 июн 2026, 18:05
35debac
Код
Авторство
О чём код?
from __future__ import annotations def test_duplicate_slug_blocked_within_same_project_but_allowed_across_projects(client, seeded_projects, admin_headers): payload = { "projectId": "donafisha-guide", "type": "article", "status": "published", "slug": "shared-slug", "title": "Shared Slug", "contentJson": { "type": "doc", "content": [ { "type": "heading", "attrs": {"level": 1}, "content": [{"type": "text", "text": "Shared slug"}], } ], }, "tags": ["shared"], "commentsEnabled": True, } first = client.post("/api/v1/admin/posts", headers=admin_headers, json=payload) second = client.post("/api/v1/admin/posts", headers=admin_headers, json=payload) other_project = client.post( "/api/v1/admin/posts", headers=admin_headers, json={**payload, "projectId": "enotgpt-blog", "title": "Shared Slug Other Project"}, ) assert first.status_code == 201 assert second.status_code == 409 assert other_project.status_code == 201 def test_category_crud_is_scoped_to_project(client, seeded_projects, admin_headers): payload = {"name": "Новости", "slug": "news"} first = client.post( "/api/v1/admin/projects/donafisha-guide/categories", headers=admin_headers, json=payload, ) duplicate = client.post( "/api/v1/admin/projects/donafisha-guide/categories", headers=admin_headers, json={**payload, "name": "Другие новости"}, ) other_project = client.post( "/api/v1/admin/projects/enotgpt-blog/categories", headers=admin_headers, json=payload, ) assert first.status_code == 201 assert first.json()["projectId"] == "donafisha-guide" assert first.json()["slug"] == "news" assert duplicate.status_code == 409 assert other_project.status_code == 201 category_id = first.json()["id"] update = client.patch( f"/api/v1/admin/projects/donafisha-guide/categories/{category_id}", headers=admin_headers, json={"name": "Афиша"}, ) assert update.status_code == 200 assert update.json()["name"] == "Афиша" def test_category_delete_hides_from_lists(client, seeded_projects, admin_headers): create = client.post( "/api/v1/admin/projects/donafisha-guide/categories", headers=admin_headers, json={"name": "Events", "slug": "events"}, ) category_id = create.json()["id"] delete = client.delete( f"/api/v1/admin/projects/donafisha-guide/categories/{category_id}", headers=admin_headers, ) admin_default = client.get("/api/v1/admin/projects/donafisha-guide/categories", headers=admin_headers) public_list = client.get("/api/v1/public/donafisha-guide/categories") assert delete.status_code == 204 assert admin_default.json() == [] assert public_list.json() == []