def test_is_removed_returns_true_is_was_removed(self, video_comment): moderation_services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing', ) assert video_comment.is_removed is True
def test_returns_false_if_removed_then_reinstated(self, video_comment): services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing') services.reinstate_removed_video_comment( video_comment_id=video_comment.id) assert (services.video_comment_is_removed( video_comment_id=video_comment.id) is False)
def test_raises_if_reason_and_report_specified(self, video_comment, mocker, video_comment_report): mock_task = mocker.patch( f'{MODULE}.tasks.' 'task_notify_channel_owner_video_comment_is_removed') with pytest.raises(IntegrityError): services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing', video_comment_report_id=video_comment_report.id, ) assert not mock_task.delay.called
def test_task_notify_channel_owner_video_comment_is_removed( video_comment, mocker, settings): mock_send_mail = mocker.patch(f'{MODULE}.send_mail') video_comment_removal = services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing', notify=False) tasks.task_notify_channel_owner_video_comment_is_removed( video_comment_removal_id=video_comment_removal.id, ) assert mock_send_mail.called exp_subject = 'Your Veems video comment has been removed' exp_message = (f'Your comment on video "{video_comment.video.title}" ' 'has been removed.\n\n' 'Other users will not be able to view this comment.\n' 'Reason: doxxing\n\n' 'If you think this decision has been made in error, ' 'please reply to this email.\n\n' '- Veems Support Team\n') mock_send_mail.assert_called_once_with( subject=exp_subject, message=exp_message, from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=[video_comment.commenter_channel.user.email], fail_silently=False, )
def existing_comments(self, video, video_comment_factory): num_comment_replies = (0, 1, 2, 3) exp_comments_and_replies = {} for replies_count_to_create in num_comment_replies: comment = video_comment_factory(video_id=video.id) exp_comments_and_replies[comment.id] = [] if replies_count_to_create: for _ in range(replies_count_to_create): reply = video_comment_factory(video_id=video.id, parent_comment_id=comment.id) exp_comments_and_replies[comment.id].append(reply.id) # Mark one as deleted comment.mark_as_deleted() # Mark one as removed moderation_services.mark_video_comment_as_removed( video_comment_id=comment.id, reason='doxxing') return video, exp_comments_and_replies, num_comment_replies
def test_with_reason(self, video_comment, mocker): mock_task = mocker.patch( f'{MODULE}.tasks.' 'task_notify_channel_owner_video_comment_is_removed') removal = services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing') assert isinstance(removal, services.models.VideoCommentRemoval) assert removal.reason == 'doxxing' assert removal.video_comment_report is None assert removal.video_comment == video_comment assert removal.reason_text == 'doxxing' assert mock_task.delay.called
def test_with_report(self, video_comment, video_comment_report, mocker): mock_task = mocker.patch( f'{MODULE}.tasks.' 'task_notify_channel_owner_video_comment_is_removed') removal = services.mark_video_comment_as_removed( video_comment_id=video_comment.id, video_comment_report_id=video_comment_report.id, ) assert isinstance(removal, services.models.VideoCommentRemoval) assert removal.reason is None assert removal.video_comment_report == video_comment_report assert removal.video_comment == video_comment assert removal.reason_text == video_comment_report.reason assert mock_task.delay.called video_comment_report.refresh_from_db() assert video_comment_report.processed_on
def test_returns_true_if_is_removed(self, video_comment): services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing') assert (services.video_comment_is_removed( video_comment_id=video_comment.id) is True)
def make(video_comment=None): video_comment = video_comment or request.getfixturevalue( 'video_comment') return moderation_services.mark_video_comment_as_removed( video_comment_id=video_comment.id, reason='doxxing')