本文整理汇总了Python中tests.factories.CommentFactory.delete方法的典型用法代码示例。如果您正苦于以下问题:Python CommentFactory.delete方法的具体用法?Python CommentFactory.delete怎么用?Python CommentFactory.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.CommentFactory
的用法示例。
在下文中一共展示了CommentFactory.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCommentModel
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import delete [as 别名]
class TestCommentModel(OsfTestCase):
def setUp(self):
super(TestCommentModel, self).setUp()
self.comment = CommentFactory()
self.auth = Auth(user=self.comment.user)
def test_create(self):
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
page='node',
is_public=True,
content='This is a comment.'
)
assert_equal(comment.user, self.comment.user)
assert_equal(comment.node, self.comment.node)
assert_equal(comment.target, self.comment.target)
assert_equal(len(comment.node.logs), 2)
assert_equal(comment.node.logs[-1].action, NodeLog.COMMENT_ADDED)
def test_create_comment_content_cannot_exceed_max_length(self):
with assert_raises(ValidationValueError):
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=''.join(['c' for c in range(settings.COMMENT_MAXLENGTH + 1)])
)
def test_create_comment_content_cannot_be_none(self):
with assert_raises(ValidationError) as error:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=None
)
assert_equal(error.exception.message, 'Value <content> is required.')
def test_create_comment_content_cannot_be_empty(self):
with assert_raises(ValidationValueError) as error:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=''
)
assert_equal(error.exception.message, 'Value must not be empty.')
def test_create_comment_content_cannot_be_whitespace(self):
with assert_raises(ValidationValueError) as error:
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
is_public=True,
content=' '
)
assert_equal(error.exception.message, 'Value must not be empty.')
def test_create_sends_comment_added_signal(self):
with capture_signals() as mock_signals:
comment = Comment.create(
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):
#.........这里部分代码省略.........
示例2: TestCommentModel
# 需要导入模块: from tests.factories import CommentFactory [as 别名]
# 或者: from tests.factories.CommentFactory import delete [as 别名]
#.........这里部分代码省略.........
def test_edit_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned(self):
with assert_raises(ValidationValueError) as error:
with capture_signals() as mock_signals:
user = UserFactory()
user.is_registered = False
user.is_claimed = False
user.save()
self.comment.node.add_contributor(user, visible=False, permissions=[permissions.READ])
self.comment.node.save()
self.comment.edit(
auth=self.auth,
content="This is a comment with a bad mention [@Unconfirmed User](http://localhost:5000/"
+ user._id
+ "/).",
save=True,
)
assert_equal(mock_signals.signals_sent(), set([contributor_added]))
assert_equal(error.exception.message, "User does not exist or is not active.")
def test_edit_does_not_send_mention_added_signal_if_already_mentioned(self):
with capture_signals() as mock_signals:
self.comment.ever_mentioned = [self.comment.user._id]
self.comment.edit(
auth=self.auth,
content="This is a comment with a bad mention [@Already Mentioned User](http://localhost:5000/"
+ self.comment.user._id
+ "/).",
save=True,
)
assert_equal(mock_signals.signals_sent(), set([]))
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_read_permission_contributor_can_comment(self):
project = ProjectFactory()
user = UserFactory()
project.set_privacy("private")
project.add_contributor(user, permissions=[permissions.READ])
project.save()
assert_true(project.can_comment(Auth(user=user)))
def test_get_content_for_not_deleted_comment(self):
project = ProjectFactory(is_public=True)
comment = CommentFactory(node=project)
content = comment.get_content(auth=Auth(comment.user))
assert_equal(content, comment.content)
def test_get_content_returns_deleted_content_to_commenter(self):
comment = CommentFactory(is_deleted=True)
content = comment.get_content(auth=Auth(comment.user))
assert_equal(content, comment.content)