本文整理汇总了Python中website.project.model.Comment.create方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.create方法的具体用法?Python Comment.create怎么用?Python Comment.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.project.model.Comment
的用法示例。
在下文中一共展示了Comment.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_comment_content_cannot_exceed_max_length
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
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)])
)
示例2: create
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def create(self, validated_data):
user = validated_data['user']
auth = Auth(user)
node = validated_data['node']
validated_data['content'] = validated_data.pop('get_content')
if node and node.can_comment(auth):
comment = Comment.create(auth=auth, **validated_data)
else:
raise PermissionDenied("Not authorized to comment on this project.")
return comment
示例3: test_create_sends_comment_added_signal
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
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]))
示例4: test_create_comment_content_cannot_be_whitespace
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
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.')
示例5: test_create_comment_content_cannot_be_none
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
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.')
示例6: test_create_comment_content_does_not_exceed_max_length_complex
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def test_create_comment_content_does_not_exceed_max_length_complex(self):
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 - 12)])
+ "[@George Ant](http://localhost:5000/"
+ self.comment.user._id
+ "/)",
)
示例7: test_create_does_not_send_mention_added_signal_if_nonuser_mentioned
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def test_create_does_not_send_mention_added_signal_if_nonuser_mentioned(self):
with assert_raises(ValidationValueError) as error:
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 with a bad mention [@Not a User](http://localhost:5000/qwert/).",
)
assert_equal(mock_signals.signals_sent(), set([]))
assert_equal(error.exception.message, "User does not exist or is not active.")
示例8: test_create_sends_mention_added_signal_if_mentions
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def test_create_sends_mention_added_signal_if_mentions(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 with a bad mention [@Unconfirmed User](http://localhost:5000/"
+ self.comment.user._id
+ "/).",
)
assert_equal(mock_signals.signals_sent(), set([comment_added, mention_added]))
示例9: test_create
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
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)
示例10: test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned(self):
with assert_raises(ValidationValueError) as error:
with capture_signals() as mock_signals:
user = UserFactory()
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 with a bad mention [@Non-contributor User](http://localhost:5000/"
+ user._id
+ "/).",
)
assert_equal(mock_signals.signals_sent(), set([]))
assert_equal(error.exception.message, "Mentioned user is not a contributor.")
示例11: test_create
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def test_create(self):
comment = Comment.create(
auth=self.auth,
user=self.comment.user,
node=self.comment.node,
target=self.comment.target,
root_target=self.comment.root_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)
assert_equal([], self.comment.ever_mentioned)
示例12: create
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def create(self, validated_data):
user = validated_data['user']
auth = Auth(user)
node = validated_data['node']
target_id = self.context['request'].data.get('id')
try:
target = self.get_target(node._id, target_id)
except ValueError:
raise InvalidModelValueError(
source={'pointer': '/data/relationships/target/data/id'},
detail='Invalid comment target \'{}\'.'.format(target_id)
)
validated_data['target'] = target
validated_data['content'] = validated_data.pop('get_content')
try:
comment = Comment.create(auth=auth, **validated_data)
except PermissionsError:
raise PermissionDenied('Not authorized to comment on this project.')
return comment
示例13: create
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def create(self, validated_data):
user = validated_data["user"]
auth = Auth(user)
node = validated_data["node"]
target_id = self.context["request"].data.get("id")
try:
target = self.get_target(node._id, target_id)
except ValueError:
raise InvalidModelValueError(
source={"pointer": "/data/relationships/target/data/id"},
detail="Invalid comment target '{}'.".format(target_id),
)
validated_data["target"] = target
validated_data["content"] = validated_data.pop("get_content")
try:
comment = Comment.create(auth=auth, **validated_data)
except PermissionsError:
raise PermissionDenied("Not authorized to comment on this project.")
return comment
示例14: test_create_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned
# 需要导入模块: from website.project.model import Comment [as 别名]
# 或者: from website.project.model.Comment import create [as 别名]
def test_create_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()
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 with a bad mention [@Unconfirmed User](http://localhost:5000/"
+ user._id
+ "/).",
)
assert_equal(mock_signals.signals_sent(), set([contributor_added]))
assert_equal(error.exception.message, "User does not exist or is not active.")