Пример #1
0
 def test_preprint_contributor_signal_not_sent_one_contributor(self):
     with capture_signals() as mock_signals:
         private_project_payload = build_preprint_create_payload(self.private_project._id, self.subject._id,
                                                                self.file_one_private_project._id)
         res = self.app.post_json_api(self.url, private_project_payload, auth=self.user.auth)
         assert_equal(res.status_code, 201)
         assert_not_equal(mock_signals.signals_sent(), set([project_signals.contributor_added]))
Пример #2
0
    def test_preprint_contributor_signal_not_sent_on_creation(self):
        with capture_signals() as mock_signals:
            public_project_payload = build_preprint_create_payload(self.public_project._id, self.provider._id,
                                                                   self.file_one_public_project._id)
            res = self.app.post_json_api(self.url, public_project_payload, auth=self.user.auth)

            assert_equal(res.status_code, 201)
            assert_not_in(project_signals.contributor_added, mock_signals.signals_sent())
Пример #3
0
 def test_edit_sends_mention_added_signal_if_mentions(self):
     with capture_signals() as mock_signals:
         self.comment.edit(
             auth=self.auth,
             content="This is a comment with a bad mention [@Mentioned User](http://localhost:5000/"
             + self.comment.user._id
             + "/).",
             save=True,
         )
     assert_equal(mock_signals.signals_sent(), set([mention_added]))
Пример #4
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})
Пример #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})
Пример #6
0
 def test_edit_sends_mention_added_signal_if_mentions(self):
     comment = CommentFactory()
     auth = Auth(comment.user)
     with capture_signals() as mock_signals:
         comment.edit(
             auth=auth,
             content='This is a comment with a bad mention [@Mentioned User](http://localhost:5000/' + comment.user._id + '/).',
             save=True
         )
     assert mock_signals.signals_sent() == ({mention_added})
Пример #7
0
 def test_edit_does_not_send_mention_added_signal_if_nonuser_mentioned(self):
     with assert_raises(ValidationValueError) as error:
         with capture_signals() as mock_signals:
             self.comment.edit(
                 auth=self.auth,
                 content="This is a comment with a bad mention [@Not a User](http://localhost:5000/qwert/).",
                 save=True,
             )
     assert_equal(mock_signals.signals_sent(), set([]))
     assert_equal(error.exception.message, "User does not exist or is not active.")
Пример #8
0
 def test_edit_does_not_send_mention_added_signal_if_already_mentioned(self):
     comment = CommentFactory()
     auth = Auth(comment.user)
     with capture_signals() as mock_signals:
         comment.ever_mentioned.add(comment.user)
         comment.edit(
             auth=auth,
             content='This is a comment with a bad mention [@Already Mentioned User](http://localhost:5000/' + comment.user._id + '/).',
             save=True
         )
     assert mock_signals.signals_sent() == set([])
Пример #9
0
 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]))
Пример #10
0
 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([]))
Пример #11
0
 def test_edit_does_not_send_mention_added_signal_if_nonuser_mentioned(self):
     comment = CommentFactory()
     auth = Auth(comment.user)
     with pytest.raises(ValidationError) as error:
         with capture_signals() as mock_signals:
             comment.edit(
                 auth=auth,
                 content='This is a comment with a bad mention [@Not a User](http://localhost:5000/qwert/).',
                 save=True
             )
     assert mock_signals.signals_sent() == set([])
     assert error.value.message == 'User does not exist or is not active.'
Пример #12
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.'
Пример #13
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.'
    def test_preprint_contributor_signal_sent_on_creation(self):
        # Signal sent but bails out early without sending email
        with capture_signals() as mock_signals:
            payload = build_preprint_create_payload(
                provider_id=self.provider._id)
            res = self.app.post_json_api(
                self.url, payload, auth=self.user.auth)

            assert_equal(res.status_code, 201)
            assert_true(len(mock_signals.signals_sent()) == 1)
            assert_in(
                project_signals.contributor_added,
                mock_signals.signals_sent())
Пример #15
0
 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]))
Пример #16
0
 def test_removed_contrib_files_checked_in(self, app, node, file):
     write_contrib = AuthUserFactory()
     node.add_contributor(write_contrib, permissions=['read', 'write'])
     node.save()
     assert node.can_edit(user=write_contrib)
     file.checkout = write_contrib
     file.save()
     assert file.is_checked_out
     with capture_signals() as mock_signals:
         node.remove_contributor(write_contrib, auth=Auth(write_contrib))
     assert mock_signals.signals_sent() == set([contributor_removed])
     file.reload()
     assert not file.is_checked_out
Пример #17
0
 def test_edit_does_not_send_mention_added_signal_if_noncontributor_mentioned(self):
     comment = CommentFactory()
     auth = Auth(comment.user)
     with pytest.raises(ValidationError) as error:
         with capture_signals() as mock_signals:
             user = UserFactory()
             comment.edit(
                 auth=auth,
                 content='This is a comment with a bad mention [@Non-contributor User](http://localhost:5000/' + user._id + '/).',
                 save=True
             )
     assert mock_signals.signals_sent() == set([])
     assert error.value.message == 'Mentioned user is not a contributor.'
