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


Python NodeFactory.web_url_for方法代码示例

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


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

示例1: test_new_draft_registration_POST

# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import web_url_for [as 别名]
    def test_new_draft_registration_POST(self):
        target = NodeFactory(creator=self.user)
        payload = {
            'schema_name': self.meta_schema.name,
            'schema_version': self.meta_schema.schema_version
        }
        url = target.web_url_for('new_draft_registration')

        res = self.app.post(url, payload, auth=self.user.auth)
        assert_equal(res.status_code, http.FOUND)
        target.reload()
        draft = DraftRegistration.objects.get(branched_from=target)
        assert_equal(draft.registration_schema, self.meta_schema)
开发者ID:icereval,项目名称:osf.io,代码行数:15,代码来源:test_views.py

示例2: test_implicit_admins_can_see_project_status

# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import web_url_for [as 别名]
    def test_implicit_admins_can_see_project_status(self):
        project = ProjectFactory(creator=self.admin)
        component = NodeFactory(creator=self.admin, parent=project)
        project.add_contributor(self.write_contrib, ['read', 'write', 'admin'])
        project.save()

        preprint = PreprintFactory(creator=self.admin, filename='mgla.pdf', provider=self.provider_one, subjects=[[self.subject_one._id]], project=component, is_published=True)
        preprint.machine_state = 'pending'
        provider = PreprintProviderFactory(reviews_workflow='post-moderation')
        preprint.provider = provider
        preprint.save()
        url = component.web_url_for('view_project')

        res = self.app.get(url, auth=self.write_contrib.auth)
        assert_in('{}'.format(preprint.provider.name), res.body)
        assert_in('Pending\n', res.body)
        assert_in('This preprint is publicly available and searchable but is subject to removal by a moderator.', res.body)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:19,代码来源:test_webtests.py

示例3: TestResolveGuid

# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import web_url_for [as 别名]
class TestResolveGuid(OsfTestCase):

    def setUp(self):
        super(TestResolveGuid, self).setUp()
        self.node = NodeFactory()

    def test_resolve_guid(self):
        res_guid = self.app.get(self.node.web_url_for('node_setting', _guid=True), auth=self.node.creator.auth)
        res_full = self.app.get(self.node.web_url_for('node_setting'), auth=self.node.creator.auth)
        assert res_guid.text == res_full.text

    def test_resolve_guid_no_referent(self):
        guid = Guid.load(self.node._id)
        guid.referent = None
        guid.save()
        res = self.app.get(
            self.node.web_url_for('node_setting', _guid=True),
            auth=self.node.creator.auth,
            expect_errors=True,
        )
        assert res.status_code == 404

    @mock.patch('osf.models.node.Node.deep_url', None)
    def test_resolve_guid_no_url(self):
        res = self.app.get(
            self.node.web_url_for('node_setting', _guid=True),
            auth=self.node.creator.auth,
            expect_errors=True,
        )
        assert res.status_code == 404

    def test_resolve_guid_download_file(self):
        pp = PreprintFactory(finish=True)

        res = self.app.get(pp.url + 'download')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('/{}/download'.format(pp.primary_file.get_guid(create=True)._id))
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        pp.primary_file.create_version(
            creator=pp.node.creator,
            location={u'folder': u'osf', u'object': u'deadbe', u'service': u'cloud'},
            metadata={u'contentType': u'img/png', u'size': 9001}
        )
        pp.primary_file.save()

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=2&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/?version=1')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        unpub_pp = PreprintFactory(project=self.node, is_published=False)
        res = self.app.get(unpub_pp.url + 'download/?version=1', auth=self.node.creator.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, unpub_pp.node._id, unpub_pp.primary_file.provider, unpub_pp.primary_file.path) in res.location

    @mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
    @mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
        'preprints': {
            'url': '/preprints/',
            'server': 'http://localhost:4200',
            'path': '/preprints/'
        },
    })
    def test_resolve_guid_download_file_from_emberapp_preprints(self):
        provider = PreprintProviderFactory(_id='sockarxiv', name='Sockarxiv')
        pp = PreprintFactory(finish=True, provider=provider)
        assert pp.url.startswith('/preprints/sockarxiv')

        res = self.app.get(pp.url + 'download')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

    def test_resolve_guid_download_file_export(self):
        pp = PreprintFactory(finish=True)

        res = self.app.get(pp.url + 'download?format=asdf')
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3Faction%3Ddownload'.format(urllib.quote(WATERBUTLER_URL), pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/?format=asdf')
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3Faction%3Ddownload'.format(urllib.quote(WATERBUTLER_URL), pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location

