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_cell_template_error(app):
|
|
237 |
Page.objects.all().delete()
|
|
238 |
page = Page(title='example page', slug='example-page')
|
|
239 |
page.save()
|
|
240 |
|
|
241 |
with override_settings(JSON_CELL_TYPES={'foobar': {'name': 'Foobar', 'url': 'http://test/'},
|
|
242 |
'badsyntax': {'name': 'Error', 'url': 'http://test/'}},
|
|
243 |
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
|
244 |
# missing template
|
|
245 |
cell = ConfigJsonCell()
|
|
246 |
cell.key = 'foobar'
|
|
247 |
cell.page = page
|
|
248 |
cell.order = 0
|
|
249 |
cell.save()
|
|
250 |
|
|
251 |
url = reverse('combo-public-ajax-page-cell', kwargs={'page_pk': page.id,
|
|
252 |
'cell_reference': cell.get_reference()})
|
|
253 |
data = {'data': []}
|
|
254 |
|
|
255 |
with mock.patch('combo.utils.requests.get') as requests_get:
|
|
256 |
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
|
|
257 |
with override_settings(DEBUG=False):
|
|
258 |
resp_body = app.get(url).body.strip()
|
|
259 |
assert resp_body == 'template error: TemplateDoesNotExist'
|
|
260 |
with override_settings(DEBUG=True):
|
|
261 |
resp_body = app.get(url).body.strip()
|
|
262 |
assert resp_body.startswith('template error: TemplateDoesNotExist')
|
|
263 |
assert 'cell: config json cell' in resp_body
|
|
264 |
assert 'template names: [' in resp_body
|
|
265 |
assert 'exception message: combo/json/foobar.html, combo/configjsoncell.html' in resp_body
|
|
266 |
|
|
267 |
# syntax error (see badsyntax.html)
|
|
268 |
cell.key = 'badsyntax'
|
|
269 |
cell.save()
|
|
270 |
with mock.patch('combo.utils.requests.get') as requests_get:
|
|
271 |
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
|
|
272 |
with override_settings(DEBUG=False):
|
|
273 |
resp_body = app.get(url).body.strip()
|
|
274 |
assert resp_body == 'template error: TemplateSyntaxError'
|
|
275 |
with override_settings(DEBUG=True):
|
|
276 |
resp_body = app.get(url).body.strip()
|
|
277 |
assert resp_body.startswith('template error: TemplateSyntaxError')
|
|
278 |
assert 'cell: config json cell' in resp_body
|
|
279 |
assert 'template names: [' in resp_body
|
|
280 |
assert 'exception message: Invalid block tag' in resp_body
|
|
281 |
assert 'foo_boom_bar' in resp_body
|
234 |
|
-
|