Example #1
0
 def node_in_conference(self, user):
     node = ProjectFactory(creator=user, is_public=True)
     con = ConferenceFactory()
     con.auto_check_spam = False
     con.submissions.add(node)
     con.save()
     return node
 def test_route_valid_alternate(self):
     conf = ConferenceFactory(endpoint='chocolate', active=True)
     conf.name = 'Chocolate Conference'
     conf.field_names['submission2'] = 'data'
     conf.save()
     recipient = '{0}[email protected]'.format('test-' if settings.DEV_MODE else '')
     with self.make_context(data={'recipient': recipient}):
         self.app.app.preprocess_request()
         msg = message.ConferenceMessage()
         assert_equal(msg.conference_name, 'chocolate')
         assert_equal(msg.conference_category, 'data')
     conf.__class__.delete(conf)
Example #3
0
 def test_route_valid_alternate(self):
     conf = ConferenceFactory(endpoint='chocolate', active=True)
     conf.name = 'Chocolate Conference'
     conf.field_names['submission2'] = 'data'
     conf.save()
     recipient = '{0}[email protected]'.format('test-' if settings.DEV_MODE else '')
     with self.make_context(data={'recipient': recipient}):
         self.app.app.preprocess_request()
         msg = message.ConferenceMessage()
         assert_equal(msg.conference_name, 'chocolate')
         assert_equal(msg.conference_category, 'data')
     conf.__class__.remove_one(conf)
    def test_conference_valid_submissions(self):
        conf = ConferenceFactory(endpoint='Hamburgers', name='Hamburger conference')
        conf.save()

        # 3 good nodes added
        create_fake_conference_nodes(3, conf)

        # Deleted node added
        deleted_node = ProjectFactory(is_public=True)
        deleted_node.is_deleted = True
        deleted_node.save()
        conf.submissions.add(deleted_node)

        # Private node added
        private_node = ProjectFactory(is_public=False)
        conf.submissions.add(private_node)

        assert_equal(conf.submissions.count(), 5)
        assert_equal(conf.valid_submissions.count(), 3)
 def test_default_field_names(self):
     conf = ConferenceFactory(endpoint='cookie', name='Cookies Conference')
     conf.save()
     assert_equal(conf.field_names['submission1'], 'poster')
     assert_equal(conf.field_names['mail_subject'], 'Presentation title')
