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


Python NodeFactory.get_addon方法代码示例

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


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

示例1: test_migrate_osffiles

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import get_addon [as 别名]
 def test_migrate_osffiles(self):
     node = NodeFactory()
     osf_addon = node.get_addon('osffiles')
     AddonFilesNodeSettings.remove_one(osf_addon)
     assert_false(node.has_addon('osffiles'))
     was_migrated = migrate_addons(node)
     assert_true(was_migrated)
     assert_true(node.has_addon('osffiles'))
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:ensure_wiki_and_files.py

示例2: test_migrate_wiki

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import get_addon [as 别名]
 def test_migrate_wiki(self):
     node = NodeFactory()
     wiki_addon = node.get_addon('wiki')
     AddonWikiNodeSettings.remove_one(wiki_addon)
     assert_false(node.has_addon('wiki'))
     was_migrated = migrate_addons(node)
     assert_true(was_migrated)
     assert_true(node.has_addon('wiki'))
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:ensure_wiki_and_files.py

示例3: test_affected_nodes

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import get_addon [as 别名]
    def test_affected_nodes(self):
        affected_node = NodeFactory()
        AddonWikiNodeSettings.remove_one(affected_node.get_addon('wiki'))
        assert_false(affected_node.has_addon('wiki'))

        unaffected_node = NodeFactory()
        assert_true(unaffected_node.has_addon('wiki'))

        affected_nodes = list(get_affected_nodes(self.db, AddonWikiNodeSettings))

        assert_in(affected_node, affected_nodes)
        assert_not_in(unaffected_node, affected_nodes)
开发者ID:adlius,项目名称:osf.io,代码行数:14,代码来源:ensure_wiki_and_files.py

示例4: TestFigshareAPIWrapper

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

    def setUp(self):
        OsfTestCase.setUp(self)
        self.node = NodeFactory()
        self.node.add_addon('figshare', auth=Auth(self.node.creator))
        self.node.save()
        self.node_settings = self.node.get_addon('figshare')
        self.client = Figshare()

    def test_get_project_url(self):
        url = _get_project_url(self.node_settings, 123)
        expected = os.path.join(self.node_settings.api_url, 'projects', '123')
        assert_equal(url, expected)

    # Regression test
    @mock.patch('website.addons.figshare.api.Figshare._send')
    def test_add_article_to_project_called_with_correct_url(self, mock_send):
        self.client.add_article_to_project(self.node_settings, 123, 'foo')
        url = _get_project_url(self.node_settings, 123, 'articles')
        assert_equal(mock_send.call_args[0][0], url)

    @mock.patch('website.addons.figshare.api.Figshare._send')
    def test_remove_article_from_project_called_with_correct_url(self, mock_send):
        self.client.add_article_to_project(self.node_settings, 123, 'foo')
        url = _get_project_url(self.node_settings, 123, 'articles')
        assert_equal(mock_send.call_args[0][0], url)

    @mock.patch('website.addons.figshare.api.Figshare._send')
    def test_delete_project_called_with_correct_url(self, mock_send):
        self.client.delete_project(self.node_settings, 123)
        url = _get_project_url(self.node_settings, 123)
        assert_equal(mock_send.call_args[0][0], url)

    @mock.patch('website.addons.figshare.api.Figshare._send')
    def test_create_project_called_with_correct_url(self, mock_send):
        self.client.create_project(self.node_settings, 123)
        url = _get_project_url(self.node_settings, '').rstrip('/')
        assert_equal(mock_send.call_args[0][0], url)

    @mock.patch('website.addons.figshare.api.Figshare._send')
    def test_get_project_collaborators(self, mock_send):
        self.client.get_project_collaborators(self.node_settings, 123)
        url = _get_project_url(self.node_settings, 123, 'collaborators')
        assert_equal(mock_send.call_args[0][0], url)
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:47,代码来源:test_api.py

