Add direct-save public content API
This commit is contained in:
56
apps/content/tests/integration/test_api.py
Normal file
56
apps/content/tests/integration/test_api.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
|
||||
from apps.content.current import AboutContent, HomeContent, ListingContent
|
||||
|
||||
|
||||
pytestmark = [pytest.mark.django_db, pytest.mark.integration]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("slug", "expected_title"),
|
||||
(("home", "انجمن علمی کامپیوتر دانشگاه گیلان"), ("about", "انجمنهای علمی کامپیوتر گیلان"), ("events", "رویدادها"), ("blog", "بلاگ")),
|
||||
)
|
||||
def test_fixed_page_api_returns_current_content_without_caching(client, slug, expected_title):
|
||||
response = client.get(f"/api/v1/content/pages/{slug}")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["slug"] == slug
|
||||
assert response.json()["title"] == expected_title
|
||||
assert response["Cache-Control"] == "no-store"
|
||||
assert "seo" in response.json()
|
||||
assert "status" not in response.json()
|
||||
assert "revision" not in response.json()
|
||||
|
||||
|
||||
def test_api_returns_an_admin_save_on_the_next_request(client):
|
||||
page = HomeContent.objects.get(pk=1)
|
||||
page.hero_heading = "Saved in admin"
|
||||
page.save()
|
||||
|
||||
response = client.get("/api/v1/content/pages/home")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["hero_heading"] == "Saved in admin"
|
||||
assert response["Cache-Control"] == "no-store"
|
||||
|
||||
|
||||
def test_site_api_returns_current_identity_and_no_store_header(client):
|
||||
response = client.get("/api/v1/content/site")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["official_name"]
|
||||
assert response.json()["navigation"]["home"] == "خانه"
|
||||
assert response["Cache-Control"] == "no-store"
|
||||
|
||||
|
||||
def test_unknown_and_missing_content_return_404(client):
|
||||
assert client.get("/api/v1/content/pages/unknown").status_code == 404
|
||||
|
||||
HomeContent.objects.filter(pk=1).delete()
|
||||
assert client.get("/api/v1/content/pages/home").status_code == 404
|
||||
|
||||
ListingContent.objects.filter(slug="events").delete()
|
||||
assert client.get("/api/v1/content/pages/events").status_code == 404
|
||||
|
||||
AboutContent.objects.filter(pk=1).delete()
|
||||
assert client.get("/api/v1/content/pages/about").status_code == 404
|
||||
Reference in New Issue
Block a user