本文整理汇总了Python中tests.factories.CommentFactory.confirm_spam方法的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory.confirm_spam方法的具体用法?Python CommentFactory.confirm_spam怎么用?Python CommentFactory.confirm_spam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.CommentFactory
的用法示例。
在下文中一共展示了CommentFactory.confirm_spam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSpamMixin
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import confirm_spam [as 别名]
#.........这里部分代码省略.........
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)
def test_confirm_ham(self):
self.comment.confirm_ham(save=True)
assert_equal(self.comment.spam_status, SpamStatus.HAM)
def test_confirm_spam(self):
self.comment.confirm_spam(save=True)
assert_equal(self.comment.spam_status, SpamStatus.SPAM)
def test_validate_reports_bad_key(self):
self.comment.reports[None] = {'category': 'spam', 'text': 'ads'}
with assert_raises(ValidationValueError):
self.comment.save()
def test_validate_reports_bad_type(self):
self.comment.reports[self.comment.user._id] = 'not a dict'
with assert_raises(ValidationTypeError):
self.comment.save()
def test_validate_reports_bad_value(self):
self.comment.reports[self.comment.user._id] = {'foo': 'bar'}
with assert_raises(ValidationValueError):
self.comment.save()