@@ -338,16 +338,18 @@ def test_admin_can_hide_comment(db):
338338
339339
340340def test_total_num_responses_excludes_shadowed (db ):
341+ from couchers .context import make_background_user_context # noqa: PLC0415
341342 from couchers .servicers .threads import total_num_responses # noqa: PLC0415
342343
343344 author , author_token = generate_user ()
344345 viewer , _ = generate_user ()
345346 parent_thread_id , _ = _make_thread_and_comment (author_token , content = "one" )
347+ viewer_context = make_background_user_context (user_id = viewer .id )
346348
347349 parent_db_id , _ = divmod (parent_thread_id , 10 )
348350
349351 with session_scope () as session :
350- assert total_num_responses (session , viewer . id , parent_db_id ) == 0
352+ assert total_num_responses (session , viewer_context , parent_db_id ) == 0
351353
352354 with session_scope () as session :
353355 state = session .execute (
@@ -359,18 +361,20 @@ def test_total_num_responses_excludes_shadowed(db):
359361 state .visibility = ModerationVisibility .visible
360362
361363 with session_scope () as session :
362- assert total_num_responses (session , viewer . id , parent_db_id ) == 1
364+ assert total_num_responses (session , viewer_context , parent_db_id ) == 1
363365
364366
365367def test_total_num_responses_includes_own_shadowed (db ):
366- """The count uses the viewer's id so authors see their own shadowed content in the total,
368+ """The count uses the viewer's context so authors see their own shadowed content in the total,
367369 matching what GetThread shows them in the list."""
370+ from couchers .context import make_background_user_context # noqa: PLC0415
368371 from couchers .servicers .threads import total_num_responses # noqa: PLC0415
369372
370373 author , author_token = generate_user ()
371374 parent_thread_id , _ = _make_thread_and_comment (author_token , content = "one" )
375+ author_context = make_background_user_context (user_id = author .id )
372376
373377 parent_db_id , _ = divmod (parent_thread_id , 10 )
374378
375379 with session_scope () as session :
376- assert total_num_responses (session , author . id , parent_db_id ) == 1
380+ assert total_num_responses (session , author_context , parent_db_id ) == 1
0 commit comments