本文整理汇总了Python中openspending.lib.browser.Browser.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.execute方法的具体用法?Python Browser.execute怎么用?Python Browser.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.lib.browser.Browser
的用法示例。
在下文中一共展示了Browser.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_union
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_filter_union(self):
f = {'foo': ['bar', 'baz']}
b = Browser(filter=f)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert '+foo:"bar" OR +foo:"baz"' in solr_args['fq']
示例2: index
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def index(self, dataset, format='html'):
# Get the dataset into the context variable 'c'
self._get_dataset(dataset)
# If the format is either json or csv we direct the user to the search
# API instead
if format in ['json', 'csv']:
return redirect(h.url_for(controller='api/version2',
action='search',
format=format, dataset=dataset,
**request.params))
# Get the default view
handle_request(request, c, c.dataset)
# Parse the parameters using the SearchParamParser (used by the API)
parser = EntryIndexParamParser(request.params)
params, errors = parser.parse()
# We have to remove page from the parameters because that's also
# used in the Solr browser (which fetches the queries)
params.pop('page')
# We limit ourselve to only our dataset
params['filter']['dataset'] = [c.dataset.name]
facet_dimensions = {field.name: field
for field in c.dataset.dimensions
if field.facet}
params['facet_field'] = facet_dimensions.keys()
# Create a Solr browser and execute it
b = Browser(**params)
try:
b.execute()
except SolrException as e:
return {'errors': [unicode(e)]}
# Get the entries, each item is a tuple of the dataset and entry
solr_entries = b.get_entries()
entries = [entry for (dataset, entry) in solr_entries]
# Get expanded facets for this dataset,
c.facets = b.get_expanded_facets(c.dataset)
# Create a pager for the entries
c.entries = templating.Page(entries, **request.params)
# Set the search word and default to empty string
c.search = params.get('q', '')
# Set filters (but remove the dataset as we don't need it)
c.filters = params['filter']
del c.filters['dataset']
# We also make the facet dimensions and dimension names available
c.facet_dimensions = facet_dimensions
c.dimensions = [dimension.name for dimension in c.dataset.dimensions]
# Render the entries page
return templating.render('entry/index.html')
示例3: test_facets_page_pagesize
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_facets_page_pagesize(self):
b = Browser(facet_field=['one'], facet_page=2, facet_pagesize=50)
b.execute()
_, solr_args = self.conn.raw_query.call_args
h.assert_equal(solr_args['facet.offset'], 50)
h.assert_equal(solr_args['facet.limit'], 50)
示例4: test_fractional_page_pagesize
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_fractional_page_pagesize(self):
b = Browser(page=2.5, pagesize=50)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args['start'] == 75
assert solr_args['rows'] == 50
示例5: test_facets_page_pagesize
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_facets_page_pagesize(self):
b = Browser(facet_field=["one"], facet_page=2, facet_pagesize=50)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args["facet.offset"] == 50
assert solr_args["facet.limit"] == 50
示例6: test_page_pagesize
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_page_pagesize(self):
b = Browser(page=2, pagesize=50)
b.execute()
_, solr_args = self.conn.raw_query.call_args
h.assert_equal(solr_args['start'], 50)
h.assert_equal(solr_args['rows'], 50)
示例7: test_page_pagesize
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_page_pagesize(self):
b = Browser(page=2, pagesize=50)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args["start"] == 50
assert solr_args["rows"] == 50
示例8: test_filter
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_filter(self):
f = {"foo": "bar", "baz": 'with "quotes"'}
b = Browser(filter=f)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert '+foo:"bar"' in solr_args["fq"]
assert '+baz:"with \\"quotes\\""' in solr_args["fq"]
示例9: test_filter
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_filter(self):
f = {'foo': 'bar', 'baz': 'with "quotes"'}
b = Browser(filter=f)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert '+foo:"bar"' in solr_args['fq']
assert '+baz:"with \\"quotes\\""' in solr_args['fq']
示例10: test_facets
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_facets(self):
b = Browser(facet_field=['foo', 'bar'])
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args['facet'] == 'true'
assert solr_args['facet.mincount'] == 1
assert solr_args['facet.sort'] == 'count'
assert solr_args['facet.field'] == ['foo', 'bar']
示例11: test_entries_order
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_entries_order(self):
self.conn.raw_query.return_value = make_response([1, 2, 3])
self.dataset.entries.return_value = make_entries([3, 1, 2])
b = Browser()
b.execute()
entries = b.get_entries()
h.assert_equal(map(lambda (a, b): b, entries), make_entries([1, 2, 3]))
示例12: test_entries_order
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_entries_order(self):
self.conn.raw_query.return_value = make_response([1, 2, 3])
self.dataset.entries.return_value = make_entries([3, 1, 2])
b = Browser()
b.execute()
entries = b.get_entries()
assert map(lambda a_b: a_b[1], entries) == make_entries([1, 2, 3])
示例13: test_facets
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_facets(self):
b = Browser(facet_field=['foo', 'bar'])
b.execute()
_, solr_args = self.conn.raw_query.call_args
h.assert_equal(solr_args['facet'], 'true')
h.assert_equal(solr_args['facet.mincount'], 1)
h.assert_equal(solr_args['facet.sort'], 'count')
h.assert_equal(solr_args['facet.field'], ['foo', 'bar'])
示例14: test_fractional_page_pagesize
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_fractional_page_pagesize(self):
b = Browser(page=2.5, pagesize=50)
b.execute()
_, solr_args = self.conn.raw_query.call_args
# Use assert_is rather than assert_equal to verify
# that it's an integer.
h.assert_is(solr_args['start'], 75)
h.assert_equal(solr_args['rows'], 50)
示例15: test_entries_stats
# 需要导入模块: from openspending.lib.browser import Browser [as 别名]
# 或者: from openspending.lib.browser.Browser import execute [as 别名]
def test_entries_stats(self):
self.conn.raw_query.return_value = make_response([1, 2, 3])
self.dataset.entries.return_value = make_entries([3, 1, 2])
b = Browser()
b.execute()
stats = b.get_stats()
h.assert_equal(stats['results_count'], 3)
h.assert_equal(stats['results_count_query'], 1234)