cells: check tempate_string is defined in configjsoncell settings (#55647)
This commit is contained in:
parent
dc02e65e18
commit
d1cd349cce
|
@ -2097,7 +2097,8 @@ class ConfigJsonCell(JsonCellBase):
|
|||
return context
|
||||
|
||||
def render(self, context):
|
||||
if 'template_string' in self.parameters:
|
||||
settings_varnames = [f.get('varname') for f in settings.JSON_CELL_TYPES[self.key].get('form') or {}]
|
||||
if 'template_string' in self.parameters and 'template_string' in settings_varnames:
|
||||
self.template_string = self.parameters['template_string']
|
||||
return super().render(context)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ from django.conf import settings
|
|||
from django.contrib.auth.models import User
|
||||
from django.db import connection
|
||||
from django.forms.widgets import Media
|
||||
from django.template.exceptions import TemplateDoesNotExist
|
||||
from django.test import override_settings
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
|
@ -853,6 +854,22 @@ def test_config_json_cell_with_template_string(settings, context):
|
|||
requests_get.return_value = mock_json_response(content=json.dumps(data), status_code=200)
|
||||
assert cell.render({}) == 'Foo Bar plop'
|
||||
|
||||
settings.JSON_CELL_TYPES = { # template_string is not defined anymore
|
||||
'test-config-json-cell': {
|
||||
'name': 'Foobar',
|
||||
'url': 'http://foo',
|
||||
'form': [
|
||||
{"varname": "identifier", "type": "string", "label": "Identifier"},
|
||||
],
|
||||
},
|
||||
}
|
||||
cell = ConfigJsonCell.objects.get(pk=cell.pk) # reload cell
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
data = {'data': []}
|
||||
requests_get.return_value = mock_json_response(content=json.dumps(data), status_code=200)
|
||||
with pytest.raises(TemplateDoesNotExist):
|
||||
cell.render({})
|
||||
|
||||
|
||||
def test_config_json_cell_with_global(settings, app):
|
||||
settings.JSON_CELL_TYPES = {
|
||||
|
|
Loading…
Reference in New Issue