#.........这里部分代码省略.........
开发者ID:leb2dg,项目名称:osf.io,代码行数:103,代码来源:test_guid.py

示例4: TestResolveGuid

# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import web_url_for [as 别名]
class TestResolveGuid(OsfTestCase):

    def setUp(self):
        super(TestResolveGuid, self).setUp()
        self.node = NodeFactory()

    def test_resolve_guid(self):
        res_guid = self.app.get(self.node.web_url_for('node_setting', _guid=True), auth=self.node.creator.auth)
        res_full = self.app.get(self.node.web_url_for('node_setting'), auth=self.node.creator.auth)
        assert res_guid.text == res_full.text

    def test_resolve_guid_no_referent(self):
        guid = Guid.load(self.node._id)
        guid.referent = None
        guid.save()
        res = self.app.get(
            self.node.web_url_for('node_setting', _guid=True),
            auth=self.node.creator.auth,
            expect_errors=True,
        )
        assert res.status_code == 404

    @mock.patch('osf.models.node.Node.deep_url', None)
    def test_resolve_guid_no_url(self):
        res = self.app.get(
            self.node.web_url_for('node_setting', _guid=True),
            auth=self.node.creator.auth,
            expect_errors=True,
        )
        assert res.status_code == 404

    def test_resolve_guid_download_file(self):
        pp = PreprintFactory(finish=True)

        res = self.app.get(pp.url + 'download')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('/{}/download'.format(pp.primary_file.get_guid(create=True)._id))
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        pp.primary_file.create_version(
            creator=pp.creator,
            location={u'folder': u'osf', u'object': u'deadbe', u'service': u'cloud'},
            metadata={u'contentType': u'img/png', u'size': 9001}
        )
        pp.primary_file.save()

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=2&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/?version=1')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        unpub_pp = PreprintFactory(project=self.node, is_published=False)
        res = self.app.get(unpub_pp.url + 'download/?version=1', auth=unpub_pp.creator.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, unpub_pp._id, unpub_pp.primary_file.provider, unpub_pp.primary_file.path) in res.location

    @mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
    @mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
        'preprints': {
            'server': 'http://localhost:4200',
            'path': '/preprints/'
        },
    })
    def test_resolve_guid_download_file_from_emberapp_preprints(self):
        provider = PreprintProviderFactory(_id='sockarxiv', name='Sockarxiv')
        pp = PreprintFactory(finish=True, provider=provider)
        assert pp.url.startswith('/preprints/sockarxiv')

        res = self.app.get(pp.url + 'download')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

    @mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
    @mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
        'preprints': {
            'server': 'http://localhost:4200',
            'path': '/preprints/'
        },
    })
    def test_resolve_guid_download_file_from_emberapp_preprints_unpublished(self):
        # non-branded domains
        provider = PreprintProviderFactory(_id='sockarxiv', name='Sockarxiv', reviews_workflow='pre-moderation')

        # branded domains
        branded_provider = PreprintProviderFactory(_id='spot', name='Spotarxiv', reviews_workflow='pre-moderation')
        branded_provider.allow_submissions = False
#.........这里部分代码省略.........
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:103,代码来源:test_guid.py


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