Пример #18
0
 def test_removed_contrib_files_checked_in(self):
     user = AuthUserFactory()
     self.node.add_contributor(user, permissions=['read', 'write'])
     self.node.save()
     assert_true(self.node.can_edit(user=user))
     self.file.checkout = user
     self.file.save()
     assert_true(self.file.is_checked_out)
     with capture_signals() as mock_signals:
         self.node.remove_contributor(user, auth=Auth(user))
     assert_equal(mock_signals.signals_sent(), set([contributor_removed]))
     self.file.reload()
     assert_false(self.file.is_checked_out)
Пример #19
0
 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.")
Пример #20
0
 def test_edit_does_not_send_mention_added_signal_if_noncontributor_mentioned(self):
     with assert_raises(ValidationValueError) as error:
         with capture_signals() as mock_signals:
             user = UserFactory()
             self.comment.edit(
                 auth=self.auth,
                 content="This is a comment with a bad mention [@Non-contributor User](http://localhost:5000/"
                 + user._id
                 + "/).",
                 save=True,
             )
     assert_equal(mock_signals.signals_sent(), set([]))
     assert_equal(error.exception.message, "Mentioned user is not a contributor.")
Пример #21
0
    def test_adds_institution(self):
        username = '******'

        user = User(username=username, fullname='Mr Moco')
        user.save()

        with capture_signals() as mock_signals:
            res = self.app.post(self.url, self.build_payload(username))

        assert_equal(res.status_code, 204)
        assert_equal(mock_signals.signals_sent(), set())

        user.reload()
        assert_in(self.institution, user.affiliated_institutions)
Пример #22
0
    def test_creates_user(self):
        username = '******'
        assert_equal(User.find(Q('username', 'eq', username)).count(), 0)

        with capture_signals() as mock_signals:
            res = self.app.post(self.url, self.build_payload(username))

        assert_equal(res.status_code, 204)
        assert_equal(mock_signals.signals_sent(), set([signals.user_confirmed]))

        user = User.find_one(Q('username', 'eq', username))

        assert_true(user)
        assert_in(self.institution, user.affiliated_institutions)
Пример #23
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.'
Пример #24
0
 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.")
Пример #25
0
    def test_edit_does_not_send_mention_added_signal_if_unconfirmed_contributor_mentioned(self):
        comment = CommentFactory()
        auth = Auth(comment.user)
        with pytest.raises(ValidationError) as error:
            with capture_signals() as mock_signals:
                user = UnregUserFactory()
                user.save()
                comment.node.add_unregistered_contributor(user.fullname, user.email, auth=Auth(comment.node.creator), visible=False, permissions=[permissions.READ])
                comment.node.save()

                comment.edit(
                    auth=auth,
                    content='This is a comment with a bad mention [@Unconfirmed User](http://localhost:5000/' + user._id + '/).',
                    save=True
                )
        assert mock_signals.signals_sent() == ({contributor_added})
        assert error.value.message == 'User does not exist or is not active.'
    def test_adds_institution(self, app, institution, url_auth_institution):
        username = '******'

        user = make_user(username, 'Mr Moco')
        user.save()

        with capture_signals() as mock_signals:
            res = app.post(
                url_auth_institution,
                make_payload(institution, username)
            )

        assert res.status_code == 204
        assert mock_signals.signals_sent() == set()

        user.reload()
        assert institution in user.affiliated_institutions.all()
    def test_creates_user(self, app, url_auth_institution, institution):
        username = '******'
        assert OSFUser.objects.filter(username=username).count() == 0

        with capture_signals() as mock_signals:
            res = app.post(
                url_auth_institution,
                make_payload(institution, username)
            )

        assert res.status_code == 204
        assert mock_signals.signals_sent() == set([signals.user_confirmed])

        user = OSFUser.objects.filter(username=username).first()

        assert user
        assert institution in user.affiliated_institutions.all()
Пример #28
0
    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.")
Пример #29
0
        def test_node_subscriptions_and_backrefs_removed_when_node_is_deleted(self):
            project = factories.ProjectFactory()
            subscription = factories.NotificationSubscriptionFactory(
                _id=project._id + '_comments',
                owner=project
            )
            subscription.save()
            subscription.email_transactional.append(project.creator)
            subscription.save()

            s = getattr(project.creator, 'email_transactional', [])
            assert_equal(len(s), 1)

            with capture_signals() as mock_signals:
                project.remove_node(auth=Auth(project.creator))
            assert_true(project.is_deleted)
            assert_equal(mock_signals.signals_sent(), set([node_deleted]))

            s = getattr(project.creator, 'email_transactional', [])
            assert_equal(len(s), 0)

            with assert_raises(NoResultsFound):
                NotificationSubscription.find_one(Q('owner', 'eq', project))
Пример #30
0
 def test_remove_contributor_signal_called_when_contributor_is_removed(self):
     with capture_signals() as mock_signals:
         self.project.remove_contributor(self.contributor, auth=Auth(self.project.creator))
     assert_equal(mock_signals.signals_sent(), set([contributor_removed]))