@@ -183,6 +183,13 @@ def test_update_discussion(db):
183183 assert res .title == "Updated title"
184184 assert res .content == "Updated content"
185185 assert res .can_edit
186+ assert res .last_edited is not None
187+
188+ with discussions_session (token ) as api :
189+ res = api .GetDiscussion (discussions_pb2 .GetDiscussionReq (discussion_id = discussion_id ))
190+ assert res .title == "Updated title"
191+ assert res .content == "Updated content"
192+ assert res .last_edited is not None
186193
187194
188195def test_update_discussion_permission_denied (db ):
@@ -263,18 +270,20 @@ def test_delete_discussion_by_creator(db):
263270 assert res .thread .thread_id != 0
264271
265272
266- def test_delete_discussion_by_moderator (db ):
273+ def test_delete_discussion_permission_denied_for_non_creator (db ):
267274 creator , creator_token = generate_user ()
268- moderator , moderator_token = generate_user ()
275+ community_admin , community_admin_token = generate_user ()
269276 random_user , random_token = generate_user ()
270277 with session_scope () as session :
271- community = create_community (session , 0 , 1 , "Testing Community" , [moderator ], [creator , random_user ], None )
278+ community = create_community (
279+ session , 0 , 1 , "Testing Community" , [community_admin ], [creator , random_user ], None
280+ )
272281 community_id = community .id
273282
274283 with discussions_session (creator_token ) as api :
275284 res = api .CreateDiscussion (
276285 discussions_pb2 .CreateDiscussionReq (
277- title = "To be moderated " ,
286+ title = "Only creator can delete " ,
278287 content = "Some content" ,
279288 owner_community_id = community_id ,
280289 )
@@ -287,10 +296,10 @@ def test_delete_discussion_by_moderator(db):
287296 api .DeleteDiscussion (discussions_pb2 .DeleteDiscussionReq (discussion_id = discussion_id ))
288297 assert e .value .code () == grpc .StatusCode .PERMISSION_DENIED
289298
290- with discussions_session (moderator_token ) as api :
291- api . DeleteDiscussion ( discussions_pb2 . DeleteDiscussionReq ( discussion_id = discussion_id ))
292- res = api .GetDiscussion (discussions_pb2 .GetDiscussionReq (discussion_id = discussion_id ))
293- assert res . deleted
299+ with discussions_session (community_admin_token ) as api :
300+ with pytest . raises ( grpc . RpcError ) as e :
301+ api .DeleteDiscussion (discussions_pb2 .DeleteDiscussionReq (discussion_id = discussion_id ))
302+ assert e . value . code () == grpc . StatusCode . PERMISSION_DENIED
294303
295304
296305def test_deleted_discussion_not_in_list (db ):
@@ -326,7 +335,7 @@ def test_deleted_discussion_not_in_list(db):
326335 assert deleted_id not in ids
327336
328337
329- def test_deleted_discussion_thread_still_accessible (db ):
338+ def test_deleted_discussion_thread_still_accessible (db , moderator : Moderator ):
330339 user , token = generate_user ()
331340 commenter , commenter_token = generate_user ()
332341 with session_scope () as session :
@@ -347,7 +356,8 @@ def test_deleted_discussion_thread_still_accessible(db):
347356 process_jobs ()
348357
349358 with threads_session (commenter_token ) as api :
350- api .PostReply (threads_pb2 .PostReplyReq (thread_id = thread_id , content = "a comment" ))
359+ comment_thread_id = api .PostReply (threads_pb2 .PostReplyReq (thread_id = thread_id , content = "a comment" )).thread_id
360+ moderator .approve_thread_post (comment_thread_id )
351361
352362 with discussions_session (token ) as api :
353363 api .DeleteDiscussion (discussions_pb2 .DeleteDiscussionReq (discussion_id = discussion_id ))
@@ -360,7 +370,7 @@ def test_deleted_discussion_thread_still_accessible(db):
360370 assert len (res .replies ) == 1
361371
362372
363- def test_delete_comment_shows_placeholder_with_replies (db ):
373+ def test_delete_comment_shows_placeholder_with_replies (db , moderator : Moderator ):
364374 """Deleting a top-level comment that has nested replies should show a deleted
365375 placeholder so the replies remain visible."""
366376 user , token = generate_user ()
@@ -383,13 +393,22 @@ def test_delete_comment_shows_placeholder_with_replies(db):
383393
384394 # commenter adds a top-level comment
385395 with threads_session (commenter_token ) as api :
386- comment_res = api .PostReply (threads_pb2 .PostReplyReq (thread_id = thread_id , content = "top-level comment" ))
387- comment_thread_id = comment_res .thread_id
396+ comment_thread_id = api .PostReply (
397+ threads_pb2 .PostReplyReq (thread_id = thread_id , content = "top-level comment" )
398+ ).thread_id
388399
389400 # replier adds two nested replies
390401 with threads_session (replier_token ) as api :
391- api .PostReply (threads_pb2 .PostReplyReq (thread_id = comment_thread_id , content = "nested reply 1" ))
392- api .PostReply (threads_pb2 .PostReplyReq (thread_id = comment_thread_id , content = "nested reply 2" ))
402+ reply_thread_id_1 = api .PostReply (
403+ threads_pb2 .PostReplyReq (thread_id = comment_thread_id , content = "nested reply 1" )
404+ ).thread_id
405+ reply_thread_id_2 = api .PostReply (
406+ threads_pb2 .PostReplyReq (thread_id = comment_thread_id , content = "nested reply 2" )
407+ ).thread_id
408+
409+ moderator .approve_thread_post (comment_thread_id )
410+ moderator .approve_thread_post (reply_thread_id_1 )
411+ moderator .approve_thread_post (reply_thread_id_2 )
393412
394413 # commenter deletes their top-level comment
395414 with threads_session (commenter_token ) as api :
0 commit comments