本文整理汇总了Python中tests.factories.ProjectFactory.set_privacy方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.set_privacy方法的具体用法?Python ProjectFactory.set_privacy怎么用?Python ProjectFactory.set_privacy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.ProjectFactory
的用法示例。
在下文中一共展示了ProjectFactory.set_privacy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_fake_project
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import set_privacy [as 别名]
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name, is_registration):
auth = Auth(user=creator)
project_title = name if name else fake.science_sentence()
if not is_registration:
project = ProjectFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
else:
project = RegistrationFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
project.set_privacy(privacy)
for _ in range(n_users):
contrib = create_fake_user()
project.add_contributor(contrib, auth=auth)
if isinstance(n_components, int):
for _ in range(n_components):
NodeFactory(project=project, title=fake.science_sentence(), description=fake.science_paragraph(),
creator=creator)
elif isinstance(n_components, list):
render_generations_from_node_structure_list(project, creator, n_components)
for _ in range(n_tags):
project.add_tag(fake.science_word(), auth=auth)
if presentation_name is not None:
project.add_tag(presentation_name, auth=auth)
project.add_tag('poster', auth=auth)
project.save()
logger.info('Created project: {0}'.format(project.title))
return project
示例2: test_read_permission_contributor_can_comment
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import set_privacy [as 别名]
def test_read_permission_contributor_can_comment(self):
project = ProjectFactory()
user = UserFactory()
project.set_privacy('private')
project.add_contributor(user, permissions=[permissions.READ])
project.save()
assert_true(project.can_comment(Auth(user=user)))
示例3: TestPiwik
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import set_privacy [as 别名]
class TestPiwik(OsfTestCase):
def setUp(self):
super(TestPiwik, self).setUp()
self.users = [
AuthUserFactory()
for _ in range(3)
]
self.consolidate_auth = Auth(user=self.users[0])
self.project = ProjectFactory(creator=self.users[0], is_public=True)
self.project.add_contributor(contributor=self.users[1])
self.project.save()
def test_contains_iframe_and_src(self):
res = self.app.get(
'/{0}/statistics/'.format(self.project._primary_key),
auth=self.users[0].auth
).maybe_follow()
assert_in('iframe', res)
assert_in('src', res)
assert_in(settings.PIWIK_HOST, res)
def test_anonymous_no_token(self):
res = self.app.get(
'/{0}/statistics/'.format(self.project._primary_key),
auth=self.users[2].auth
).maybe_follow()
assert_in('token_auth=anonymous', res)
def test_contributor_token(self):
res = self.app.get(
'/{0}/statistics/'.format(self.project._primary_key),
auth=self.users[1].auth
).maybe_follow()
assert_in(self.users[1].piwik_token, res)
def test_no_user_token(self):
res = self.app.get(
'/{0}/statistics/'.format(self.project._primary_key)
).maybe_follow()
assert_in('token_auth=anonymous', res)
def test_private_alert(self):
self.project.set_privacy('private', auth=self.consolidate_auth)
self.project.save()
res = self.app.get(
'/{0}/statistics/'.format(self.project._primary_key),
auth=self.users[0].auth
).maybe_follow().normal_body
assert_in(
'Usage statistics are collected only for public resources.',
res
)
示例4: TestProject
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import set_privacy [as 别名]
class TestProject(SearchTestCase):
def setUp(self):
super(TestProject, self).setUp()
search.delete_index(elastic_search.INDEX)
search.create_index(elastic_search.INDEX)
self.user = UserFactory(fullname='John Deacon')
self.project = ProjectFactory(title='Red Special', creator=self.user)
def test_new_project_private(self):
# Verify that a private project is not present in Elastic Search.
docs = query(self.project.title)['results']
assert_equal(len(docs), 0)
def test_make_public(self):
# Make project public, and verify that it is present in Elastic
# Search.
self.project.set_privacy('public')
docs = query(self.project.title)['results']
assert_equal(len(docs), 1)
示例5: create_fake_project
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import set_privacy [as 别名]
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name):
auth = Auth(user=creator)
project_title = name if name else fake.science_sentence()
project = ProjectFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
project.set_privacy(privacy)
for _ in range(n_users):
contrib = create_fake_user()
project.add_contributor(contrib, auth=auth)
for _ in range(n_components):
NodeFactory(project=project, title=fake.science_sentence(), description=fake.science_paragraph(),
creator=creator)
for _ in range(n_tags):
project.add_tag(fake.science_word(), auth=auth)
if presentation_name is not None:
project.add_tag(presentation_name, auth=auth)
project.add_tag('poster', auth=auth)
project.save()
logger.info('Created project: {0}'.format(project.title))
return project
示例6: TestPublicNodes
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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']
#.........这里部分代码省略.........
示例7: TestPublicNodes
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)
#.........这里部分代码省略.........