cells: check tempate_string is defined in configjsoncell settings (#55647)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-07-26 14:02:41 +02:00
parent dc02e65e18
commit d1cd349cce
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 19 additions and 1 deletions

View File

@ -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)

View File

@ -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 = {