本文整理汇总了Python中tests.factories.ProjectFactory类的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory类的具体用法?Python ProjectFactory怎么用?Python ProjectFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(TestMustBeContributorOrPublicButNotAnonymizedDecorator, self).setUp()
self.contrib = AuthUserFactory()
self.non_contrib = AuthUserFactory()
admin = UserFactory()
self.public_project = ProjectFactory(is_public=True)
self.public_project.add_contributor(admin, auth=Auth(self.public_project.creator), permissions=['read', 'write', 'admin'])
self.private_project = ProjectFactory(is_public=False)
self.private_project.add_contributor(admin, auth=Auth(self.private_project.creator), permissions=['read', 'write', 'admin'])
self.public_project.add_contributor(self.contrib, auth=Auth(self.public_project.creator))
self.private_project.add_contributor(self.contrib, auth=Auth(self.private_project.creator))
self.public_project.save()
self.private_project.save()
self.anonymized_link_to_public_project = PrivateLinkFactory(anonymous=True)
self.anonymized_link_to_private_project = PrivateLinkFactory(anonymous=True)
self.anonymized_link_to_public_project.nodes.append(self.public_project)
self.anonymized_link_to_public_project.save()
self.anonymized_link_to_private_project.nodes.append(self.private_project)
self.anonymized_link_to_private_project.save()
self.flaskapp = Flask('Testing decorator')
@self.flaskapp.route('/project/<pid>/')
@must_be_contributor_or_public_but_not_anonymized
def project_get(**kwargs):
return 'success', 200
self.app = TestApp(self.flaskapp)
示例2: TestGoogleDriveHgridViews
class TestGoogleDriveHgridViews(OsfTestCase):
def setUp(self):
super(TestGoogleDriveHgridViews, self).setUp()
self.user = AuthUserFactory()
self.user.add_addon('googledrive')
self.project = ProjectFactory(creator=self.user)
self.project.add_addon('googledrive', Auth(self.user))
self.node_settings = self.project.get_addon('googledrive')
self.user_settings = self.user.get_addon('googledrive')
self.node_settings.user_settings = self.user_settings
self.user_settings.save()
self.node_settings.save()
# Log user in
self.app.authenticate(*self.user.auth)
@mock.patch('website.addons.googledrive.views.hgrid.GoogleDriveClient.folders')
def test_googledrive_folders(self, mock_drive_client_folders):
folderId = '12345'
mock_drive_client_folders.return_value = mock_folders['items']
url = api_url_for('googledrive_folders', pid=self.project._primary_key, folderId=folderId)
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, 200)
assert_equal(len(res.json), len(mock_folders['items']))
@mock.patch('website.addons.googledrive.views.hgrid.GoogleDriveClient.about')
def test_googledrive_folders_returns_only_root(self, mock_about):
mock_about.return_value = {'rootFolderId': '24601'}
url = self.project.api_url_for('googledrive_folders')
res = self.app.get(url, auth=self.user.auth)
assert_equal(len(res.json), 1)
assert_equal(res.status_code, 200)
assert_equal(res.json[0]['id'], '24601')
示例3: TestViewsAuth
class TestViewsAuth(OsfTestCase):
def setUp(self):
super(TestViewsAuth, self).setUp()
self.user = AuthUserFactory()
self.consolidated_auth = Auth(user=self.user)
self.auth = ('test', self.user.api_keys[0]._primary_key)
self.project = ProjectFactory(creator=self.user)
self.non_authenticator = AuthUserFactory()
self.project.add_contributor(
contributor=self.non_authenticator,
auth=Auth(self.project.creator),
)
self.project.add_addon('figshare', auth=self.consolidated_auth)
self.project.creator.add_addon('figshare')
self.node_settings = self.project.get_addon('figshare')
self.user_settings = self.project.creator.get_addon('figshare')
self.node_settings.user_settings = self.user_settings
self.node_settings.figshare_id = '436'
self.node_settings.figshare_type = 'project'
self.node_settings.save()
@unittest.skip('finish this')
def test_oauth_fail(self):
url = '/api/v1/project/{0}/figshare/oauth/'.format(self.project._id)
self.app.get(url, auth=self.user.auth)
@unittest.skip('finish this')
def test_oauth_bad_token(self):
pass
示例4: test_POST_register_embargo_does_not_make_project_or_children_public
def test_POST_register_embargo_does_not_make_project_or_children_public(self, mock_enqueue):
public_project = ProjectFactory(creator=self.user, is_public=True)
component = NodeFactory(creator=self.user, parent=public_project, title="Component", is_public=True)
subproject = ProjectFactory(creator=self.user, parent=public_project, title="Subproject", is_public=True)
subproject_component = NodeFactory(creator=self.user, parent=subproject, title="Subcomponent", is_public=True)
res = self.app.post(
public_project.api_url_for("node_register_template_page_post", template=u"Open-Ended_Registration"),
self.valid_embargo_payload,
content_type="application/json",
auth=self.user.auth,
)
public_project.reload()
assert_equal(res.status_code, 201)
# Last node directly registered from self.project
registration = Node.load(public_project.node__registrations[-1])
assert_true(registration.is_registration)
assert_false(registration.is_public)
assert_true(registration.is_pending_embargo_for_existing_registration)
assert_is_not_none(registration.embargo)
for node in registration.get_descendants_recursive():
assert_true(node.is_registration)
assert_false(node.is_public)
示例5: TestSearchExceptions
class TestSearchExceptions(OsfTestCase):
"""
Verify that the correct exception is thrown when the connection is lost
"""
@classmethod
def setUpClass(cls):
logging.getLogger('website.project.model').setLevel(logging.CRITICAL)
super(TestSearchExceptions, cls).setUpClass()
if settings.SEARCH_ENGINE == 'elastic':
cls._es = search.search_engine.es
search.search_engine.es = None
@classmethod
def tearDownClass(cls):
super(TestSearchExceptions, cls).tearDownClass()
if settings.SEARCH_ENGINE == 'elastic':
search.search_engine.es = cls._es
def test_connection_error(self):
# Ensures that saving projects/users doesn't break as a result of connection errors
self.user = UserFactory(usename='Doug Bogie')
self.project = ProjectFactory(
title="Tom Sawyer",
creator=self.user,
is_public=True,
)
self.user.save()
self.project.save()
示例6: test_project_dashboard_shows_no_wiki_content_text
def test_project_dashboard_shows_no_wiki_content_text(self):
# Regression test for:
# https://github.com/CenterForOpenScience/openscienceframework.org/issues/1104
project = ProjectFactory(creator=self.user)
url = project.web_url_for('view_project')
res = self.app.get(url, auth=self.user.auth)
assert_in('No wiki content', res)
示例7: setUp
def setUp(self):
super(TestNodeTags, self).setUp()
self.user = AuthUserFactory()
self.admin = AuthUserFactory()
self.user_two = AuthUserFactory()
self.read_only_contributor = AuthUserFactory()
self.public_project = ProjectFactory(title="Project One", is_public=True, creator=self.user)
self.public_project.add_contributor(
self.user, permissions=permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, save=True
)
self.private_project = ProjectFactory(title="Project Two", is_public=False, creator=self.user)
self.private_project.add_contributor(
self.user, permissions=permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, save=True
)
self.private_project.add_contributor(self.admin, permissions=permissions.CREATOR_PERMISSIONS, save=True)
self.public_url = "/{}nodes/{}/".format(API_BASE, self.public_project._id)
self.private_url = "/{}nodes/{}/".format(API_BASE, self.private_project._id)
self.one_new_tag_json = {
"data": {"id": self.public_project._id, "type": "nodes", "attributes": {"tags": ["new-tag"]}}
}
self.private_payload = {
"data": {"id": self.private_project._id, "type": "nodes", "attributes": {"tags": ["new-tag"]}}
}
示例8: setUp
def setUp(self):
self.user = UserFactory()
self.public_node = ProjectFactory(creator=self.user, is_public=True)
self.public_node = ProjectFactory(creator=self.user, is_public=False)
self.request = RequestFactory().post('/fake_path')
self.view = SpamUserDeleteView()
self.view = setup_log_view(self.view, self.request, guid=self.user._id)
示例9: setUp
def setUp(self):
super(TestNodeLicense, self).setUp()
self.user = AuthUserFactory()
self.admin = AuthUserFactory()
self.user_two = AuthUserFactory()
self.read_only_contributor = AuthUserFactory()
self.public_project = ProjectFactory(title="Project One", is_public=True, creator=self.user)
self.public_project.add_contributor(self.user, permissions=permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, save=True)
self.private_project = ProjectFactory(title="Project Two", is_public=False, creator=self.user)
self.private_project.add_contributor(self.user, permissions=permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, save=True)
self.private_project.add_contributor(self.admin, permissions=permissions.CREATOR_PERMISSIONS, save=True)
self.public_url = '/{}nodes/{}/'.format(API_BASE, self.public_project._id)
self.private_url = '/{}nodes/{}/'.format(API_BASE, self.private_project._id)
ensure_licenses()
self.LICENSE_NAME = 'MIT License'
self.node_license = NodeLicense.find_one(
Q('name', 'eq', self.LICENSE_NAME)
)
self.YEAR = '2105'
self.COPYRIGHT_HOLDERS = ['Foo', 'Bar']
self.public_project.node_license = NodeLicenseRecordFactory(
node_license=self.node_license,
year=self.YEAR,
copyright_holders=self.COPYRIGHT_HOLDERS
)
self.public_project.save()
self.private_project.node_license = NodeLicenseRecordFactory(
node_license=self.node_license,
year=self.YEAR,
copyright_holders=self.COPYRIGHT_HOLDERS
)
self.private_project.save()
示例10: test_migration
def test_migration(self):
BoxUserSettings.remove()
user = UserFactory()
node = ProjectFactory(creator=user)
account = BoxAccountFactory()
user.external_accounts = [account]
user.add_addon('box', auth=Auth(user))
user_addon = user.get_addon('box')
user_addon.save()
node.add_addon('box', auth=Auth(user))
node_addon = node.get_addon('box')
node_addon.foreign_user_settings = user_addon
node_addon.folder_id = 'abcdef0'
node_addon.folder_path = '/'
node_addon.folder_name = '/ (Full Box)'
node_addon.save()
assert_equal(node_addon.external_account, None)
assert_equal(node_addon.folder_id, 'abcdef0')
do_migration()
node_addon.reload()
assert_equal(node_addon.external_account, account)
assert_equal(node_addon.folder_id, 'abcdef0')
assert_equal(node_addon.folder_path, '/')
assert_equal(node_addon.folder_name, '/ (Full Box)')
示例11: TestDisableSpamUser
class TestDisableSpamUser(AdminTestCase):
def setUp(self):
self.user = UserFactory()
self.public_node = ProjectFactory(creator=self.user, is_public=True)
self.public_node = ProjectFactory(creator=self.user, is_public=False)
self.request = RequestFactory().post('/fake_path')
self.view = SpamUserDeleteView()
self.view = setup_log_view(self.view, self.request, guid=self.user._id)
def test_get_object(self):
obj = self.view.get_object()
nt.assert_is_instance(obj, User)
def test_get_context(self):
res = self.view.get_context_data(object=self.user)
nt.assert_in('guid', res)
nt.assert_equal(res.get('guid'), self.user._id)
def test_disable_spam_user(self):
settings.ENABLE_EMAIL_SUBSCRIPTIONS = False
count = OSFLogEntry.objects.count()
self.view.delete(self.request)
self.user.reload()
self.public_node.reload()
nt.assert_true(self.user.is_disabled)
nt.assert_false(self.public_node.is_public)
nt.assert_equal(OSFLogEntry.objects.count(), count + 3)
def test_no_user(self):
view = setup_view(UserDeleteView(), self.request, guid='meh')
with nt.assert_raises(Http404):
view.delete(self.request)
示例12: TestNodeDeleteView
class TestNodeDeleteView(AdminTestCase):
def setUp(self):
super(TestNodeDeleteView, self).setUp()
self.node = ProjectFactory()
self.request = RequestFactory().post('/fake_path')
self.view = NodeDeleteView()
self.view = setup_log_view(self.view, self.request,
guid=self.node._id)
def test_get_object(self):
obj = self.view.get_object()
nt.assert_is_instance(obj, Node)
def test_get_context(self):
res = self.view.get_context_data(object=self.node)
nt.assert_in('guid', res)
nt.assert_equal(res.get('guid'), self.node._id)
def test_remove_node(self):
count = OSFLogEntry.objects.count()
self.view.delete(self.request)
self.node.reload()
nt.assert_true(self.node.is_deleted)
nt.assert_equal(OSFLogEntry.objects.count(), count + 1)
def test_restore_node(self):
self.view.delete(self.request)
nt.assert_true(self.node.is_deleted)
count = OSFLogEntry.objects.count()
self.view.delete(self.request)
self.node.reload()
nt.assert_false(self.node.is_deleted)
nt.assert_equal(OSFLogEntry.objects.count(), count + 1)
示例13: TestCreateBucket
class TestCreateBucket(OsfTestCase):
def setUp(self):
super(TestCreateBucket, self).setUp()
self.user = AuthUserFactory()
self.consolidated_auth = Auth(user=self.user)
self.auth = ('test', self.user.api_keys[0]._primary_key)
self.project = ProjectFactory(creator=self.user)
self.project.add_addon('s3', auth=self.consolidated_auth)
self.project.creator.add_addon('s3')
self.user_settings = self.user.get_addon('s3')
self.user_settings.access_key = 'We-Will-Rock-You'
self.user_settings.secret_key = 'Idontknowanyqueensongs'
self.user_settings.save()
self.node_settings = self.project.get_addon('s3')
self.node_settings.bucket = 'Sheer-Heart-Attack'
self.node_settings.user_settings = self.project.creator.get_addon('s3')
self.node_settings.save()
def test_bad_names(self):
assert_false(validate_bucket_name('bogus naMe'))
assert_false(validate_bucket_name(''))
assert_false(validate_bucket_name('no'))
assert_false(validate_bucket_name('.cantstartwithp'))
assert_false(validate_bucket_name('or.endwith.'))
assert_false(validate_bucket_name('..nodoubles'))
assert_false(validate_bucket_name('no_unders_in'))
def test_names(self):
assert_true(validate_bucket_name('imagoodname'))
assert_true(validate_bucket_name('still.passing'))
assert_true(validate_bucket_name('can-have-dashes'))
assert_true(validate_bucket_name('kinda.name.spaced'))
@mock.patch('website.addons.s3.views.crud.create_bucket')
@mock.patch('website.addons.s3.utils.get_bucket_drop_down')
def test_create_bucket_pass(self, mock_make, mock_dropdown):
mock_make.return_value = True
mock_dropdown.return_value = ['mybucket']
url = self.project.api_url_for('create_new_bucket')
ret = self.app.post_json(url, {'bucket_name': 'doesntevenmatter'}, auth=self.user.auth)
assert_equals(ret.status_int, http.OK)
@mock.patch('website.addons.s3.views.crud.create_bucket')
def test_create_bucket_fail(self, mock_make):
error = S3ResponseError(418, 'because Im a test')
error.message = 'This should work'
mock_make.side_effect = error
url = "/api/v1/project/{0}/s3/newbucket/".format(self.project._id)
ret = self.app.post_json(url, {'bucket_name': 'doesntevenmatter'}, auth=self.user.auth, expect_errors=True)
assert_equals(ret.body, '{"message": "This should work", "title": "Problem connecting to S3"}')
示例14: setUp
def setUp(self):
super(TestRegistrationFiltering, self).setUp()
self.user_one = AuthUserFactory()
self.user_two = AuthUserFactory()
self.project_one = ProjectFactory(title="Project One", description='Two', is_public=True, creator=self.user_one, category='hypothesis')
self.project_two = ProjectFactory(title="Project Two", description="One Three", is_public=True, creator=self.user_one)
self.project_three = ProjectFactory(title="Three", is_public=True, creator=self.user_two)
self.private_project_user_one = ProjectFactory(title="Private Project User One",
is_public=False,
creator=self.user_one)
self.private_project_user_two = ProjectFactory(title="Private Project User Two",
is_public=False,
creator=self.user_two)
self.project_one.add_tag('tag1', Auth(self.project_one.creator), save=False)
self.project_one.add_tag('tag2', Auth(self.project_one.creator), save=False)
self.project_one.save()
self.project_two.add_tag('tag1', Auth(self.project_two.creator), save=True)
self.project_two.save()
self.project_one_reg = RegistrationFactory(creator=self.user_one, project=self.project_one, is_public=True)
self.project_two_reg = RegistrationFactory(creator=self.user_one, project=self.project_two, is_public=True)
self.project_three_reg = RegistrationFactory(creator=self.user_two, project=self.project_three, is_public=True)
self.private_project_user_one_reg = RegistrationFactory(creator=self.user_one, project=self.private_project_user_one, is_public=False)
self.private_project_user_two_reg = RegistrationFactory(creator=self.user_two, project=self.private_project_user_two, is_public=False)
self.folder = FolderFactory()
self.dashboard = DashboardFactory()
self.url = "/{}registrations/".format(API_BASE)
示例15: test__initiate_embargo_adds_admins_on_child_nodes
def test__initiate_embargo_adds_admins_on_child_nodes(self):
project_admin = UserFactory()
project_non_admin = UserFactory()
child_admin = UserFactory()
child_non_admin = UserFactory()
grandchild_admin = UserFactory()
project = ProjectFactory(creator=project_admin)
project.add_contributor(project_non_admin, auth=Auth(project.creator), save=True)
child = NodeFactory(creator=child_admin, parent=project)
child.add_contributor(child_non_admin, auth=Auth(project.creator), save=True)
grandchild = NodeFactory(creator=grandchild_admin, parent=child) # noqa
embargo = project._initiate_embargo(
project.creator,
self.valid_embargo_end_date,
for_existing_registration=True
)
assert_in(project_admin._id, embargo.approval_state)
assert_in(child_admin._id, embargo.approval_state)
assert_in(grandchild_admin._id, embargo.approval_state)
assert_not_in(project_non_admin._id, embargo.approval_state)
assert_not_in(child_non_admin._id, embargo.approval_state)