本文整理汇总了Python中tests.factories.CommentFactory.report_abuse方法的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory.report_abuse方法的具体用法?Python CommentFactory.report_abuse怎么用?Python CommentFactory.report_abuse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.CommentFactory
的用法示例。
在下文中一共展示了CommentFactory.report_abuse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSpamDetail
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from 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 = OSFLogEntry.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 = OSFLogEntry.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 tests.factories import CommentFactory [as 别名]
# 或者: from 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: TestEmailFormView
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import report_abuse [as 别名]
class TestEmailFormView(AdminTestCase):
def setUp(self):
super(TestEmailFormView, 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()
self.view = EmailFormView()
self.form = EmailForm(data={
'author': 'Nemo',
'message': 'A message for spammers.',
'subject': 'stop spamming',
'email': ('[email protected]', '[email protected]')
})
self.view = setup_form_view(self.view, self.request, self.form,
spam_id=self.comment._id)
@mock.patch('admin.spam.views.render')
def test_get_context_data(self, mock_render):
res = self.view.get_context_data()
nt.assert_equal(res['status'], '1')
nt.assert_equal(res['page_number'], '1')
nt.assert_is_instance(res['comment'], dict)
def test_get_context_data_bad_id(self):
view = setup_view(EmailFormView(), self.request, spam_id='a1')
with nt.assert_raises(Http404):
view.get_context_data()
@mock.patch('admin.spam.views.render')
def test_get_initial(self, mock_render):
self.view.get_initial()
res = self.view.initial
nt.assert_is_instance(res, dict)
nt.assert_is_instance(res['email'], list)
nt.assert_is_instance(res['email'][0], tuple)
def test_get_initial_bad_id(self):
view = setup_view(EmailFormView(), self.request, spam_id='a1')
with nt.assert_raises(Http404):
view.get_initial()
示例4: TestSpamMixin
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from 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 = datetime.utcnow()
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 = datetime.utcnow()
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 = datetime.utcnow()
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)
#.........这里部分代码省略.........
示例5: TestUserSpamListView
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from 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_2.save()
self.user_1.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')
def test_get_spam(self):
guid = self.user_1._id
request = RequestFactory().get('/fake_path')
view = UserSpamList()
view = setup_view(view, request, user_id=guid)
res = list(view.get_queryset())
nt.assert_equal(len(res), 4)
示例6: TestCommentModel
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import report_abuse [as 别名]
#.........这里部分代码省略.........
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content='This is a comment.'
)
assert_equal(mock_signals.signals_sent(), set([comment_added]))
def test_edit(self):
self.comment.edit(
auth=self.auth,
content='edited',
save=True
)
assert_equal(self.comment.content, 'edited')
assert_true(self.comment.modified)
assert_equal(len(self.comment.node.logs), 2)
assert_equal(self.comment.node.logs[-1].action, NodeLog.COMMENT_UPDATED)
def test_delete(self):
self.comment.delete(auth=self.auth, save=True)
assert_equal(self.comment.is_deleted, True)
assert_equal(len(self.comment.node.logs), 2)
assert_equal(self.comment.node.logs[-1].action, NodeLog.COMMENT_REMOVED)
def test_undelete(self):
self.comment.delete(auth=self.auth, save=True)
self.comment.undelete(auth=self.auth, save=True)
assert_equal(self.comment.is_deleted, False)
assert_equal(len(self.comment.node.logs), 3)
assert_equal(self.comment.node.logs[-1].action, NodeLog.COMMENT_RESTORED)
def test_report_abuse(self):
user = UserFactory()
self.comment.report_abuse(user, category='spam', text='ads', save=True)
assert_in(user._id, self.comment.reports)
assert_equal(
self.comment.reports[user._id],
{'category': 'spam', 'text': 'ads'}
)
def test_report_abuse_own_comment(self):
with assert_raises(ValueError):
self.comment.report_abuse(
self.comment.user, category='spam', text='ads', save=True
)
def test_unreport_abuse(self):
user = UserFactory()
self.comment.report_abuse(user, category='spam', text='ads', save=True)
self.comment.unreport_abuse(user, save=True)
assert_not_in(user._id, self.comment.reports)
def test_unreport_abuse_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.unreport_abuse(non_reporter, save=True)
assert_in(reporter._id, self.comment.reports)
def test_validate_reports_bad_key(self):
self.comment.reports[None] = {'category': 'spam', 'text': 'ads'}
with assert_raises(ValidationValueError):
self.comment.save()
示例7: TestSpamListView
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import report_abuse [as 别名]
class TestSpamListView(AdminTestCase):
def setUp(self):
super(TestSpamListView, 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()
date = datetime.utcnow()
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')
def test_get_spam(self):
guid = self.user_1._id
request = RequestFactory().get('/fake_path')
view = SpamList()
view = setup_view(view, request, user_id=guid)
res = list(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)