json cell: add log_errors parameter (#17826)

This commit is contained in:
Thomas NOËL 2017-07-28 00:42:18 +02:00
parent 1f0eaa3057
commit c6cf29c988
2 changed files with 14 additions and 2 deletions

View File

@ -831,6 +831,7 @@ class JsonCellBase(CellBase):
template_string = None
varnames = None
force_async = False
log_errors = True
actions = {}
additional_data = None
# [
@ -857,7 +858,8 @@ class JsonCellBase(CellBase):
context[varname] = context['request'].GET[varname]
self._json_content = None
data_urls = [{'key': 'json', 'url': self.url, 'cache_duration': self.cache_duration}]
data_urls = [{'key': 'json', 'url': self.url, 'cache_duration': self.cache_duration,
'log_errors': self.log_errors}]
data_urls.extend(self.additional_data or [])
for data_url_dict in data_urls:
@ -878,6 +880,7 @@ class JsonCellBase(CellBase):
without_user=True,
raise_if_not_cached=not(context.get('synchronous')),
invalidate_cache=invalidate_cache,
log_errors=data_url_dict.get('log_errors', self.log_errors),
)
extra_context[data_key + '_url'] = url
extra_context[data_key + '_status'] = json_response.status_code
@ -1036,6 +1039,11 @@ class ConfigJsonCell(JsonCellBase):
return settings.JSON_CELL_TYPES[self.key].get('force_async',
JsonCellBase.force_async)
@property
def log_errors(self):
return settings.JSON_CELL_TYPES[self.key].get('log_errors',
JsonCellBase.log_errors)
@property
def actions(self):
return settings.JSON_CELL_TYPES[self.key].get('actions',

View File

@ -341,6 +341,7 @@ def test_config_json_cell_with_param_in_url(app):
'test-config-json-cell': {
'name': 'Foobar',
'url': 'http://foo?var=[identifier]',
'log_errors': False,
'form': [
{
"varname": "identifier",
@ -366,6 +367,7 @@ def test_config_json_cell_with_param_in_url(app):
resp = app.get(url)
assert requests_get.call_count == 1
assert requests_get.call_args[0][0] == 'http://foo?var=plop'
assert requests_get.call_args[-1]['log_errors'] == False
def test_json_force_async():
cell = JsonCellBase()
@ -407,7 +409,7 @@ def test_config_json_cell_additional_url(app):
'name': 'Foobar',
'url': 'http://foo',
'additional-data': [
{'key': 'plop', 'url': 'http://bar'},
{'key': 'plop', 'url': 'http://bar', 'log_errors': False},
]
}},
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
@ -427,7 +429,9 @@ def test_config_json_cell_additional_url(app):
assert resp.body.strip() == '/var1=toto/var2=toto/'
assert len(requests_get.mock_calls) == 2
assert requests_get.mock_calls[0][1][0] == 'http://foo'
assert requests_get.mock_calls[0][-1]['log_errors'] == True
assert requests_get.mock_calls[1][1][0] == 'http://bar'
assert requests_get.mock_calls[1][-1]['log_errors'] == False
with mock.patch('combo.utils.requests.get') as requests_get:
data = {'data': 'toto'}