本文整理汇总了Python中tests.factories.ProjectFactory.use_as_template方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.use_as_template方法的具体用法?Python ProjectFactory.use_as_template怎么用?Python ProjectFactory.use_as_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.ProjectFactory
的用法示例。
在下文中一共展示了ProjectFactory.use_as_template方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestResolveTemplatedOrphans
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import use_as_template [as 别名]
class TestResolveTemplatedOrphans(OsfTestCase):
def setUp(self):
super(TestResolveTemplatedOrphans, self).setUp()
self.node = NodeFactory()
self.project = ProjectFactory(creator=self.node.creator)
self.project.nodes.append(self.node)
self.project.save()
self.templated_project = self.project.use_as_template(
Auth(self.node.creator)
)
self.templated_node = self.templated_project.nodes[0]
self.templated_project.nodes = []
self.templated_project.save()
def test_find(self):
orphans = find_templated_orphans()
assert_equal(orphans.count(), 1)
assert_equal(orphans[0], self.templated_node)
def test_resolve(self):
assert_not_in(self.templated_node, self.templated_project.nodes)
resolve_templated_orphan(self.node)
assert_in(self.node, self.project.nodes)
示例2: TestMigrateTemplates
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import use_as_template [as 别名]
class TestMigrateTemplates(OsfTestCase):
def setUp(self):
super(TestMigrateTemplates, self).setUp()
# Create registration with correct settings
self.user = UserFactory()
self.consolidated_auth = Auth(user=self.user)
# Create base project
self.base_project = ProjectFactory(
creator=self.user,
piwik_site_id=1,
)
self.base_component = NodeFactory(
project=self.base_project,
creator=self.user,
piwik_site_id=2,
)
# Create valid template
self.template_project = self.base_project.use_as_template(
auth=self.consolidated_auth
)
self.template_project.piwik_site_id = 3
self.template_project.save()
self.template_component = self.template_project.nodes[0]
self.template_component.piwik_site_id = 4
self.template_component.save()
# Create broken fork
self.bad_template_project = self.base_project.use_as_template(
auth=self.consolidated_auth
)
self.bad_template_project.piwik_site_id = self.base_project.piwik_site_id
self.bad_template_project.save()
self.bad_template_component = self.bad_template_project.nodes[0]
self.bad_template_component.piwik_site_id = self.base_component.piwik_site_id
self.bad_template_component.save()
responses.start()
responses.add(
responses.GET,
'{host}index.php?module=API&method=SitesManager.getAllSites&format=JSON&token_auth={auth_token}'.format(
host=PIWIK_HOST,
auth_token=PIWIK_ADMIN_TOKEN,
),
status=200,
content_type='application/json',
body=json.dumps({
'1': {'name': 'Node: ' + self.base_project._id},
'2': {'name': 'Node: ' + self.base_component._id},
'3': {'name': 'Node: ' + self.template_project._id},
'4': {'name': 'Node: ' + self.template_component._id},
}),
match_querystring=True,
)
def tearDown(self):
super(TestMigrateTemplates, self).tearDown()
Node.remove()
responses.stop()
responses.reset()
piwik_cache._cache = None
def test_get_broken_templated(self):
nodes = set(get_broken_templated())
assert_equal(2, len(nodes))
assert_equal(
{self.bad_template_project, self.bad_template_component},
nodes,
)
def test_fix_templated(self):
assert_equal(
2,
fix_nodes(get_broken_templated())
)
Node._clear_caches()
broken_nodes = list(get_broken_templated())
assert_equal(0, len(broken_nodes))
assert_is_none(self.bad_template_project.piwik_site_id)
assert_is_none(self.bad_template_component.piwik_site_id)
assert_is_not_none(self.template_project.piwik_site_id)
assert_is_not_none(self.template_component.piwik_site_id)