0001-cells-check-tempate_string-is-defined-in-configjsonc.patch
combo/data/models.py | ||
---|---|---|
2097 | 2097 |
return context |
2098 | 2098 | |
2099 | 2099 |
def render(self, context): |
2100 |
if 'template_string' in self.parameters: |
|
2100 |
settings_varnames = [f.get('varname') for f in settings.JSON_CELL_TYPES[self.key].get('form') or {}] |
|
2101 |
if 'template_string' in self.parameters and 'template_string' in settings_varnames: |
|
2101 | 2102 |
self.template_string = self.parameters['template_string'] |
2102 | 2103 |
return super().render(context) |
2103 | 2104 |
tests/test_cells.py | ||
---|---|---|
11 | 11 |
from django.contrib.auth.models import User |
12 | 12 |
from django.db import connection |
13 | 13 |
from django.forms.widgets import Media |
14 |
from django.template.exceptions import TemplateDoesNotExist |
|
14 | 15 |
from django.test import override_settings |
15 | 16 |
from django.test.client import RequestFactory |
16 | 17 |
from django.test.utils import CaptureQueriesContext |
... | ... | |
853 | 854 |
requests_get.return_value = mock_json_response(content=json.dumps(data), status_code=200) |
854 | 855 |
assert cell.render({}) == 'Foo Bar plop' |
855 | 856 | |
857 |
settings.JSON_CELL_TYPES = { # template_string is not defined anymore |
|
858 |
'test-config-json-cell': { |
|
859 |
'name': 'Foobar', |
|
860 |
'url': 'http://foo', |
|
861 |
'form': [ |
|
862 |
{"varname": "identifier", "type": "string", "label": "Identifier"}, |
|
863 |
], |
|
864 |
}, |
|
865 |
} |
|
866 |
cell = ConfigJsonCell.objects.get(pk=cell.pk) # reload cell |
|
867 |
with mock.patch('combo.utils.requests.get') as requests_get: |
|
868 |
data = {'data': []} |
|
869 |
requests_get.return_value = mock_json_response(content=json.dumps(data), status_code=200) |
|
870 |
with pytest.raises(TemplateDoesNotExist): |
|
871 |
cell.render({}) |
|
872 | ||
856 | 873 | |
857 | 874 |
def test_config_json_cell_with_global(settings, app): |
858 | 875 |
settings.JSON_CELL_TYPES = { |
859 |
- |