From 521d9d2848f724782113347574f704ae3dbb89a9 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Wed, 5 Apr 2017 15:43:30 +0200 Subject: [PATCH] add fail-over template for config json cell (#15768) --- combo/public/templates/combo/configjsoncell.html | 1 + tests/test_cells.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 combo/public/templates/combo/configjsoncell.html diff --git a/combo/public/templates/combo/configjsoncell.html b/combo/public/templates/combo/configjsoncell.html new file mode 100644 index 0000000..3f40ebc --- /dev/null +++ b/combo/public/templates/combo/configjsoncell.html @@ -0,0 +1 @@ +{% load i18n %}{% trans 'missing template' %}{% if debug %} combo/json/{{ cell.key }}.html{% endif %} diff --git a/tests/test_cells.py b/tests/test_cells.py index 3b15fd9..1e08023 100644 --- a/tests/test_cells.py +++ b/tests/test_cells.py @@ -10,6 +10,7 @@ from django.template import Context from django.test import override_settings from django.test.client import RequestFactory from django.contrib.auth.models import User +from django.core.urlresolvers import reverse from combo.utils import NothingInCacheException @@ -231,3 +232,24 @@ def test_config_json_cell(): context = cell.get_cell_extra_context(Context({'request': request})) assert context['json'] == {'hello': 'world'} assert context['parameters'] == {'blah': 'plop'} + +def test_config_json_cell_without_template(app): + page = Page(title='example page', slug='example-page') + page.save() + + with override_settings(JSON_CELL_TYPES={'foobar': {'name': 'Foobar', 'url': 'http://test/'}}): + cell = ConfigJsonCell() + cell.key = 'foobar' + cell.page = page + cell.order = 0 + cell.save() + + with mock.patch('combo.utils.requests.get') as requests_get: + data = {'data': []} + requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200) + url = reverse('combo-public-ajax-page-cell', + kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()}) + with override_settings(DEBUG=True): + assert app.get(url).body.strip() == 'missing template combo/json/foobar.html' + with override_settings(DEBUG=False): + assert app.get(url).body.strip() == 'missing template' -- 2.11.0