2026-10-05 09:36:20 +02:00
# retoor <retoor@molodetz.nl>
JSON = { "Accept" : "application/json" }
def _create ( admin , ** overrides ):
2026-10-05 11:25:41 +02:00
payload = { "title" : "A real note" , "body" : "Text with **emphasis** and `code`." , "topic" : "roll" , "status" : "draft" }
2026-10-05 09:36:20 +02:00
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 ):
2026-10-05 11:25:41 +02:00
data = _create ( admin , title = "Draft that goes live later" )
2026-10-05 09:36:20 +02:00
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
2026-10-05 11:25:41 +02:00
assert "<strong>emphasis</strong>" in page . text
2026-10-05 09:36:20 +02:00
def test_edit_post ( admin , anon ):
2026-10-05 11:25:41 +02:00
data = _create ( admin , title = "Note to edit" , status = "published" )
response = admin . post ( f "/admin/posts/ { data [ 'uid' ] } " , json = { "title" : "Edited note" , "body" : "New text right here." , "topic" : "standard" , "status" : "published" }, headers = JSON )
2026-10-05 09:36:20 +02:00
assert response . status_code == 200 , response . text
2026-10-05 11:25:41 +02:00
posts = anon . get ( "/standard" , headers = JSON ) . json ()[ "posts" ]
assert any ( post [ "title" ] == "Edited note" for post in posts )
2026-10-05 09:36:20 +02:00
def test_delete_goes_to_trash ( admin , anon ):
2026-10-05 11:25:41 +02:00
data = _create ( admin , title = "Gone with it note" , status = "published" )
2026-10-05 09:36:20 +02:00
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 ):
2026-10-05 11:25:41 +02:00
response = admin . post ( "/admin/posts" , data = { "title" : "Via the form" , "body" : "Form text right here." , "topic" : "roll" , "status" : "draft" })
2026-10-05 09:36:20 +02:00
assert response . status_code in ( 302 , 303 )
def test_member_cannot_write ( member ):
2026-10-05 11:25:41 +02:00
response = member . post ( "/admin/posts" , json = { "title" : "Not allowed" , "body" : "Text right here." , "topic" : "roll" }, headers = JSON )
2026-10-05 09:36:20 +02:00
assert response . status_code == 403