Projet

Général

Profil

0001-add-fail-over-template-for-config-json-cell-15768.patch

Thomas Noël, 05 avril 2017 15:44

Télécharger (2,42 ko)

Voir les différences:

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
combo/public/templates/combo/configjsoncell.html
1
{% load i18n %}{% trans 'missing template' %}{% if debug %} combo/json/{{ cell.key }}.html{% endif %}
tests/test_cells.py
10 10
from django.test import override_settings
11 11
from django.test.client import RequestFactory
12 12
from django.contrib.auth.models import User
13
from django.core.urlresolvers import reverse
13 14

  
14 15
from combo.utils import NothingInCacheException
15 16

  
......
231 232
            context = cell.get_cell_extra_context(Context({'request': request}))
232 233
            assert context['json'] == {'hello': 'world'}
233 234
            assert context['parameters'] == {'blah': 'plop'}
235

  
236
def test_config_json_cell_without_template(app):
237
    page = Page(title='example page', slug='example-page')
238
    page.save()
239

  
240
    with override_settings(JSON_CELL_TYPES={'foobar': {'name': 'Foobar', 'url': 'http://test/'}}):
241
        cell = ConfigJsonCell()
242
        cell.key = 'foobar'
243
        cell.page = page
244
        cell.order = 0
245
        cell.save()
246

  
247
        with mock.patch('combo.utils.requests.get') as requests_get:
248
            data = {'data': []}
249
            requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
250
            url = reverse('combo-public-ajax-page-cell',
251
                    kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()})
252
            with override_settings(DEBUG=True):
253
                assert app.get(url).body.strip() == 'missing template combo/json/foobar.html'
254
            with override_settings(DEBUG=False):
255
                assert app.get(url).body.strip() == 'missing template'
234
-