本文整理汇总了Python中openspending.model.Dataset.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.by_name方法的具体用法?Python Dataset.by_name怎么用?Python Dataset.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.Dataset
的用法示例。
在下文中一共展示了Dataset.by_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_views_update
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_views_update(self):
cra = Dataset.by_name('cra')
views = cra.data['views']
views[0]['label'] = 'Banana'
response = self.app.post(url(controller='editor',
action='views_update', dataset='cra'),
params={'views': json.dumps(views)},
extra_environ={'REMOTE_USER': 'test'},
expect_errors=True)
assert '200' in response.status, response.status
cra = Dataset.by_name('cra')
assert 'Banana' in repr(cra.data['views'])
示例2: test_retract
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_retract(self):
cra = Dataset.by_name('cra')
assert cra.private is False, cra.private
response = self.app.post(url(controller='editor',
action='retract', dataset='cra'),
extra_environ={'REMOTE_USER': 'test'})
cra = Dataset.by_name('cra')
assert cra.private is True, cra.private
response = self.app.post(url(controller='editor',
action='retract', dataset='cra'),
extra_environ={'REMOTE_USER': 'test'},
expect_errors=True)
assert '400' in response.status, response.status
示例3: test_publish
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_publish(self):
cra = Dataset.by_name('cra')
cra.private = True
db.session.commit()
response = self.app.post(url(controller='editor',
action='publish', dataset='cra'),
extra_environ={'REMOTE_USER': 'test'})
cra = Dataset.by_name('cra')
assert cra.private is False, cra.private
response = self.app.post(url(controller='editor',
action='publish', dataset='cra'),
extra_environ={'REMOTE_USER': 'test'},
expect_errors=True)
assert '400' in response.status, response.status
示例4: remove_dataset
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def remove_dataset(dataset_name):
log.warn("Dropping dataset '%s'", dataset_name)
from openspending.model import Dataset, meta as db
dataset = Dataset.by_name(dataset_name)
dataset.drop()
db.session.delete(dataset)
db.session.commit()
示例5: archive_one
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def archive_one(dataset_name, archive_dir):
"""
Find the dataset, create the archive directory and start archiving
"""
# Find the dataset
dataset = Dataset.by_name(dataset_name)
# If no dataset found, exit with error message
if dataset is None:
exit_with_error("Dataset not found. Unable to archive it.")
# If the archive_dir exists we have to ask the user if we should overwrite
if os.path.exists(archive_dir):
# If user doesn't want to write over it we exit
if not get_confirmation("%s exists. Do you want to overwrite?"
% archive_dir):
sys.exit(0)
# If the archive dir is a file we don't do anything
if os.path.isfile(archive_dir):
exit_with_error("Cannot overwrite a file (need a directory).")
# If the archive_dir doesn't exist we create it
else:
try:
os.makedirs(archive_dir)
except OSError:
# If we couldn't create it, we exit with an error message
exit_with_error("Couldn't create archive directory.")
# Archive the model (dataset metadata)
archive_model(dataset, archive_dir)
# Archive the visualisations
archive_visualisations(dataset, archive_dir)
# Download all sources
update(os.path.join(archive_dir, 'sources'), dataset)
示例6: test_new_wrong_user
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_new_wrong_user(self):
# First we add a Dataset with user 'test_new'
user = Account.by_name('test_new')
assert user.api_key == 'd0610659-627b-4403-8b7f-6e2820ebc95d'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization':apikey_header})
#Dataset.by_name('openspending-example').private = False
assert "200" in response.status
assert Dataset.by_name('openspending-example')
# After that we try to update the Dataset with user 'test_new2'
user = Account.by_name('test_new2')
assert user.api_key == 'c011c340-8dad-419c-8138-1c6ded86ead5'
u = url(controller='api/version2', action='create')
params = {
'metadata':
'https://dl.dropbox.com/u/3250791/sample-openspending-model.json',
'csv_file':
'http://mk.ucant.org/info/data/sample-openspending-dataset.csv'
}
apikey_header = 'apikey {0}'.format(user.api_key)
response = self.app.post(u, params, {'Authorization':apikey_header},
expect_errors=True)
assert '403' in response.status
示例7: permissions
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def permissions(self):
"""
Check a user's permissions for a given dataset. This could also be
done via request to the user, but since we're not really doing a
RESTful service we do this via the api instead.
"""
# Check the parameters. Since we only use one parameter we check it
# here instead of creating a specific parameter parser
if len(request.params) != 1 or 'dataset' not in request.params:
return to_jsonp({'error': 'Parameter dataset missing'})
# Get the dataset we want to check permissions for
dataset = Dataset.by_name(request.params['dataset'])
# Return permissions
return to_jsonp({
"create":\
can.dataset.create() and dataset is None,
"read":\
False if dataset is None else can.dataset.read(dataset),
"update":\
False if dataset is None else can.dataset.update(dataset),
"delete":\
False if dataset is None else can.dataset.delete(dataset)
})
示例8: test_delete
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_delete(self):
cra = Dataset.by_name('cra')
assert len(cra) == 36, len(cra)
# double-check authz
response = self.app.post(url(controller='editor',
action='delete', dataset='cra'),
expect_errors=True)
assert '403' in response.status
cra = Dataset.by_name('cra')
assert len(cra) == 36, len(cra)
response = self.app.post(url(controller='editor',
action='delete', dataset='cra'),
extra_environ={'REMOTE_USER': 'test'})
cra = Dataset.by_name('cra')
assert cra is None, cra
示例9: test_index_hide_private
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_index_hide_private(self):
cra = Dataset.by_name('cra')
cra.private = True
db.session.commit()
response = self.app.get(url(controller='dataset', action='index', format='json'))
obj = json.loads(response.body)
h.assert_equal(len(obj['datasets']), 0)
示例10: create
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def create(self):
"""
Adds a new dataset dynamically through a POST request
"""
# User must be authenticated so we should have a user object in
# c.account, if not abort with error message
if not c.account:
abort(status_code=400, detail='user not authenticated')
# Check if the params are there ('metadata', 'csv_file')
if len(request.params) != 2:
abort(status_code=400, detail='incorrect number of params')
metadata = request.params['metadata'] \
if 'metadata' in request.params \
else abort(status_code=400, detail='metadata is missing')
csv_file = request.params['csv_file'] \
if 'csv_file' in request.params \
else abort(status_code=400, detail='csv_file is missing')
# We proceed with the dataset
try:
model = json.load(urllib2.urlopen(metadata))
except:
abort(status_code=400, detail='JSON model could not be parsed')
try:
log.info("Validating model")
model = validate_model(model)
except Invalid as i:
log.error("Errors occured during model validation:")
for field, error in i.asdict().items():
log.error("%s: %s", field, error)
abort(status_code=400, detail='Model is not well formed')
dataset = Dataset.by_name(model['dataset']['name'])
if dataset is None:
dataset = Dataset(model)
require.dataset.create()
dataset.managers.append(c.account)
dataset.private = True # Default value
db.session.add(dataset)
else:
require.dataset.update(dataset)
log.info("Dataset: %s", dataset.name)
source = Source(dataset=dataset, creator=c.account, url=csv_file)
log.info(source)
for source_ in dataset.sources:
if source_.url == csv_file:
source = source_
break
db.session.add(source)
db.session.commit()
# Send loading of source into celery queue
load_source.delay(source.id)
return to_jsonp(dataset_apply_links(dataset.as_dict()))
示例11: test_view_private
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_view_private(self):
cra = Dataset.by_name('cra')
cra.private = True
db.session.commit()
response = self.app.get(url(controller='dataset', action='view',
dataset='cra'), status=403)
h.assert_false('Country Regional Analysis v2009' in response,
"'Country Regional Analysis v2009' not in response!")
h.assert_false('openspending_browser' in response, "'openspending_browser' not in response!")
示例12: test_core_update_invalid_currency
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_core_update_invalid_currency(self):
response = self.app.post(url(controller='editor',
action='core_update', dataset='cra'),
params={'name': 'cra', 'label': 'Common Rough Act',
'description': 'I\'m a banana', 'currency': 'glass pearls'},
extra_environ={'REMOTE_USER': 'test'})
assert 'not a valid currency' in response.body
cra = Dataset.by_name('cra')
assert cra.currency=='GBP', cra.label
示例13: test_core_update_invalid_territory
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_core_update_invalid_territory(self):
response = self.app.post(url(controller='editor',
action='core_update', dataset='cra'),
params={'name': 'cra', 'label': 'CRA', 'territories': 'su',
'description': 'I\'m a banana', 'currency': 'GBP'},
extra_environ={'REMOTE_USER': 'test'})
assert not 'updated' in response.body
cra = Dataset.by_name('cra')
assert not 'su' in cra.territories
示例14: test_core_update_invalid_label
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_core_update_invalid_label(self):
response = self.app.post(url(controller='editor',
action='core_update', dataset='cra'),
params={'name': 'cra', 'label': '',
'description': 'I\'m a banana', 'currency': 'GBP'},
extra_environ={'REMOTE_USER': 'test'})
assert 'Required' in response.body
cra = Dataset.by_name('cra')
assert cra.label!='', cra.label
示例15: test_team_update
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_name [as 别名]
def test_team_update(self):
response = self.app.post(url(controller='editor',
action='team_update', dataset='cra'),
params={},
extra_environ={'REMOTE_USER': 'test'},
expect_errors=True)
assert '200' in response.status, response.status
cra = Dataset.by_name('cra')
assert len(cra.managers.all()) == 1, cra.managers