class TestProvisionNode(ContextTestCase):

    def setUp(self):
        super(TestProvisionNode, self).setUp()
        self.node = ProjectFactory()
        self.user = self.node.creator
        self.conference = ConferenceFactory()
        self.body = 'dragon on my back'
        self.content = 'dragon attack'
        self.attachment = StringIO(self.content)
        self.recipient = '{0}{1}[email protected]'.format(
            'test-' if settings.DEV_MODE else '',
            self.conference.endpoint,
        )

    def make_context(self, **kwargs):
        data = {
            'attachment-count': '1',
            'attachment-1': (self.attachment, 'attachment-1'),
            'X-Mailgun-Sscore': 0,
            'recipient': self.recipient,
            'stripped-text': self.body,
        }
        data.update(kwargs.pop('data', {}))
        return super(TestProvisionNode, self).make_context(data=data, **kwargs)

    def test_provision(self):
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_true(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in(self.conference.endpoint, self.node.system_tags)
        assert_true(self.node.tags.filter(name=self.conference.endpoint).exists())
        assert_not_in('spam', self.node.system_tags)

    def test_provision_private(self):
        self.conference.public_projects = False
        self.conference.save()
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_not_in('spam', self.node.system_tags)

    def test_provision_spam(self):
        with self.make_context(data={'X-Mailgun-Sscore': message.SSCORE_MAX_VALUE + 1}):
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in('spam', self.node.system_tags)

    @mock.patch('website.conferences.utils.waterbutler_api_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        file_name = 'hammer-to-fall'
        self.attachment.filename = file_name
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            self.node._id,
            'osfstorage',
            _internal=True,
            base_url=self.node.osfstorage_region.waterbutler_url,
            cookie=self.user.get_or_create_cookie(),
            name=file_name
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )

    @mock.patch('website.conferences.utils.waterbutler_api_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload_no_file_name(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        self.attachment.filename = ''
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            self.node._id,
            'osfstorage',
            _internal=True,
            base_url=self.node.osfstorage_region.waterbutler_url,
            cookie=self.user.get_or_create_cookie(),
            name=settings.MISSING_FILE_NAME,
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )

    @mock.patch('website.conferences.utils.upload_attachments')
    def test_add_poster_by_email(self, mock_upload_attachments):
        conference = ConferenceFactory()

        with self.make_context(data={'from': '*****@*****.**', 'subject': 'It\'s PARTY TIME!'}):
            msg = message.ConferenceMessage()
            views.add_poster_by_email(conference, msg)

        user = OSFUser.objects.get(username='******')
        assert user.email == '*****@*****.**'
        assert user.fullname == user._id  # user's shouldn't be able to use email as fullname, so we use the guid.
Example #7
0
 def test_default_field_names(self):
     conf = ConferenceFactory(endpoint='cookie', name='Cookies Conference')
     conf.save()
     assert_equal(conf.field_names['submission1'], 'poster')
     assert_equal(conf.field_names['mail_subject'], 'Presentation title')
Example #8
0
class TestProvisionNode(ContextTestCase):
    def setUp(self):
        super(TestProvisionNode, self).setUp()
        self.node = ProjectFactory()
        self.user = self.node.creator
        self.conference = ConferenceFactory()
        self.body = 'dragon on my back'
        self.content = 'dragon attack'
        self.attachment = StringIO(self.content)
        self.recipient = '{0}{1}[email protected]'.format(
            'test-' if settings.DEV_MODE else '',
            self.conference.endpoint,
        )

    def make_context(self, **kwargs):
        data = {
            'attachment-count': '1',
            'attachment-1': (self.attachment, 'attachment-1'),
            'X-Mailgun-Sscore': 0,
            'recipient': self.recipient,
            'stripped-text': self.body,
        }
        data.update(kwargs.pop('data', {}))
        return super(TestProvisionNode, self).make_context(data=data, **kwargs)

    def test_provision(self):
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_true(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in(self.conference.endpoint, self.node.system_tags)
        assert_true(
            self.node.tags.filter(name=self.conference.endpoint).exists())
        assert_not_in('spam', self.node.system_tags)

    def test_provision_private(self):
        self.conference.public_projects = False
        self.conference.save()
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_not_in('spam', self.node.system_tags)

    def test_provision_spam(self):
        with self.make_context(
                data={'X-Mailgun-Sscore': message.SSCORE_MAX_VALUE + 1}):
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in('spam', self.node.system_tags)

    @mock.patch('website.util.waterbutler_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        self.attachment.filename = 'hammer-to-fall'
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            'upload',
            'osfstorage',
            '/' + self.attachment.filename,
            self.node,
            _internal=True,
            user=self.user,
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )

    @mock.patch('website.util.waterbutler_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload_no_file_name(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        self.attachment.filename = ''
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            'upload',
            'osfstorage',
            '/' + settings.MISSING_FILE_NAME,
            self.node,
            _internal=True,
            user=self.user,
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )
class TestProvisionNode(ContextTestCase):

    def setUp(self):
        super(TestProvisionNode, self).setUp()
        self.node = ProjectFactory()
        self.user = self.node.creator
        self.conference = ConferenceFactory()
        self.body = 'dragon on my back'
        self.content = b'dragon attack'
        self.attachment = BytesIO(self.content)
        self.recipient = '{0}{1}[email protected]'.format(
            'test-' if settings.DEV_MODE else '',
            self.conference.endpoint,
        )

    def make_context(self, **kwargs):
        data = {
            'attachment-count': '1',
            'attachment-1': (self.attachment, 'attachment-1'),
            'X-Mailgun-Sscore': 0,
            'recipient': self.recipient,
            'stripped-text': self.body,
        }
        data.update(kwargs.pop('data', {}))
        return super(TestProvisionNode, self).make_context(data=data, **kwargs)

    def test_provision(self):
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_true(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in(self.conference.endpoint, self.node.system_tags)
        assert self.node in self.conference.submissions.all()
        assert_not_in('spam', self.node.system_tags)

    def test_provision_private(self):
        self.conference.public_projects = False
        self.conference.save()
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_not_in('spam', self.node.system_tags)

    def test_provision_spam(self):
        with self.make_context(data={'X-Mailgun-Sscore': message.SSCORE_MAX_VALUE + 1}):
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in('spam', self.node.system_tags)

    @mock.patch('website.conferences.utils.waterbutler_api_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        file_name = 'hammer-to-fall'
        self.attachment.filename = file_name
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            self.node._id,
            'osfstorage',
            _internal=True,
            base_url=self.node.osfstorage_region.waterbutler_url,
            cookie=self.user.get_or_create_cookie().decode(),
            name=file_name
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )

    @mock.patch('website.conferences.utils.waterbutler_api_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload_no_file_name(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        self.attachment.filename = ''
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            self.node._id,
            'osfstorage',
            _internal=True,
            base_url=self.node.osfstorage_region.waterbutler_url,
            cookie=self.user.get_or_create_cookie().decode(),
            name=settings.MISSING_FILE_NAME,
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )

    @mock.patch('website.conferences.utils.upload_attachments')
    def test_add_poster_by_email(self, mock_upload_attachments):
        conference = ConferenceFactory()

        with self.make_context(data={'from': '*****@*****.**', 'subject': 'It\'s PARTY TIME!'}):
            msg = message.ConferenceMessage()
            views.add_poster_by_email(conference, msg)

        user = OSFUser.objects.get(username='******')
        assert user.email == '*****@*****.**'
        assert user.fullname == user._id  # user's shouldn't be able to use email as fullname, so we use the guid.
Example #10
0
class TestProvisionNode(ContextTestCase):

    def setUp(self):
        super(TestProvisionNode, self).setUp()
        self.node = ProjectFactory()
        self.user = self.node.creator
        self.conference = ConferenceFactory()
        self.body = 'dragon on my back'
        self.content = 'dragon attack'
        self.attachment = StringIO(self.content)
        self.recipient = '{0}{1}[email protected]'.format(
            'test-' if settings.DEV_MODE else '',
            self.conference.endpoint,
        )

    def make_context(self, **kwargs):
        data = {
            'attachment-count': '1',
            'attachment-1': (self.attachment, 'attachment-1'),
            'X-Mailgun-Sscore': 0,
            'recipient': self.recipient,
            'stripped-text': self.body,
        }
        data.update(kwargs.pop('data', {}))
        return super(TestProvisionNode, self).make_context(data=data, **kwargs)

    def test_provision(self):
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_true(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in(self.conference.endpoint, self.node.system_tags)
        assert_true(self.node.tags.filter(name=self.conference.endpoint).exists())
        assert_not_in('spam', self.node.system_tags)

    def test_provision_private(self):
        self.conference.public_projects = False
        self.conference.save()
        with self.make_context():
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_not_in('spam', self.node.system_tags)

    def test_provision_spam(self):
        with self.make_context(data={'X-Mailgun-Sscore': message.SSCORE_MAX_VALUE + 1}):
            msg = message.ConferenceMessage()
            utils.provision_node(self.conference, msg, self.node, self.user)
        assert_false(self.node.is_public)
        assert_in(self.conference.admins.first(), self.node.contributors)
        assert_in('emailed', self.node.system_tags)
        assert_in('spam', self.node.system_tags)

    @mock.patch('website.util.waterbutler_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        self.attachment.filename = 'hammer-to-fall'
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            'upload',
            'osfstorage',
            '/' + self.attachment.filename,
            self.node,
            _internal=True,
            user=self.user,
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )

    @mock.patch('website.util.waterbutler_url_for')
    @mock.patch('website.conferences.utils.requests.put')
    def test_upload_no_file_name(self, mock_put, mock_get_url):
        mock_get_url.return_value = 'http://queen.com/'
        self.attachment.filename = ''
        self.attachment.content_type = 'application/json'
        utils.upload_attachment(self.user, self.node, self.attachment)
        mock_get_url.assert_called_with(
            'upload',
            'osfstorage',
            '/' + settings.MISSING_FILE_NAME,
            self.node,
            _internal=True,
            user=self.user,
        )
        mock_put.assert_called_with(
            mock_get_url.return_value,
            data=self.content,
        )