本文整理匯總了Python中ckan.tests.factories.Sysadmin方法的典型用法代碼示例。如果您正苦於以下問題:Python factories.Sysadmin方法的具體用法?Python factories.Sysadmin怎麽用?Python factories.Sysadmin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ckan.tests.factories
的用法示例。
在下文中一共展示了factories.Sysadmin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_dataset_doi_admin_sysadmin
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_dataset_doi_admin_sysadmin(self):
model.repo.rebuild_db()
dataset = factories.Dataset(author='test author')
sysadmin = factories.Sysadmin()
env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
url = url_for(
controller='ckanext.ands.controller:DatasetDoiController', action='dataset_doi_admin',
id=dataset['name'])
mock_response = Mock(content=json.dumps(dict(response=dict(responsecode='MT001', doi='testdoi'))))
mock_post = Mock(return_value=mock_response)
with patch.object(requests, 'post', new=mock_post):
response = self.app.post(url, {'xml': 'test'}, extra_environ=env)
# Don't bother checking the mocks, other tests do this
response = response.follow(extra_environ=env)
# Shouldn't appear as already created
response.mustcontain(no='Approve DOI')
response.mustcontain(no='Request DOI')
response.mustcontain('Cite this as')
示例2: test_dataset_doi_admin_sysadmin_verify_xml
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_dataset_doi_admin_sysadmin_verify_xml(self):
model.repo.rebuild_db()
dataset = factories.Dataset(author='test author')
sysadmin = factories.Sysadmin()
env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
url = url_for(
controller='ckanext.ands.controller:DatasetDoiController', action='dataset_doi_admin',
id=dataset['name'])
mock_response = Mock(content=json.dumps(dict(response=dict(responsecode='MT001', doi='testdoi'))))
mock_post = Mock(return_value=mock_response)
response = self.app.get(url, extra_environ=env)
form = response.forms['dataset-doi']
assert_equal(sorted(form.fields.keys()), ['save', 'xml'])
with patch.object(requests, 'post', new=mock_post):
response = form.submit('submit', extra_environ=env)
# Don't bother checking the mocks, other tests do this
response = response.follow(extra_environ=env)
# Shouldn't appear as already created
response.mustcontain(no='Approve DOI')
response.mustcontain(no='Request DOI')
response.mustcontain('Cite this as')
示例3: test_resource_controller_plugin_create
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_resource_controller_plugin_create(self):
user = factories.Sysadmin()
package = factories.Dataset(user=user)
# Set up the plugin
ckan.plugins.load('example_iresourcecontroller')
plugin = ckan.plugins.get_plugin('example_iresourcecontroller')
res = helpers.call_action('resource_create',
package_id=package['id'],
name='test-resource',
url='http://resource.create/',
apikey=user['apikey'])
assert plugin.counter['before_create'] == 1, plugin.counter
assert plugin.counter['after_create'] == 1, plugin.counter
assert plugin.counter['before_update'] == 0, plugin.counter
assert plugin.counter['after_update'] == 0, plugin.counter
assert plugin.counter['before_delete'] == 0, plugin.counter
assert plugin.counter['after_delete'] == 0, plugin.counter
示例4: test_resource_controller_plugin_update
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_resource_controller_plugin_update(self):
user = factories.Sysadmin()
resource = factories.Resource(user=user)
# Set up the plugin here because we don't want the resource creation
# to affect it (because we will only check for changes to update)
ckan.plugins.load('example_iresourcecontroller')
plugin = ckan.plugins.get_plugin('example_iresourcecontroller')
res = helpers.call_action('resource_update',
id=resource['id'],
url='http://resource.updated/',
apikey=user['apikey'])
assert plugin.counter['before_create'] == 0, plugin.counter
assert plugin.counter['after_create'] == 0, plugin.counter
assert plugin.counter['before_update'] == 1, plugin.counter
assert plugin.counter['after_update'] == 1, plugin.counter
assert plugin.counter['before_delete'] == 0, plugin.counter
assert plugin.counter['after_delete'] == 0, plugin.counter
示例5: test_resource_controller_plugin_delete
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_resource_controller_plugin_delete(self):
user = factories.Sysadmin()
resource = factories.Resource(user=user)
# Set up the plugin here because we don't want the resource creation
# to affect it (because we will only check for changes to delete)
ckan.plugins.load('example_iresourcecontroller')
plugin = ckan.plugins.get_plugin('example_iresourcecontroller')
res = helpers.call_action('resource_delete',
id=resource['id'],
apikey=user['apikey'])
assert plugin.counter['before_create'] == 0, plugin.counter
assert plugin.counter['after_create'] == 0, plugin.counter
assert plugin.counter['before_update'] == 0, plugin.counter
assert plugin.counter['after_update'] == 0, plugin.counter
assert plugin.counter['before_delete'] == 1, plugin.counter
assert plugin.counter['after_delete'] == 1, plugin.counter
示例6: test_resource_controller_plugin_show
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_resource_controller_plugin_show(self):
"""
Before show gets called by the other methods but we test it
separately here and make sure that it doesn't call the other
methods.
"""
user = factories.Sysadmin()
package = factories.Dataset(user=user)
resource = factories.Resource(user=user, package_id=package['id'])
# Set up the plugin here because we don't want the resource creation
# to affect it (because we will only check for changes to delete)
ckan.plugins.load('example_iresourcecontroller')
plugin = ckan.plugins.get_plugin('example_iresourcecontroller')
res = helpers.call_action('package_show',
name_or_id=package['id'])
assert plugin.counter['before_create'] == 0, plugin.counter
assert plugin.counter['after_create'] == 0, plugin.counter
assert plugin.counter['before_update'] == 0, plugin.counter
assert plugin.counter['after_update'] == 0, plugin.counter
assert plugin.counter['before_delete'] == 0, plugin.counter
assert plugin.counter['after_delete'] == 0, plugin.counter
assert plugin.counter['before_show'] == 1, plugin.counter
示例7: _make_curators_group
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def _make_curators_group(self):
'''This is a helper method for test methods to call when they want
the 'curators' group to be created.
'''
sysadmin = factories.Sysadmin()
# Create a user who will *not* be a member of the curators group.
noncurator = factories.User()
# Create a user who will be a member of the curators group.
curator = factories.User()
# Create the curators group, with the 'curator' user as a member.
users = [{'name': curator['name'], 'capacity': 'member'}]
curators_group = tests.call_action_api(self.app, 'group_create',
apikey=sysadmin['apikey'],
name='curators',
users=users)
return (noncurator, curator, curators_group)
示例8: test_user_show_include_datasets_includes_draft_sysadmin
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_user_show_include_datasets_includes_draft_sysadmin(self):
# sysadmin should see the draft and private datasets
user = factories.User()
sysadmin = factories.Sysadmin()
org = factories.Organization(user=user)
factories.Dataset(user=user)
dataset_deleted = factories.Dataset(user=user, state='deleted')
factories.Dataset(user=user, state='draft')
factories.Dataset(user=user, private=True, owner_org=org['name'])
got_user = helpers.call_action('user_show',
context={'user': sysadmin['name']},
include_datasets=True,
id=user['id'])
eq(len(got_user['datasets']), 3)
datasets_got = set([user_['name'] for user_ in got_user['datasets']])
assert dataset_deleted['name'] not in datasets_got
eq(got_user['number_created_packages'], 3)
示例9: test_package_search_with_include_drafts_option_includes_drafts_for_sysadmin
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_package_search_with_include_drafts_option_includes_drafts_for_sysadmin(self):
'''
A sysadmin can use the include_drafts option to get draft datasets for
all users.
'''
user = factories.User()
other_user = factories.User()
sysadmin = factories.Sysadmin()
org = factories.Organization(user=user)
dataset = factories.Dataset(user=user)
factories.Dataset(user=user, state='deleted')
draft_dataset = factories.Dataset(user=user, state='draft')
other_draft_dataset = factories.Dataset(user=other_user, state='draft')
factories.Dataset(user=user, private=True, owner_org=org['name'])
results = helpers.call_action('package_search', include_drafts=True,
context={'user': sysadmin['name']})['results']
eq(len(results), 3)
names = [r['name'] for r in results]
nose.tools.assert_true(draft_dataset['name'] in names)
nose.tools.assert_true(other_draft_dataset['name'] in names)
nose.tools.assert_true(dataset['name'] in names)
示例10: test_package_search_with_fq_for_create_user_id_will_include_drafts_for_other_users_for_sysadmin
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_package_search_with_fq_for_create_user_id_will_include_drafts_for_other_users_for_sysadmin(self):
'''
Sysadmins can use fq to get draft datasets for another user.
'''
user = factories.User()
sysadmin = factories.Sysadmin()
other_user = factories.User()
org = factories.Organization(user=user)
dataset = factories.Dataset(user=user, name="dataset")
factories.Dataset(user=other_user, name="other-dataset")
factories.Dataset(user=user, state='deleted', name="deleted-dataset")
draft_dataset = factories.Dataset(user=user, state='draft', name="draft-dataset")
factories.Dataset(user=other_user, state='draft', name="other-draft-dataset")
factories.Dataset(user=user, private=True, owner_org=org['name'], name="private-dataset")
fq = "(creator_user_id:{0} AND +state:draft)".format(user['id'])
results = helpers.call_action('package_search', fq=fq,
context={'user': sysadmin['name']})['results']
names = [r['name'] for r in results]
eq(len(results), 1)
nose.tools.assert_true(dataset['name'] not in names)
nose.tools.assert_true(draft_dataset['name'] in names)
示例11: test_dataset_delete_marks_membership_of_group_as_deleted
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_dataset_delete_marks_membership_of_group_as_deleted(self):
sysadmin = factories.Sysadmin()
group = factories.Group()
dataset = factories.Dataset(groups=[{'name': group['name']}])
context = {'user': sysadmin['name']}
group_members = helpers.call_action('member_list', context,
id=group['id'],
object_type='package')
eq(len(group_members), 1)
eq(group_members[0][0], dataset['id'])
eq(group_members[0][1], 'package')
helpers.call_action('package_delete', context, id=dataset['id'])
group_members = helpers.call_action('member_list', context,
id=group['id'],
object_type='package')
eq(len(group_members), 0)
示例12: test_dataset_delete_marks_membership_of_org_as_deleted
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_dataset_delete_marks_membership_of_org_as_deleted(self):
sysadmin = factories.Sysadmin()
org = factories.Organization()
dataset = factories.Dataset(owner_org=org['id'])
context = {'user': sysadmin['name']}
org_members = helpers.call_action('member_list', context,
id=org['id'],
object_type='package')
eq(len(org_members), 1)
eq(org_members[0][0], dataset['id'])
eq(org_members[0][1], 'package')
helpers.call_action('package_delete', context, id=dataset['id'])
org_members = helpers.call_action('member_list', context,
id=org['id'],
object_type='package')
eq(len(org_members), 0)
示例13: test_smtp_error_returns_error_message
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_smtp_error_returns_error_message(self):
sysadmin = factories.Sysadmin()
group = factories.Group()
context = {
'user': sysadmin['name']
}
params = {
'email': '[email protected]',
'group_id': group['id'],
'role': 'editor'
}
assert_raises(logic.ValidationError, helpers.call_action,
'user_invite', context, **params)
# Check that the pending user was deleted
user = model.Session.query(model.User).filter(
model.User.name.like('example-invited-user%')).all()
assert_equals(user[0].state, 'deleted')
示例14: test_user_follower_list
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_user_follower_list(self):
'''Following users appear on followers list page.'''
app = self._get_test_app()
user_one = factories.Sysadmin()
user_two = factories.User()
env = {'REMOTE_USER': user_one['name'].encode('ascii')}
follow_url = url_for(controller='user',
action='follow',
id=user_two['id'])
app.post(follow_url, extra_environ=env, status=302)
followers_url = url_for(controller='user', action='followers',
id=user_two['id'])
# Only sysadmins can view the followers list pages
followers_response = app.get(followers_url, extra_environ=env,
status=200)
assert_true(user_one['display_name'] in followers_response)
示例15: test_user_page_sysadmin_user
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Sysadmin [as 別名]
def test_user_page_sysadmin_user(self):
'''Sysadmin can search for users by email.'''
app = self._get_test_app()
sysadmin = factories.Sysadmin()
factories.User(fullname='User One', email='[email protected]')
factories.User(fullname='Person Two')
factories.User(fullname='Person Three')
env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
user_url = url_for(controller='user', action='index')
user_response = app.get(user_url, status=200, extra_environ=env)
search_form = user_response.forms['user-search-form']
search_form['q'] = '[email protected]'
search_response = webtest_submit(search_form, status=200,
extra_environ=env)
search_response_html = BeautifulSoup(search_response.body)
user_list = search_response_html.select('ul.user-list li')
assert_equal(len(user_list), 1)
assert_equal(user_list[0].text.strip(), 'User One')