当前位置: 首页>>代码示例>>Python>>正文


Python Comment.create方法代码示例

本文整理汇总了Python中osf.models.Comment.create方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.create方法的具体用法?Python Comment.create怎么用?Python Comment.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osf.models.Comment的用法示例。


在下文中一共展示了Comment.create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_comment_content_does_not_exceed_max_length_complex

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_comment_content_does_not_exceed_max_length_complex(self, node, user, auth):
     Comment.create(
         auth=auth,
         user=user,
         node=node,
         target=node.guids.all()[0],
         content=''.join(['c' for c in range(settings.COMMENT_MAXLENGTH - 12)]) + '[@George Ant](http://localhost:5000/' + user._id + '/)'
     )
开发者ID:erinspace,项目名称:osf.io,代码行数:10,代码来源:test_comment.py

示例2: test_create_comment_content_cannot_exceed_max_length_simple

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_comment_content_cannot_exceed_max_length_simple(self, node, user, auth):
     with pytest.raises(ValidationError):
         Comment.create(
             auth=auth,
             user=user,
             node=node,
             target=node.guids.all()[0],
             content=''.join(['c' for c in range(settings.COMMENT_MAXLENGTH + 3)])
         )
开发者ID:erinspace,项目名称:osf.io,代码行数:11,代码来源:test_comment.py

示例3: test_create_sends_mention_added_signal_if_mentions

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_sends_mention_added_signal_if_mentions(self, node, user, auth):
     with capture_signals() as mock_signals:
         Comment.create(
             auth=auth,
             user=user,
             node=node,
             target=node.guids.all()[0],
             content='This is a comment with a bad mention [@Unconfirmed User](http://localhost:5000/' + user._id + '/).'
         )
     assert mock_signals.signals_sent() == ({comment_added, mention_added})
开发者ID:erinspace,项目名称:osf.io,代码行数:12,代码来源:test_comment.py

示例4: test_create_sends_comment_added_signal

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_sends_comment_added_signal(self, node, user, auth):
     with capture_signals() as mock_signals:
         Comment.create(
             auth=auth,
             user=user,
             node=node,
             target=node.guids.all()[0],
             content='This is a comment.'
         )
     assert mock_signals.signals_sent() == ({comment_added})
开发者ID:erinspace,项目名称:osf.io,代码行数:12,代码来源:test_comment.py

示例5: test_create_comment_content_cannot_be_whitespace

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_comment_content_cannot_be_whitespace(self, node, user, auth):
     with pytest.raises(ValidationError) as error:
         Comment.create(
             auth=auth,
             user=user,
             node=node,
             target=node.guids.all()[0],
             content='    '
         )
     assert error.value.messages[0] == 'Value must not be empty.'
开发者ID:erinspace,项目名称:osf.io,代码行数:12,代码来源:test_comment.py

示例6: test_create_comment_content_cannot_be_empty

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_comment_content_cannot_be_empty(self, node, user, auth):
     with pytest.raises(ValidationError) as error:
         Comment.create(
             auth=auth,
             user=user,
             node=node,
             target=node.guids.all()[0],
             content=''
         )
     assert error.value.messages[0] == 'This field cannot be blank.'
开发者ID:erinspace,项目名称:osf.io,代码行数:12,代码来源:test_comment.py

示例7: test_create_does_not_send_mention_added_signal_if_nonuser_mentioned

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_does_not_send_mention_added_signal_if_nonuser_mentioned(self, node, user, auth):
     with pytest.raises(ValidationError) as error:
         with capture_signals() as mock_signals:
             Comment.create(
                 auth=auth,
                 user=user,
                 node=node,
                 target=node.guids.all()[0],
                 content='This is a comment with a bad mention [@Not a User](http://localhost:5000/qwert/).'
             )
     assert mock_signals.signals_sent() == set([])
     assert error.value.message == 'User does not exist or is not active.'
开发者ID:erinspace,项目名称:osf.io,代码行数:14,代码来源:test_comment.py

示例8: test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
 def test_create_does_not_send_mention_added_signal_if_noncontributor_mentioned(self, node, user, auth):
     with pytest.raises(ValidationError) as error:
         with capture_signals() as mock_signals:
             user = UserFactory()
             Comment.create(
                 auth=auth,
                 user=user,
                 node=node,
                 target=node.guids.all()[0],
                 content='This is a comment with a bad mention [@Non-contributor User](http://localhost:5000/' + user._id + '/).'
             )
     assert mock_signals.signals_sent() == set([])
     assert error.value.message == 'Mentioned user is not a contributor.'
开发者ID:erinspace,项目名称:osf.io,代码行数:15,代码来源:test_comment.py

示例9: test_create_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
    def test_create_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned(self, node, user, auth):
        with pytest.raises(ValidationError) as error:
            with capture_signals() as mock_signals:
                user = UnregUserFactory()
                user.save()
                node.add_unregistered_contributor(user.fullname, user.email, Auth(node.creator), permissions=[permissions.READ], save=True)

                Comment.create(
                    auth=auth,
                    user=user,
                    node=node,
                    target=node.guids.all()[0],
                    content='This is a comment with a bad mention [@Unconfirmed User](http://localhost:5000/' + user._id + '/).'
                )
        assert mock_signals.signals_sent() == ({contributor_added})
        assert error.value.message == 'User does not exist or is not active.'
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:18,代码来源:test_comment.py

示例10: test_create

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import create [as 别名]
    def test_create(self):
        first_comment = CommentFactory()
        auth = Auth(user=first_comment.user)

        comment = Comment.create(
            auth=auth,
            user=first_comment.user,
            node=first_comment.node,
            target=first_comment.target,
            root_target=first_comment.root_target,
            page='node',
            content='This is a comment, and ya cant teach that.'
        )
        assert comment.user == first_comment.user
        assert comment.node == first_comment.node
        assert comment.target == first_comment.target
        assert comment.node.logs.count() == 2
        assert comment.node.logs.latest().action == NodeLog.COMMENT_ADDED
        assert not first_comment.ever_mentioned.exists()
开发者ID:erinspace,项目名称:osf.io,代码行数:21,代码来源:test_comment.py

示例11: create

# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.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.')
        except ModelValidationError as err:
            raise ValidationError(err.messages[0])
        return comment
开发者ID:erinspace,项目名称:osf.io,代码行数:24,代码来源:serializers.py


注:本文中的osf.models.Comment.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。