@@ -2150,18 +2150,6 @@ def test_following(self):
2150
2150
assert cs_request .method == 'POST'
2151
2151
assert parsed_body (cs_request ) == {'source_type' : ['thread' ], 'source_id' : ['test_id' ]}
2152
2152
2153
- def test_abuse_flagged (self ):
2154
- self .register_post_thread_response ({"id" : "test_id" , "username" : self .user .username })
2155
- self .register_thread_flag_response ("test_id" )
2156
- data = self .minimal_data .copy ()
2157
- data ["abuse_flagged" ] = "True"
2158
- result = create_thread (self .request , data )
2159
- assert result ['abuse_flagged' ] is True
2160
- cs_request = httpretty .last_request ()
2161
- assert urlparse (cs_request .path ).path == '/api/v1/threads/test_id/abuse_flag' # lint-amnesty, pylint: disable=no-member
2162
- assert cs_request .method == 'PUT'
2163
- assert parsed_body (cs_request ) == {'user_id' : [str (self .user .id )]}
2164
-
2165
2153
def test_course_id_missing (self ):
2166
2154
with pytest .raises (ValidationError ) as assertion :
2167
2155
create_thread (self .request , {})
@@ -2510,18 +2498,6 @@ def test_endorsed(self, role_name, is_thread_author, thread_type):
2510
2498
except ValidationError :
2511
2499
assert expected_error
2512
2500
2513
- def test_abuse_flagged (self ):
2514
- self .register_post_comment_response ({"id" : "test_comment" , "username" : self .user .username }, "test_thread" )
2515
- self .register_comment_flag_response ("test_comment" )
2516
- data = self .minimal_data .copy ()
2517
- data ["abuse_flagged" ] = "True"
2518
- result = create_comment (self .request , data )
2519
- assert result ['abuse_flagged' ] is True
2520
- cs_request = httpretty .last_request ()
2521
- assert urlparse (cs_request .path ).path == '/api/v1/comments/test_comment/abuse_flag' # lint-amnesty, pylint: disable=no-member
2522
- assert cs_request .method == 'PUT'
2523
- assert parsed_body (cs_request ) == {'user_id' : [str (self .user .id )]}
2524
-
2525
2501
def test_thread_id_missing (self ):
2526
2502
with pytest .raises (ValidationError ) as assertion :
2527
2503
create_comment (self .request , {})
@@ -2957,108 +2933,6 @@ def test_vote_count_two_users(
2957
2933
assert result ['vote_count' ] == vote_count
2958
2934
self .register_get_user_response (self .user , upvoted_ids = [])
2959
2935
2960
- @ddt .data (* itertools .product ([True , False ], [True , False ]))
2961
- @ddt .unpack
2962
- @mock .patch ("eventtracking.tracker.emit" )
2963
- def test_abuse_flagged (self , old_flagged , new_flagged , mock_emit ):
2964
- """
2965
- Test attempts to edit the "abuse_flagged" field.
2966
-
2967
- old_flagged indicates whether the thread should be flagged at the start
2968
- of the test. new_flagged indicates the value for the "abuse_flagged"
2969
- field in the update. If old_flagged and new_flagged are the same, no
2970
- update should be made. Otherwise, a PUT should be made to the flag or
2971
- or unflag endpoint according to the new_flagged value.
2972
- """
2973
- self .register_get_user_response (self .user )
2974
- self .register_thread_flag_response ("test_thread" )
2975
- self .register_thread ({"abuse_flaggers" : [str (self .user .id )] if old_flagged else []})
2976
- data = {"abuse_flagged" : new_flagged }
2977
- result = update_thread (self .request , "test_thread" , data )
2978
- assert result ['abuse_flagged' ] == new_flagged
2979
- last_request_path = urlparse (httpretty .last_request ().path ).path # lint-amnesty, pylint: disable=no-member
2980
- flag_url = "/api/v1/threads/test_thread/abuse_flag"
2981
- unflag_url = "/api/v1/threads/test_thread/abuse_unflag"
2982
- if old_flagged == new_flagged :
2983
- assert last_request_path != flag_url
2984
- assert last_request_path != unflag_url
2985
- else :
2986
- assert last_request_path == (flag_url if new_flagged else unflag_url )
2987
- assert httpretty .last_request ().method == 'PUT'
2988
- assert parsed_body (httpretty .last_request ()) == {'user_id' : [str (self .user .id )]}
2989
-
2990
- expected_event_name = 'edx.forum.thread.reported' if new_flagged else 'edx.forum.thread.unreported'
2991
- expected_event_data = {
2992
- 'body' : 'Original body' ,
2993
- 'id' : 'test_thread' ,
2994
- 'content_type' : 'Post' ,
2995
- 'commentable_id' : 'original_topic' ,
2996
- 'url' : '' ,
2997
- 'user_course_roles' : [],
2998
- 'user_forums_roles' : [FORUM_ROLE_STUDENT ],
2999
- 'target_username' : self .user .username ,
3000
- 'title_truncated' : False ,
3001
- 'title' : 'Original Title' ,
3002
- 'thread_type' : 'discussion' ,
3003
- 'group_id' : None ,
3004
- 'truncated' : False ,
3005
- }
3006
- if not new_flagged :
3007
- expected_event_data ['reported_status_cleared' ] = False
3008
-
3009
- actual_event_name , actual_event_data = mock_emit .call_args [0 ]
3010
- self .assertEqual (actual_event_name , expected_event_name )
3011
- self .assertEqual (actual_event_data , expected_event_data )
3012
-
3013
- @ddt .data (
3014
- (False , True ),
3015
- (True , True ),
3016
- )
3017
- @ddt .unpack
3018
- @mock .patch ("eventtracking.tracker.emit" )
3019
- def test_thread_un_abuse_flag_for_moderator_role (self , is_author , remove_all , mock_emit ):
3020
- """
3021
- Test un-abuse flag for moderator role.
3022
-
3023
- When moderator unflags a reported thread, it should
3024
- pass the "all" flag to the api. This will indicate
3025
- to the api to clear all abuse_flaggers, and mark the
3026
- thread as unreported.
3027
- """
3028
- _assign_role_to_user (user = self .user , course_id = self .course .id , role = FORUM_ROLE_ADMINISTRATOR )
3029
- self .register_get_user_response (self .user )
3030
- self .register_thread_flag_response ("test_thread" )
3031
- self .register_thread ({"abuse_flaggers" : ["11" ], "user_id" : str (self .user .id ) if is_author else "12" })
3032
- data = {"abuse_flagged" : False }
3033
- update_thread (self .request , "test_thread" , data )
3034
- assert httpretty .last_request ().method == 'PUT'
3035
- query_params = {'user_id' : [str (self .user .id )]}
3036
- if remove_all :
3037
- query_params .update ({'all' : ['True' ]})
3038
- assert parsed_body (httpretty .last_request ()) == query_params
3039
-
3040
- expected_event_name = 'edx.forum.thread.unreported'
3041
- expected_event_data = {
3042
- 'body' : 'Original body' ,
3043
- 'id' : 'test_thread' ,
3044
- 'content_type' : 'Post' ,
3045
- 'commentable_id' : 'original_topic' ,
3046
- 'url' : '' ,
3047
- 'user_course_roles' : [],
3048
- 'user_forums_roles' : [FORUM_ROLE_STUDENT , FORUM_ROLE_ADMINISTRATOR ],
3049
- 'target_username' : self .user .username ,
3050
- 'title_truncated' : False ,
3051
- 'title' : 'Original Title' ,
3052
- 'reported_status_cleared' : False ,
3053
- 'thread_type' : 'discussion' ,
3054
- 'group_id' : None ,
3055
- 'truncated' : False ,
3056
- }
3057
-
3058
- actual_event_name , actual_event_data = mock_emit .call_args [0 ]
3059
- self .assertEqual (actual_event_name , expected_event_name )
3060
- self .assertEqual (actual_event_data , expected_event_data )
3061
-
3062
2936
def test_invalid_field (self ):
3063
2937
self .register_thread ()
3064
2938
with pytest .raises (ValidationError ) as assertion :
@@ -3566,100 +3440,6 @@ def test_vote_count_two_users(
3566
3440
assert result ['vote_count' ] == vote_count
3567
3441
self .register_get_user_response (self .user , upvoted_ids = [])
3568
3442
3569
- @ddt .data (* itertools .product ([True , False ], [True , False ]))
3570
- @ddt .unpack
3571
- @mock .patch ("eventtracking.tracker.emit" )
3572
- def test_abuse_flagged (self , old_flagged , new_flagged , mock_emit ):
3573
- """
3574
- Test attempts to edit the "abuse_flagged" field.
3575
-
3576
- old_flagged indicates whether the comment should be flagged at the start
3577
- of the test. new_flagged indicates the value for the "abuse_flagged"
3578
- field in the update. If old_flagged and new_flagged are the same, no
3579
- update should be made. Otherwise, a PUT should be made to the flag or
3580
- or unflag endpoint according to the new_flagged value.
3581
- """
3582
- self .register_get_user_response (self .user )
3583
- self .register_comment_flag_response ("test_comment" )
3584
- self .register_comment ({"abuse_flaggers" : [str (self .user .id )] if old_flagged else []})
3585
- data = {"abuse_flagged" : new_flagged }
3586
- result = update_comment (self .request , "test_comment" , data )
3587
- assert result ['abuse_flagged' ] == new_flagged
3588
- last_request_path = urlparse (httpretty .last_request ().path ).path # lint-amnesty, pylint: disable=no-member
3589
- flag_url = "/api/v1/comments/test_comment/abuse_flag"
3590
- unflag_url = "/api/v1/comments/test_comment/abuse_unflag"
3591
- if old_flagged == new_flagged :
3592
- assert last_request_path != flag_url
3593
- assert last_request_path != unflag_url
3594
- else :
3595
- assert last_request_path == (flag_url if new_flagged else unflag_url )
3596
- assert httpretty .last_request ().method == 'PUT'
3597
- assert parsed_body (httpretty .last_request ()) == {'user_id' : [str (self .user .id )]}
3598
-
3599
- expected_event_name = 'edx.forum.response.reported' if new_flagged else 'edx.forum.response.unreported'
3600
- expected_event_data = {
3601
- 'body' : 'Original body' ,
3602
- 'id' : 'test_comment' ,
3603
- 'content_type' : 'Response' ,
3604
- 'commentable_id' : 'dummy' ,
3605
- 'url' : '' ,
3606
- 'truncated' : False ,
3607
- 'user_course_roles' : [],
3608
- 'user_forums_roles' : [FORUM_ROLE_STUDENT ],
3609
- 'target_username' : self .user .username ,
3610
- }
3611
- if not new_flagged :
3612
- expected_event_data ['reported_status_cleared' ] = False
3613
-
3614
- actual_event_name , actual_event_data = mock_emit .call_args [0 ]
3615
- self .assertEqual (actual_event_name , expected_event_name )
3616
- self .assertEqual (actual_event_data , expected_event_data )
3617
-
3618
- @ddt .data (
3619
- (False , True ),
3620
- (True , True ),
3621
- )
3622
- @ddt .unpack
3623
- @mock .patch ("eventtracking.tracker.emit" )
3624
- def test_comment_un_abuse_flag_for_moderator_role (self , is_author , remove_all , mock_emit ):
3625
- """
3626
- Test un-abuse flag for moderator role.
3627
-
3628
- When moderator unflags a reported comment, it should
3629
- pass the "all" flag to the api. This will indicate
3630
- to the api to clear all abuse_flaggers, and mark the
3631
- comment as unreported.
3632
- """
3633
- _assign_role_to_user (user = self .user , course_id = self .course .id , role = FORUM_ROLE_ADMINISTRATOR )
3634
- self .register_get_user_response (self .user )
3635
- self .register_comment_flag_response ("test_comment" )
3636
- self .register_comment ({"abuse_flaggers" : ["11" ], "user_id" : str (self .user .id ) if is_author else "12" })
3637
- data = {"abuse_flagged" : False }
3638
- update_comment (self .request , "test_comment" , data )
3639
- assert httpretty .last_request ().method == 'PUT'
3640
- query_params = {'user_id' : [str (self .user .id )]}
3641
- if remove_all :
3642
- query_params .update ({'all' : ['True' ]})
3643
- assert parsed_body (httpretty .last_request ()) == query_params
3644
-
3645
- expected_event_name = 'edx.forum.response.unreported'
3646
- expected_event_data = {
3647
- 'body' : 'Original body' ,
3648
- 'id' : 'test_comment' ,
3649
- 'content_type' : 'Response' ,
3650
- 'commentable_id' : 'dummy' ,
3651
- 'truncated' : False ,
3652
- 'url' : '' ,
3653
- 'user_course_roles' : [],
3654
- 'user_forums_roles' : [FORUM_ROLE_STUDENT , FORUM_ROLE_ADMINISTRATOR ],
3655
- 'target_username' : self .user .username ,
3656
- 'reported_status_cleared' : False ,
3657
- }
3658
-
3659
- actual_event_name , actual_event_data = mock_emit .call_args [0 ]
3660
- self .assertEqual (actual_event_name , expected_event_name )
3661
- self .assertEqual (actual_event_data , expected_event_data )
3662
-
3663
3443
@ddt .data (
3664
3444
FORUM_ROLE_ADMINISTRATOR ,
3665
3445
FORUM_ROLE_MODERATOR ,
0 commit comments