本文整理匯總了Python中ckan.tests.factories.Resource方法的典型用法代碼示例。如果您正苦於以下問題:Python factories.Resource方法的具體用法?Python factories.Resource怎麽用?Python factories.Resource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ckan.tests.factories
的用法示例。
在下文中一共展示了factories.Resource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_resource_validation_creates_validation_object
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_resource_validation_creates_validation_object(
self, mock_enqueue_job):
resource = factories.Resource(format='csv')
call_action('resource_validation_run', resource_id=resource['id'])
validation = Session.query(Validation).filter(
Validation.resource_id == resource['id']).one()
assert_equals(validation.resource_id, resource['id'])
assert_equals(validation.status, 'created')
assert validation.created
assert_equals(validation.finished, None)
assert_equals(validation.report, None)
assert_equals(validation.error, None)
示例2: test_show_anon_private_dataset
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_show_anon_private_dataset(self):
user = factories.User()
org = factories.Organization()
dataset = factories.Dataset(
owner_org=org['id'], resources=[factories.Resource()],
private=True)
context = {
'user': user['name'],
'model': model
}
assert_raises(t.NotAuthorized,
call_auth, 'resource_validation_run', context=context,
resource_id=dataset['resources'][0]['id'])
示例3: setup_class
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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))
示例4: test_resource_validation_delete_removes_object
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_resource_validation_delete_removes_object(self):
resource = factories.Resource(format='csv')
timestamp = datetime.datetime.utcnow()
validation = Validation(
resource_id=resource['id'],
created=timestamp,
finished=timestamp,
status='valid',
report={'some': 'report'},
error={'some': 'error'})
Session.add(validation)
Session.commit()
count_before = Session.query(Validation).filter(
Validation.resource_id == resource['id']).count()
assert_equals(count_before, 1)
call_action('resource_validation_delete', resource_id=resource['id'])
count_after = Session.query(Validation).filter(
Validation.resource_id == resource['id']).count()
assert_equals(count_after, 0)
示例5: test_run_auth_user
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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)
示例6: test_delete_auth_user
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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)
示例7: test_show_anon_public_dataset
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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)
示例8: test_job_run_valid_stores_status_in_resource
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_job_run_valid_stores_status_in_resource(self, mock_validate):
resource = factories.Resource(
url='http://example.com/file.csv', format='csv')
run_validation_job(resource)
validation = Session.query(Validation).filter(
Validation.resource_id == resource['id']).one()
updated_resource = call_action('resource_show', id=resource['id'])
assert_equals(updated_resource['validation_status'], validation.status)
assert_equals(
updated_resource['validation_timestamp'],
validation.finished.isoformat())
示例9: test_validation_run_on_schema_change
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_validation_run_on_schema_change(self, mock_enqueue):
resource = factories.Resource(format='CSV', schema={
'fields': [
{'name': 'code'}
]
})
resource['schema'] = {
'fields': [
{'name': 'code'},
{'name': 'date'}
]
}
call_action('resource_update', {}, **resource)
assert_equals(mock_enqueue.call_count, 1)
assert_equals(mock_enqueue.call_args[0][0], run_validation_job)
assert_equals(mock_enqueue.call_args[0][1][0]['id'], resource['id'])
示例10: test_resource_controller_plugin_update
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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
示例11: test_resource_controller_plugin_delete
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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
示例12: test_resource_controller_plugin_show
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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
示例13: test_view_shown_on_resource_page
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_view_shown_on_resource_page(self):
app = self._get_test_app()
dataset = factories.Dataset()
resource = factories.Resource(package_id=dataset['id'],
url='http://some.website.html')
resource_view = factories.ResourceView(
resource_id=resource['id'],
view_type='webpage_view',
page_url='http://some.other.website.html',)
url = url_for(controller='package', action='resource_read',
id=dataset['name'], resource_id=resource['id'])
response = app.get(url)
assert_true(resource_view['page_url'] in response)
示例14: test_resource_delete_editor
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [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']))
示例15: test_view_shown_on_resource_page_with_image_url
# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Resource [as 別名]
def test_view_shown_on_resource_page_with_image_url(self):
app = self._get_test_app()
dataset = factories.Dataset()
resource = factories.Resource(package_id=dataset['id'],
format='png')
resource_view = factories.ResourceView(
resource_id=resource['id'],
image_url='http://some.image.png')
url = url_for(controller='package', action='resource_read',
id=dataset['name'], resource_id=resource['id'])
response = app.get(url)
assert_true(resource_view['image_url'] in response)