51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
# retoor <retoor@molodetz.nl>
|
|||
|
|
JSON = {"Accept": "application/json"}
|
||
|
|
|
||
|
|
|
||
|
|
def _create(admin, **overrides):
|
||
|
|
payload = {"title": "Een echte notitie", "body": "Tekst met **nadruk** en `code`.", "topic": "rol", "status": "draft"}
|
||
|
|
payload.update(overrides)
|
||
|
|
response = admin.post("/admin/posts", json=payload, headers=JSON)
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
return response.json()["data"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_create_draft_is_hidden_then_published(admin, anon):
|
||
|
|
data = _create(admin, title="Concept dat later live gaat")
|
||
|
|
assert anon.get(f"/posts/{data['slug']}").status_code == 404
|
||
|
|
assert admin.post(f"/admin/posts/{data['uid']}/publish", headers=JSON).status_code == 200
|
||
|
|
page = anon.get(f"/posts/{data['slug']}")
|
||
|
|
assert page.status_code == 200
|
||
|
|
assert "<strong>nadruk</strong>" in page.text
|
||
|
|
|
||
|
|
|
||
|
|
def test_edit_post(admin, anon):
|
||
|
|
data = _create(admin, title="Te bewerken notitie", status="published")
|
||
|
|
response = admin.post(f"/admin/posts/{data['uid']}", json={"title": "Bewerkte notitie", "body": "Nieuwe tekst hier.", "topic": "standaard", "status": "published"}, headers=JSON)
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
posts = anon.get("/standaard", headers=JSON).json()["posts"]
|
||
|
|
assert any(post["title"] == "Bewerkte notitie" for post in posts)
|
||
|
|
|
||
|
|
|
||
|
|
def test_delete_goes_to_trash(admin, anon):
|
||
|
|
data = _create(admin, title="Weg ermee notitie", status="published")
|
||
|
|
assert admin.post(f"/admin/posts/{data['uid']}/delete", headers=JSON).status_code == 200
|
||
|
|
assert anon.get(f"/posts/{data['slug']}").status_code == 404
|
||
|
|
trash = admin.get("/admin/trash", headers=JSON).json()["items"]
|
||
|
|
assert any(item["uid"] == data["uid"] for item in trash)
|
||
|
|
|
||
|
|
|
||
|
|
def test_validation_error(admin):
|
||
|
|
response = admin.post("/admin/posts", json={"title": "x"}, headers=JSON)
|
||
|
|
assert response.status_code == 422
|
||
|
|
|
||
|
|
|
||
|
|
def test_html_form_post(admin):
|
||
|
|
response = admin.post("/admin/posts", data={"title": "Via formulier", "body": "Formuliertekst hier.", "topic": "rol", "status": "draft"})
|
||
|
|
assert response.status_code in (302, 303)
|
||
|
|
|
||
|
|
|
||
|
|
def test_member_cannot_write(member):
|
||
|
|
response = member.post("/admin/posts", json={"title": "Niet toegestaan", "body": "Tekst hier.", "topic": "rol"}, headers=JSON)
|
||
|
|
assert response.status_code == 403
|