本文整理匯總了Python中ckan.tests.factories.User方法的典型用法代碼示例。如果您正苦於以下問題:Python factories.User方法的具體用法?Python factories.User怎麽用?Python factories.User使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ckan.tests.factories
的用法示例。
在下文中一共展示了factories.User方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_class
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def setup_class(cls):
wsgiapp = middleware.make_app(config['global_conf'], **config)
cls.app = paste.fixture.TestApp(wsgiapp)
if not tests.is_datastore_supported():
raise nose.SkipTest("Datastore not supported")
p.load('datastore')
p.load('datapusher')
p.load('test_datapusher_plugin')
resource = factories.Resource(url_type='datastore')
cls.dataset = factories.Dataset(resources=[resource])
cls.sysadmin_user = factories.User(name='testsysadmin', sysadmin=True)
cls.normal_user = factories.User(name='annafan')
engine = db._get_engine(
{'connection_url': config['ckan.datastore.write_url']})
cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
示例2: test_run_auth_user
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_run_auth_user(self):
user = factories.User()
org = factories.Organization(
users=[{'name': user['name'], 'capacity': 'editor'}])
dataset = factories.Dataset(
owner_org=org['id'], resources=[factories.Resource()])
context = {
'user': user['name'],
'model': model
}
assert_equals(call_auth('resource_validation_run', context=context,
resource_id=dataset['resources'][0]['id']),
True)
示例3: test_delete_auth_user
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_delete_auth_user(self):
user = factories.User()
org = factories.Organization(
users=[{'name': user['name'], 'capacity': 'editor'}])
dataset = factories.Dataset(
owner_org=org['id'], resources=[factories.Resource()])
context = {
'user': user['name'],
'model': model
}
assert_equals(call_auth('resource_validation_delete', context=context,
resource_id=dataset['resources'][0]['id']),
True)
示例4: test_show_anon_public_dataset
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_show_anon_public_dataset(self):
user = factories.User()
org = factories.Organization()
dataset = factories.Dataset(
owner_org=org['id'], resources=[factories.Resource()],
private=False)
context = {
'user': user['name'],
'model': model
}
assert_equals(call_auth('resource_validation_show', context=context,
resource_id=dataset['resources'][0]['id']),
True)
示例5: test_spatial_extra_bad_json
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_spatial_extra_bad_json(self):
app = self._get_test_app()
user = factories.User()
env = {'REMOTE_USER': user['name'].encode('ascii')}
dataset = factories.Dataset(user=user)
offset = url_for(controller='package', action='edit', id=dataset['id'])
res = app.get(offset, extra_environ=env)
form = res.forms[1]
form['extras__0__key'] = u'spatial'
form['extras__0__value'] = u'{"Type":Bad Json]'
res = helpers.webtest_submit(form, extra_environ=env, name='save')
assert 'Error' in res, res
assert 'Spatial' in res
assert 'Error decoding JSON object' in res
示例6: test_spatial_extra_bad_geojson
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_spatial_extra_bad_geojson(self):
app = self._get_test_app()
user = factories.User()
env = {'REMOTE_USER': user['name'].encode('ascii')}
dataset = factories.Dataset(user=user)
offset = url_for(controller='package', action='edit', id=dataset['id'])
res = app.get(offset, extra_environ=env)
form = res.forms[1]
form['extras__0__key'] = u'spatial'
form['extras__0__value'] = u'{"Type":"Bad_GeoJSON","a":2}'
res = helpers.webtest_submit(form, extra_environ=env, name='save')
assert 'Error' in res, res
assert 'Spatial' in res
assert 'Error creating geometry' in res
示例7: test_resource_delete_editor
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_resource_delete_editor(self):
'''Normally organization admins can delete resources
Our plugin prevents this by blocking delete organization.
Ensure the delete button is not displayed (as only resource delete
is checked for showing this)
'''
user = factories.User()
owner_org = factories.Organization(
users=[{'name': user['id'], 'capacity': 'admin'}]
)
dataset = factories.Dataset(owner_org=owner_org['id'])
resource = factories.Resource(package_id=dataset['id'])
with assert_raises(logic.NotAuthorized) as e:
logic.check_access('resource_delete', {'user': user['name']}, {'id': resource['id']})
assert_equal(e.exception.message, 'User %s not authorized to delete resource %s' % (user['name'], resource['id']))
示例8: _make_curators_group
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [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)
示例9: test_group_create_with_no_curators_group
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_group_create_with_no_curators_group(self):
'''Test that group_create returns a 404 when there's no curators group.
With this version of the plugin group_create returns a spurious 404
when a user _is_ logged-in but the site has no curators group.
'''
assert 'curators' not in tests.call_action_api(self.app, 'group_list')
user = factories.User()
response = tests.call_action_api(self.app, 'group_create',
name='test_group',
apikey=user['apikey'], status=404)
assert response == {'__type': 'Not Found Error',
'message': 'Not found'}
示例10: test_reset_password_custom_body
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_reset_password_custom_body(self):
user = factories.User()
user_obj = model.User.by_name(user['name'])
mailer.send_reset_link(user_obj)
# check it went to the mock smtp server
msgs = self.get_smtp_messages()
assert_equal(len(msgs), 1)
msg = msgs[0]
extra_vars = {
'reset_link': mailer.get_reset_link(user_obj)
}
expected = render_jinja2('emails/reset_password.txt',
extra_vars)
body = self.get_email_body(msg[3])
assert_equal(expected, body)
assert_in('**test**', body)
示例11: test_invite_user_custom_subject
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_invite_user_custom_subject(self):
user = factories.User()
user_obj = model.User.by_name(user['name'])
mailer.send_invite(user_obj)
# check it went to the mock smtp server
msgs = self.get_smtp_messages()
assert_equal(len(msgs), 1)
msg = msgs[0]
extra_vars = {
'site_title': config.get('ckan.site_title'),
}
expected = render_jinja2('emails/invite_user_subject.txt',
extra_vars)
expected = expected.split('\n')[0]
subject = self.get_email_subject(msg[3])
assert_equal(expected, subject)
assert_in('**test**', subject)
示例12: test_invite_user_custom_body
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_invite_user_custom_body(self):
user = factories.User()
user_obj = model.User.by_name(user['name'])
mailer.send_invite(user_obj)
# check it went to the mock smtp server
msgs = self.get_smtp_messages()
assert_equal(len(msgs), 1)
msg = msgs[0]
extra_vars = {
'reset_link': mailer.get_reset_link(user_obj),
'user_name': user['name'],
'site_title': config.get('ckan.site_title'),
}
expected = render_jinja2('emails/invite_user.txt',
extra_vars)
body = self.get_email_body(msg[3])
assert_equal(expected, body)
assert_in('**test**', body)
示例13: test_send_reset_email
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_send_reset_email(self):
user = factories.User()
user_obj = model.User.by_name(user['name'])
mailer.send_reset_link(user_obj)
# check it went to the mock smtp server
msgs = self.get_smtp_messages()
assert_equal(len(msgs), 1)
msg = msgs[0]
assert_equal(msg[1], config['smtp.mail_from'])
assert_equal(msg[2], [user['email']])
assert 'Reset' in msg[3], msg[3]
test_msg = mailer.get_reset_link_body(user_obj)
expected_body = self.mime_encode(test_msg,
user['name'])
assert_in(expected_body, msg[3])
示例14: test_send_invite_email
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_send_invite_email(self):
user = factories.User()
user_obj = model.User.by_name(user['name'])
assert user_obj.reset_key is None, user_obj
# send email
mailer.send_invite(user_obj)
# check it went to the mock smtp server
msgs = self.get_smtp_messages()
assert_equal(len(msgs), 1)
msg = msgs[0]
assert_equal(msg[1], config['smtp.mail_from'])
assert_equal(msg[2], [user['email']])
test_msg = mailer.get_invite_body(user_obj)
expected_body = self.mime_encode(test_msg,
user['name'])
assert_in(expected_body, msg[3])
assert user_obj.reset_key is not None, user
示例15: test_send_invite_email_with_org
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import User [as 別名]
def test_send_invite_email_with_org(self):
user = factories.User()
user_obj = model.User.by_name(user['name'])
org = factories.Organization()
role = 'admin'
# send email
mailer.send_invite(user_obj, group_dict=org, role=role)
# check it went to the mock smtp server
msgs = self.get_smtp_messages()
msg = msgs[0]
body = self.get_email_body(msg[3])
assert_in(org['title'], body)
assert_in(h.roles_translated()[role], body)