From c6cf29c988d2cea3c6a81d4199303d2e99743e7e Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Fri, 28 Jul 2017 00:42:18 +0200 Subject: [PATCH] json cell: add log_errors parameter (#17826) --- combo/data/models.py | 10 +++++++++- tests/test_cells.py | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/combo/data/models.py b/combo/data/models.py index 7feb8abf..69f38e11 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -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', diff --git a/tests/test_cells.py b/tests/test_cells.py index a75a4e28..b20f3290 100644 --- a/tests/test_cells.py +++ b/tests/test_cells.py @@ -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'}