本文整理汇总了Python中tests.factories.NodeFactory.set_privacy方法的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory.set_privacy方法的具体用法?Python NodeFactory.set_privacy怎么用?Python NodeFactory.set_privacy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.NodeFactory
的用法示例。
在下文中一共展示了NodeFactory.set_privacy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestShortUrls
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestShortUrls(OsfTestCase):
def setUp(self):
super(TestShortUrls, self).setUp()
self.user = AuthUserFactory()
self.auth = self.user.auth
self.consolidate_auth = Auth(user=self.user)
self.project = ProjectFactory(creator=self.user)
# A non-project componenet
self.component = NodeFactory(category="hypothesis", creator=self.user)
self.project.nodes.append(self.component)
self.component.save()
# Hack: Add some logs to component; should be unnecessary pending
# improvements to factories from @rliebz
self.component.set_privacy("public", auth=self.consolidate_auth)
self.component.set_privacy("private", auth=self.consolidate_auth)
self.wiki = NodeWikiFactory(user=self.user, node=self.component)
def _url_to_body(self, url):
return self.app.get(url, auth=self.auth).maybe_follow(auth=self.auth).normal_body
def test_project_url(self):
assert_equal(self._url_to_body(self.project.deep_url), self._url_to_body(self.project.url))
def test_component_url(self):
assert_equal(self._url_to_body(self.component.deep_url), self._url_to_body(self.component.url))
def test_wiki_url(self):
assert_equal(self._url_to_body(self.wiki.deep_url), self._url_to_body(self.wiki.url))
示例2: TestComponents
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestComponents(OsfTestCase):
def setUp(self):
super(TestComponents, self).setUp()
self.user = AuthUserFactory()
self.consolidate_auth = Auth(user=self.user)
self.project = ProjectFactory(creator=self.user)
self.project.add_contributor(contributor=self.user, auth=self.consolidate_auth)
# A non-project componenet
self.component = NodeFactory(category="hypothesis", creator=self.user, parent=self.project)
self.component.save()
self.component.set_privacy("public", self.consolidate_auth)
self.component.set_privacy("private", self.consolidate_auth)
self.project.save()
self.project_url = self.project.web_url_for("view_project")
def test_can_create_component_from_a_project(self):
res = self.app.get(self.project.url, auth=self.user.auth).maybe_follow()
assert_in("Add Component", res)
def test_can_create_component_from_a_component(self):
res = self.app.get(self.component.url, auth=self.user.auth).maybe_follow()
assert_in("Add Component", res)
def test_sees_parent(self):
res = self.app.get(self.component.url, auth=self.user.auth).maybe_follow()
parent_title = res.html.find_all("h2", class_="node-parent-title")
assert_equal(len(parent_title), 1)
assert_in(self.project.title, parent_title[0].text) # Bs4 will handle unescaping HTML here
def test_delete_project(self):
res = self.app.get(self.component.url + "settings/", auth=self.user.auth).maybe_follow()
assert_in("Delete {0}".format(self.component.project_or_component), res)
def test_cant_delete_project_if_not_admin(self):
non_admin = AuthUserFactory()
self.component.add_contributor(non_admin, permissions=["read", "write"], auth=self.consolidate_auth, save=True)
res = self.app.get(self.component.url + "settings/", auth=non_admin.auth).maybe_follow()
assert_not_in("Delete {0}".format(self.component.project_or_component), res)
def test_can_configure_comments_if_admin(self):
res = self.app.get(self.component.url + "settings/", auth=self.user.auth).maybe_follow()
assert_in("Configure Commenting", res)
def test_cant_configure_comments_if_not_admin(self):
non_admin = AuthUserFactory()
self.component.add_contributor(non_admin, permissions=["read", "write"], auth=self.consolidate_auth, save=True)
res = self.app.get(self.component.url + "settings/", auth=non_admin.auth).maybe_follow()
assert_not_in("Configure commenting", res)
def test_components_should_have_component_list(self):
res = self.app.get(self.component.url, auth=self.user.auth)
assert_in("Components", res)
示例3: TestShortUrls
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestShortUrls(OsfTestCase):
def setUp(self):
super(TestShortUrls, self).setUp()
self.user = UserFactory()
# Add an API key for quicker authentication
api_key = ApiKeyFactory()
self.user.api_keys.append(api_key)
self.user.save()
self.auth = ('test', api_key._primary_key)
self.consolidate_auth = Auth(user=self.user, api_key=api_key)
self.project = ProjectFactory(creator=self.user)
# A non-project componenet
self.component = NodeFactory(category='hypothesis', creator=self.user)
self.project.nodes.append(self.component)
self.component.save()
# Hack: Add some logs to component; should be unnecessary pending
# improvements to factories from @rliebz
self.component.set_privacy('public', auth=self.consolidate_auth)
self.component.set_privacy('private', auth=self.consolidate_auth)
self.wiki = NodeWikiFactory(user=self.user, node=self.component)
def _url_to_body(self, url):
return self.app.get(
url,
auth=self.auth
).maybe_follow(
auth=self.auth,
).normal_body
def test_project_url(self):
assert_equal(
self._url_to_body(self.project.deep_url),
self._url_to_body(self.project.url),
)
def test_component_url(self):
assert_equal(
self._url_to_body(self.component.deep_url),
self._url_to_body(self.component.url),
)
def test_wiki_url(self):
assert_equal(
self._url_to_body(self.wiki.deep_url),
self._url_to_body(self.wiki.url),
)
示例4: TestComponents
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestComponents(OsfTestCase):
def setUp(self):
super(TestComponents, self).setUp()
self.user = AuthUserFactory()
self.consolidate_auth = Auth(user=self.user)
self.project = ProjectFactory(creator=self.user)
self.project.add_contributor(contributor=self.user, auth=self.consolidate_auth)
# A non-project componenet
self.component = NodeFactory(
category='hypothesis',
creator=self.user,
parent=self.project,
)
self.component.save()
self.component.set_privacy('public', self.consolidate_auth)
self.component.set_privacy('private', self.consolidate_auth)
self.project.save()
self.project_url = self.project.web_url_for('view_project')
def test_sees_parent(self):
res = self.app.get(self.component.url, auth=self.user.auth).maybe_follow()
parent_title = res.html.find_all('h2', class_='node-parent-title')
assert_equal(len(parent_title), 1)
assert_in(self.project.title, parent_title[0].text) # Bs4 will handle unescaping HTML here
def test_delete_project(self):
res = self.app.get(
self.component.url + 'settings/',
auth=self.user.auth
).maybe_follow()
assert_in(
'Delete {0}'.format(self.component.project_or_component),
res
)
def test_cant_delete_project_if_not_admin(self):
non_admin = AuthUserFactory()
self.component.add_contributor(
non_admin,
permissions=['read', 'write'],
auth=self.consolidate_auth,
save=True,
)
res = self.app.get(
self.component.url + 'settings/',
auth=non_admin.auth
).maybe_follow()
assert_not_in(
'Delete {0}'.format(self.component.project_or_component),
res
)
def test_can_configure_comments_if_admin(self):
res = self.app.get(
self.component.url + 'settings/',
auth=self.user.auth,
).maybe_follow()
assert_in('Commenting', res)
def test_cant_configure_comments_if_not_admin(self):
non_admin = AuthUserFactory()
self.component.add_contributor(
non_admin,
permissions=['read', 'write'],
auth=self.consolidate_auth,
save=True,
)
res = self.app.get(
self.component.url + 'settings/',
auth=non_admin.auth
).maybe_follow()
assert_not_in('Commenting', res)
def test_components_should_have_component_list(self):
res = self.app.get(self.component.url, auth=self.user.auth)
assert_in('Components', res)
示例5: TestPublicNodes
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestPublicNodes(SearchTestCase):
def setUp(self):
super(TestPublicNodes, self).setUp()
self.user = UserFactory(usename='Doug Bogie')
self.title = 'Red Special'
self.consolidate_auth = Auth(user=self.user)
self.project = ProjectFactory(
title=self.title,
creator=self.user,
is_public=True,
)
self.component = NodeFactory(
parent=self.project,
title=self.title,
creator=self.user,
is_public=True
)
self.registration = ProjectFactory(
title=self.title,
creator=self.user,
is_public=True,
is_registration=True
)
def test_make_private(self):
"""Make project public, then private, and verify that it is not present
in search.
"""
self.project.set_privacy('private')
docs = query('category:project AND ' + self.title)['results']
assert_equal(len(docs), 0)
self.component.set_privacy('private')
docs = query('category:component AND ' + self.title)['results']
assert_equal(len(docs), 0)
self.registration.set_privacy('private')
docs = query('category:registration AND ' + self.title)['results']
assert_equal(len(docs), 0)
def test_public_parent_title(self):
self.project.set_title('hello & world', self.consolidate_auth)
self.project.save()
docs = query('category:component AND ' + self.title)['results']
assert_equal(len(docs), 1)
assert_equal(docs[0]['parent_title'], 'hello & world')
assert_true(docs[0]['parent_url'])
def test_make_parent_private(self):
"""Make parent of component, public, then private, and verify that the
component still appears but doesn't link to the parent in search.
"""
self.project.set_privacy('private')
docs = query('category:component AND ' + self.title)['results']
assert_equal(len(docs), 1)
assert_equal(docs[0]['parent_title'], '-- private project --')
assert_false(docs[0]['parent_url'])
def test_delete_project(self):
"""
"""
self.component.remove_node(self.consolidate_auth)
docs = query('category:component AND ' + self.title)['results']
assert_equal(len(docs), 0)
self.project.remove_node(self.consolidate_auth)
docs = query('category:project AND ' + self.title)['results']
assert_equal(len(docs), 0)
def test_change_title(self):
"""
"""
title_original = self.project.title
self.project.set_title(
'Blue Ordinary', self.consolidate_auth, save=True)
docs = query('category:project AND ' + title_original)['results']
assert_equal(len(docs), 0)
docs = query('category:project AND ' + self.project.title)['results']
assert_equal(len(docs), 1)
def test_add_tags(self):
tags = ['stonecoldcrazy', 'just a poor boy', 'from-a-poor-family']
for tag in tags:
docs = query('tags:"{}"'.format(tag))['results']
assert_equal(len(docs), 0)
self.project.add_tag(tag, self.consolidate_auth, save=True)
for tag in tags:
docs = query('tags:"{}"'.format(tag))['results']
assert_equal(len(docs), 1)
def test_remove_tag(self):
tags = ['stonecoldcrazy', 'just a poor boy', 'from-a-poor-family']
#.........这里部分代码省略.........
示例6: TestShortUrls
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestShortUrls(OsfTestCase):
def setUp(self):
super(TestShortUrls, self).setUp()
self.user = UserFactory()
# Add an API key for quicker authentication
api_key = ApiKeyFactory()
self.user.api_keys.append(api_key)
self.user.save()
self.auth = ('test', api_key._primary_key)
self.consolidate_auth=Auth(user=self.user, api_key=api_key)
self.project = ProjectFactory(creator=self.user)
# A non-project componenet
self.component = NodeFactory(category='hypothesis', creator=self.user)
self.project.nodes.append(self.component)
self.component.save()
# Hack: Add some logs to component; should be unnecessary pending
# improvements to factories from @rliebz
self.component.set_privacy('public', auth=self.consolidate_auth)
self.component.set_privacy('private', auth=self.consolidate_auth)
self.wiki = NodeWikiFactory(user=self.user, node=self.component)
def _url_to_body(self, url):
return self.app.get(
url,
auth=self.auth
).maybe_follow(
auth=self.auth,
).normal_body
def test_profile_url(self):
res1 = self.app.get('/{}/'.format(self.user._primary_key)).maybe_follow()
res2 = self.app.get('/profile/{}/'.format(self.user._primary_key)).maybe_follow()
assert_equal(
res1.normal_body,
res2.normal_body
)
def test_project_url(self):
assert_equal(
self._url_to_body(self.project.deep_url),
self._url_to_body(self.project.url),
)
def test_component_url(self):
assert_equal(
self._url_to_body(self.component.deep_url),
self._url_to_body(self.component.url),
)
def _mock_rendered_file(self, component, fobj):
node_settings = component.get_addon('osffiles')
cache_dir = get_cache_path(node_settings)
cache_file = get_cache_file(fobj.filename, fobj.latest_version_number(component))
cache_file_path = os.path.join(cache_dir, cache_file)
ensure_path(cache_dir)
with open(cache_file_path, 'w') as fp:
fp.write('test content')
def test_wiki_url(self):
assert_equal(
self._url_to_body(self.wiki.deep_url),
self._url_to_body(self.wiki.url),
)
示例7: TestPublicNodes
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import set_privacy [as 别名]
class TestPublicNodes(SearchTestCase):
def setUp(self):
super(TestPublicNodes, self).setUp()
self.user = UserFactory(usename="Doug Bogie")
self.title = "Red Special"
self.consolidate_auth = Auth(user=self.user)
self.project = ProjectFactory(title=self.title, creator=self.user, is_public=True)
self.component = NodeFactory(parent=self.project, title=self.title, creator=self.user, is_public=True)
self.registration = ProjectFactory(title=self.title, creator=self.user, is_public=True, is_registration=True)
def test_make_private(self):
"""Make project public, then private, and verify that it is not present
in search.
"""
self.project.set_privacy("private")
docs = query("category:project AND " + self.title)["results"]
assert_equal(len(docs), 0)
self.component.set_privacy("private")
docs = query("category:component AND " + self.title)["results"]
assert_equal(len(docs), 0)
self.registration.set_privacy("private")
docs = query("category:registration AND " + self.title)["results"]
assert_equal(len(docs), 0)
def test_public_parent_title(self):
self.project.set_title("hello & world", self.consolidate_auth)
self.project.save()
docs = query("category:component AND " + self.title)["results"]
assert_equal(len(docs), 1)
assert_equal(docs[0]["parent_title"], "hello & world")
assert_true(docs[0]["parent_url"])
def test_make_parent_private(self):
"""Make parent of component, public, then private, and verify that the
component still appears but doesn't link to the parent in search.
"""
self.project.set_privacy("private")
docs = query("category:component AND " + self.title)["results"]
assert_equal(len(docs), 1)
assert_equal(docs[0]["parent_title"], "-- private project --")
assert_false(docs[0]["parent_url"])
def test_delete_project(self):
"""
"""
self.component.remove_node(self.consolidate_auth)
docs = query("category:component AND " + self.title)["results"]
assert_equal(len(docs), 0)
self.project.remove_node(self.consolidate_auth)
docs = query("category:project AND " + self.title)["results"]
assert_equal(len(docs), 0)
def test_change_title(self):
"""
"""
title_original = self.project.title
self.project.set_title("Blue Ordinary", self.consolidate_auth, save=True)
docs = query("category:project AND " + title_original)["results"]
assert_equal(len(docs), 0)
docs = query("category:project AND " + self.project.title)["results"]
assert_equal(len(docs), 1)
def test_add_tags(self):
tags = ["stonecoldcrazy", "just a poor boy", "from-a-poor-family"]
for tag in tags:
docs = query('tags:"{}"'.format(tag))["results"]
assert_equal(len(docs), 0)
self.project.add_tag(tag, self.consolidate_auth, save=True)
for tag in tags:
docs = query('tags:"{}"'.format(tag))["results"]
assert_equal(len(docs), 1)
def test_remove_tag(self):
tags = ["stonecoldcrazy", "just a poor boy", "from-a-poor-family"]
for tag in tags:
self.project.add_tag(tag, self.consolidate_auth, save=True)
self.project.remove_tag(tag, self.consolidate_auth, save=True)
docs = query('tags:"{}"'.format(tag))["results"]
assert_equal(len(docs), 0)
def test_update_wiki(self):
"""Add text to a wiki page, then verify that project is found when
searching for wiki text.
"""
wiki_content = {"home": "Hammer to fall", "swag": "#YOLO"}
for key, value in wiki_content.items():
docs = query(value)["results"]
assert_equal(len(docs), 0)
#.........这里部分代码省略.........