示例5: FileCommentMoveRenameTestMixin

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import get_addon [as 别名]
class FileCommentMoveRenameTestMixin(object):
    # TODO: Remove skip decorators when waterbutler returns a consistently formatted payload
    # for intra-provider folder moves and renames.

    id_based_providers = ['osfstorage']

    @property
    def provider(self):
        raise NotImplementedError

    @property
    def ProviderFile(self):
        raise NotImplementedError

    @classmethod
    def _format_path(cls, path, file_id=None):
        return path

    def setUp(self):
        super(FileCommentMoveRenameTestMixin, self).setUp()
        self.user = UserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.project.add_addon(self.provider, auth=Auth(self.user))
        self.project.save()
        self.project_settings = self.project.get_addon(self.provider)
        self.project_settings.folder = '/Folder1'
        self.project_settings.save()

        self.component = NodeFactory(parent=self.project, creator=self.user)
        self.component.add_addon(self.provider, auth=Auth(self.user))
        self.component.save()
        self.component_settings = self.component.get_addon(self.provider)
        self.component_settings.folder = '/Folder2'
        self.component_settings.save()

    def _create_source_payload(self, path, node, provider, file_id=None):
        return OrderedDict([('materialized', path),
                            ('name', path.split('/')[-1]),
                            ('nid', node._id),
                            ('path', self._format_path(path, file_id)),
                            ('provider', provider),
                            ('url', '/project/{}/files/{}/{}/'.format(node._id, provider, path.strip('/'))),
                            ('node', {'url': '/{}/'.format(node._id), '_id': node._id, 'title': node.title}),
                            ('addon', provider)])

    def _create_destination_payload(self, path, node, provider, file_id, children=None):
        destination_path = PROVIDER_CLASS.get(provider)._format_path(path=path, file_id=file_id)
        destination = OrderedDict([('contentType', ''),
                            ('etag', 'abcdefghijklmnop'),
                            ('extra', OrderedDict([('revisionId', '12345678910')])),
                            ('kind', 'file'),
                            ('materialized', path),
                            ('modified', 'Tue, 02 Feb 2016 17:55:48 +0000'),
                            ('name', path.split('/')[-1]),
                            ('nid', node._id),
                            ('path', destination_path),
                            ('provider', provider),
                            ('size', 1000),
                            ('url', '/project/{}/files/{}/{}/'.format(node._id, provider, path.strip('/'))),
                            ('node', {'url': '/{}/'.format(node._id), '_id': node._id, 'title': node.title}),
                            ('addon', provider)])
        if children:
            destination_children = [self._create_destination_payload(child['path'], child['node'], child['provider'], file_id) for child in children]
            destination.update({'children': destination_children})
        return destination

    def _create_payload(self, action, user, source, destination, file_id, destination_file_id=None):
        return OrderedDict([
            ('action', action),
            ('auth', OrderedDict([('email', user.username), ('id', user._id), ('name', user.fullname)])),
            ('destination', self._create_destination_payload(path=destination['path'],
                                                             node=destination['node'],
                                                             provider=destination['provider'],
                                                             file_id=destination_file_id or file_id,
                                                             children=destination.get('children', []))),
            ('source', self._create_source_payload(source['path'], source['node'], source['provider'], file_id=file_id)),
            ('time', 100000000),
            ('node', source['node']),
            ('project', None)
        ])

    def _create_file_with_comment(self, node, path):
        self.file = self.ProviderFile.create(
            is_file=True,
            node=node,
            path=path,
            name=path.strip('/'),
            materialized_path=path)
        self.guid = self.file.get_guid(create=True)
        self.file.save()
        self.comment = CommentFactory(user=self.user, node=node, target=self.guid)

    def test_comments_move_on_file_rename(self):
        source = {
            'path': '/file.txt',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': '/file_renamed.txt',
#.........这里部分代码省略.........
开发者ID:545zhou,项目名称:osf.io,代码行数:103,代码来源:test_comments.py

示例6: FileCommentMoveRenameTestMixin

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import get_addon [as 别名]
class FileCommentMoveRenameTestMixin(object):
    # TODO: Remove skip decorators when waterbutler returns a consistently formatted payload
    # for intra-provider folder moves and renames.

    id_based_providers = ["osfstorage"]

    @property
    def provider(self):
        raise NotImplementedError

    @property
    def ProviderFile(self):
        raise NotImplementedError

    @classmethod
    def _format_path(cls, path, file_id=None):
        return path

    def setUp(self):
        super(FileCommentMoveRenameTestMixin, self).setUp()
        self.user = UserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.project.add_addon(self.provider, auth=Auth(self.user))
        self.project.save()
        self.project_settings = self.project.get_addon(self.provider)
        self.project_settings.folder = "/Folder1"
        self.project_settings.save()

        self.component = NodeFactory(parent=self.project, creator=self.user)
        self.component.add_addon(self.provider, auth=Auth(self.user))
        self.component.save()
        self.component_settings = self.component.get_addon(self.provider)
        self.component_settings.folder = "/Folder2"
        self.component_settings.save()

    def _create_source_payload(self, path, node, provider, file_id=None):
        return OrderedDict(
            [
                ("materialized", path),
                ("name", path.split("/")[-1]),
                ("nid", node._id),
                ("path", self._format_path(path, file_id)),
                ("provider", provider),
                ("url", "/project/{}/files/{}/{}/".format(node._id, provider, path.strip("/"))),
                ("node", {"url": "/{}/".format(node._id), "_id": node._id, "title": node.title}),
                ("addon", provider),
            ]
        )

    def _create_destination_payload(self, path, node, provider, file_id, children=None):
        destination_path = PROVIDER_CLASS.get(provider)._format_path(path=path, file_id=file_id)
        destination = OrderedDict(
            [
                ("contentType", ""),
                ("etag", "abcdefghijklmnop"),
                ("extra", OrderedDict([("revisionId", "12345678910")])),
                ("kind", "file"),
                ("materialized", path),
                ("modified", "Tue, 02 Feb 2016 17:55:48 +0000"),
                ("name", path.split("/")[-1]),
                ("nid", node._id),
                ("path", destination_path),
                ("provider", provider),
                ("size", 1000),
                ("url", "/project/{}/files/{}/{}/".format(node._id, provider, path.strip("/"))),
                ("node", {"url": "/{}/".format(node._id), "_id": node._id, "title": node.title}),
                ("addon", provider),
            ]
        )
        if children:
            destination_children = [
                self._create_destination_payload(child["path"], child["node"], child["provider"], file_id)
                for child in children
            ]
            destination.update({"children": destination_children})
        return destination

    def _create_payload(self, action, user, source, destination, file_id, destination_file_id=None):
        return OrderedDict(
            [
                ("action", action),
                ("auth", OrderedDict([("email", user.username), ("id", user._id), ("name", user.fullname)])),
                (
                    "destination",
                    self._create_destination_payload(
                        path=destination["path"],
                        node=destination["node"],
                        provider=destination["provider"],
                        file_id=destination_file_id or file_id,
                        children=destination.get("children", []),
                    ),
                ),
                (
                    "source",
                    self._create_source_payload(source["path"], source["node"], source["provider"], file_id=file_id),
                ),
                ("time", 100000000),
                ("node", source["node"]),
                ("project", None),
            ]
#.........这里部分代码省略.........
开发者ID:ycchen1989,项目名称:osf.io,代码行数:103,代码来源:test_comments.py


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