本文整理汇总了Python中tests.factories.NodeFactory.add_addon方法的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory.add_addon方法的具体用法?Python NodeFactory.add_addon怎么用?Python NodeFactory.add_addon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.NodeFactory
的用法示例。
在下文中一共展示了NodeFactory.add_addon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFigshareAPIWrapper
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_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)
示例2: FileCommentMoveRenameTestMixin
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_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',
#.........这里部分代码省略.........
示例3: FileCommentMoveRenameTestMixin
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_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),
]
#.........这里部分代码省略.........