本文整理汇总了Python中osf_tests.factories.CommentFactory.report_abuse方法的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory.report_abuse方法的具体用法?Python CommentFactory.report_abuse怎么用?Python CommentFactory.report_abuse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf_tests.factories.CommentFactory
的用法示例。
在下文中一共展示了CommentFactory.report_abuse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSpamDetail
# 需要导入模块: from osf_tests.factories import CommentFactory [as 别名]
# 或者: from osf_tests.factories.CommentFactory import report_abuse [as 别名]
class TestSpamDetail(AdminTestCase):
def setUp(self):
super(TestSpamDetail, self).setUp()
self.comment = CommentFactory()
self.comment.report_abuse(user=AuthUserFactory(), save=True,
category='spam')
self.request = RequestFactory().post('/fake_path')
self.request.user = UserFactory()
def test_confirm_spam(self):
form_data = {'confirm': str(SpamStatus.SPAM)}
form = ConfirmForm(data=form_data)
nt.assert_true(form.is_valid())
view = SpamDetail()
view = setup_form_view(
view, self.request, form, spam_id=self.comment._id)
with transaction.atomic():
view.form_valid(form)
obj = AdminLogEntry.objects.latest(field_name='action_time')
nt.assert_equal(obj.object_id, self.comment._id)
nt.assert_in('Confirmed SPAM:', obj.message())
def test_confirm_ham(self):
form_data = {'confirm': str(SpamStatus.HAM)}
form = ConfirmForm(data=form_data)
nt.assert_true(form.is_valid())
view = SpamDetail()
view = setup_form_view(
view, self.request, form, spam_id=self.comment._id)
with transaction.atomic():
view.form_valid(form)
obj = AdminLogEntry.objects.latest(field_name='action_time')
nt.assert_equal(obj.object_id, self.comment._id)
nt.assert_in('Confirmed HAM:', obj.message())
def test_form_valid_bad_id(self):
form = ConfirmForm()
view = SpamDetail()
view = setup_form_view(view, self.request, form, spam_id='a1')
with nt.assert_raises(Http404):
view.form_valid(form)
def test_get_context_data(self):
view = SpamDetail()
view = setup_view(view, self.request, spam_id=self.comment._id)
res = view.get_context_data()
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], '1')
nt.assert_is_instance(res['comment'], dict)
nt.assert_equal(res['SPAM_STATUS'].UNKNOWN, SpamStatus.UNKNOWN)
nt.assert_equal(res['SPAM_STATUS'].SPAM, SpamStatus.SPAM)
nt.assert_equal(res['SPAM_STATUS'].HAM, SpamStatus.HAM)
nt.assert_equal(res['SPAM_STATUS'].FLAGGED, SpamStatus.FLAGGED)
def test_get_context_data_bad_id(self):
view = setup_view(SpamDetail(), self.request, spam_id='a1')
with nt.assert_raises(Http404):
view.get_context_data()
示例2: TestEmailView
# 需要导入模块: from osf_tests.factories import CommentFactory [as 别名]
# 或者: from osf_tests.factories.CommentFactory import report_abuse [as 别名]
class TestEmailView(AdminTestCase):
def setUp(self):
super(TestEmailView, self).setUp()
self.comment = CommentFactory()
self.comment.report_abuse(user=AuthUserFactory(), save=True,
category='spam')
self.request = RequestFactory().post('/fake_path')
self.request.user = UserFactory()
def test_get_object_bad_id(self):
view = setup_view(EmailView(), self.request, spam_id='a1')
with nt.assert_raises(Http404):
view.get_object()
示例3: TestSpamListView
# 需要导入模块: from osf_tests.factories import CommentFactory [as 别名]
# 或者: from osf_tests.factories.CommentFactory import report_abuse [as 别名]
class TestSpamListView(AdminTestCase):
def setUp(self):
super(TestSpamListView, self).setUp()
Comment.objects.all().delete()
self.project = ProjectFactory(is_public=True)
self.user_1 = AuthUserFactory()
self.user_2 = AuthUserFactory()
self.project.add_contributor(self.user_1)
self.project.add_contributor(self.user_2)
self.project.save()
self.user_1.save()
self.user_2.save()
date = timezone.now()
self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
self.comment_1.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=5)
)
self.comment_2.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=4)
)
self.comment_3.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=3)
)
self.comment_4.report_abuse(
user=self.user_2,
save=True,
category='spam',
date=date - timedelta(seconds=2)
)
self.comment_5.report_abuse(
user=self.user_1,
save=True,
category='spam',
date=date - timedelta(seconds=1)
)
self.comment_6.report_abuse(user=self.user_1, save=True,
category='spam')
self.request = RequestFactory().get('/fake_path')
self.view = SpamList()
self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
def test_get_spam(self):
res = list(self.view.get_queryset())
nt.assert_equal(len(res), 6)
response_list = [r._id for r in res]
should_be = [
self.comment_6._id,
self.comment_5._id,
self.comment_4._id,
self.comment_3._id,
self.comment_2._id,
self.comment_1._id
]
nt.assert_list_equal(should_be, response_list)
def test_get_context_data(self):
self.view.object_list = self.view.get_queryset()
res = self.view.get_context_data()
nt.assert_is_instance(res['spam'], list)
nt.assert_is_instance(res['spam'][0], dict)
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], 1)
示例4: TestUserSpamListView
# 需要导入模块: from osf_tests.factories import CommentFactory [as 别名]
# 或者: from osf_tests.factories.CommentFactory import report_abuse [as 别名]
class TestUserSpamListView(AdminTestCase):
def setUp(self):
super(TestUserSpamListView, self).setUp()
self.project = ProjectFactory(is_public=True)
self.user_1 = AuthUserFactory()
self.user_2 = AuthUserFactory()
self.project.add_contributor(self.user_1)
self.project.add_contributor(self.user_2)
self.project.save()
self.user_1.save()
self.user_2.save()
self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
self.comment_1.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_2.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_3.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_4.report_abuse(user=self.user_2, save=True,
category='spam')
self.comment_5.report_abuse(user=self.user_1, save=True,
category='spam')
self.comment_6.report_abuse(user=self.user_1, save=True,
category='spam')
self.request = RequestFactory().get('/fake_path')
self.view = UserSpamList()
self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
def test_get_user_spam(self):
res = list(self.view.get_queryset())
nt.assert_equal(len(res), 4)
def test_get_context_data(self):
self.view.object_list = self.view.get_queryset()
res = self.view.get_context_data()
nt.assert_is_instance(res['spam'], list)
nt.assert_is_instance(res['spam'][0], dict)
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], 1)
nt.assert_equal(res['user_id'], self.user_1._id)
示例5: TestSpamMixin
# 需要导入模块: from osf_tests.factories import CommentFactory [as 别名]
# 或者: from osf_tests.factories.CommentFactory import report_abuse [as 别名]
class TestSpamMixin(OsfTestCase):
def setUp(self):
super(TestSpamMixin, self).setUp()
self.comment = CommentFactory()
self.auth = Auth(user=self.comment.user)
def test_report_abuse(self):
user = UserFactory()
time = timezone.now()
self.comment.report_abuse(
user, date=time, category='spam', text='ads', save=True)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
equivalent = dict(
date=time,
category='spam',
text='ads',
retracted=False
)
assert_in(user._id, self.comment.reports)
assert_equal(self.comment.reports[user._id], equivalent)
def test_report_abuse_own_comment(self):
with assert_raises(ValueError):
self.comment.report_abuse(
self.comment.user,
category='spam', text='ads',
save=True
)
assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
def test_retract_report(self):
user = UserFactory()
time = timezone.now()
self.comment.report_abuse(
user, date=time, category='spam', text='ads', save=True
)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
self.comment.retract_report(user, save=True)
assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
equivalent = {
'date': time,
'category': 'spam',
'text': 'ads',
'retracted': True
}
assert_in(user._id, self.comment.reports)
assert_equal(self.comment.reports[user._id], equivalent)
def test_retract_report_not_reporter(self):
reporter = UserFactory()
non_reporter = UserFactory()
self.comment.report_abuse(
reporter, category='spam', text='ads', save=True
)
with assert_raises(ValueError):
self.comment.retract_report(non_reporter, save=True)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_retract_one_report_of_many(self):
user_1 = UserFactory()
user_2 = UserFactory()
time = timezone.now()
self.comment.report_abuse(
user_1, date=time, category='spam', text='ads', save=True
)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
self.comment.report_abuse(
user_2, date=time, category='spam', text='all', save=True
)
self.comment.retract_report(user_1, save=True)
equivalent = {
'date': time,
'category': 'spam',
'text': 'ads',
'retracted': True
}
assert_in(user_1._id, self.comment.reports)
assert_equal(self.comment.reports[user_1._id], equivalent)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_flag_spam(self):
self.comment.flag_spam()
self.comment.save()
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_cannot_remove_flag_not_retracted(self):
user = UserFactory()
self.comment.report_abuse(
user, category='spam', text='ads', save=True
)
self.comment.remove_flag(save=True)
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
def test_remove_flag(self):
self.comment.flag_spam()
self.comment.save()
assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
self.comment.remove_flag(save=True)
assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
#.........这里部分代码省略.........