Esempio n. 1
0
 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 + '/)'
     )
Esempio n. 2
0
 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 + '/)'
     )
Esempio n. 3
0
 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)])
         )
Esempio n. 4
0
 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)])
         )
Esempio n. 5
0
 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})
Esempio n. 6
0
 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})
Esempio n. 7
0
 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.'
Esempio n. 8
0
 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.'
Esempio n. 9
0
 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})
Esempio n. 10
0
 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})
Esempio n. 11
0
 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.'
Esempio n. 12
0
 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.'
Esempio n. 13
0
 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.'
Esempio n. 14
0
 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.'
Esempio n. 15
0
 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.'
Esempio n. 16
0
 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.'
Esempio n. 17
0
 def test_create_sends_mention_added_signal_if_group_member_mentions(self, node, user, auth):
     manager = AuthUserFactory()
     group = OSFGroupFactory(creator=manager)
     node.add_osf_group(group)
     assert node.is_contributor_or_group_member(manager) is True
     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 group member mention [@Group Member](http://localhost:5000/' + manager._id + '/).'
         )
     assert mock_signals.signals_sent() == ({comment_added, mention_added})
Esempio n. 18
0
    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.'
Esempio n. 19
0
    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 = UserFactory()
                user.is_registered = False
                user.is_claimed = False
                user.save()
                node.add_contributor(user, visible=False, 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.'
Esempio n. 20
0
    def test_create_comment(self, request, user, project, comment_content, expected_signals, expected_error_msg):
        if hasattr(comment_content, '_pytestfixturefunction'):
            comment_content = request.getfixturevalue(comment_content.__name__)

        auth = Auth(user)
        error_msg = None
        with capture_signals() as mock_signals:
            try:
                Comment.create(
                    auth=auth,
                    user=user,
                    node=project,
                    target=project.guids.all()[0],
                    content=comment_content
                )
            except Exception as e:
                error_msg = str(e)

        assert expected_signals == mock_signals.signals_sent()
        assert error_msg == expected_error_msg
Esempio n. 21
0
    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()
Esempio n. 22
0
    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()
Esempio n. 23
0
    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
Esempio n. 24
0
    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