misc: push json cell parameters into context early on (#16685)
This commit is contained in:
parent
123def27c4
commit
bc28c554a3
|
@ -956,6 +956,8 @@ class ConfigJsonCell(JsonCellBase):
|
|||
return config_form_class
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
context.update(self.parameters) # early push for templated URLs
|
||||
ctx = super(ConfigJsonCell, self).get_cell_extra_context(context)
|
||||
ctx['parameters'] = self.parameters
|
||||
ctx.update(self.parameters)
|
||||
return ctx
|
||||
|
|
|
@ -258,6 +258,7 @@ def test_config_json_cell():
|
|||
context = cell.get_cell_extra_context(Context({'request': request}))
|
||||
assert context['json'] == {'hello': 'world'}
|
||||
assert context['parameters'] == {'blah': 'plop'}
|
||||
assert context['blah'] == 'plop'
|
||||
|
||||
with override_settings(JSON_CELL_TYPES={'foobar': {
|
||||
'name': 'Foobar', 'url': 'http://test/', 'cache_duration': 10}}):
|
||||
|
@ -299,6 +300,40 @@ def test_config_json_cell_with_varnames(app):
|
|||
assert '/var1=foo/' in resp.body
|
||||
assert '/var2=bar/' in resp.body
|
||||
|
||||
def test_config_json_cell_with_param_in_url(app):
|
||||
page = Page(title='example page', slug='index')
|
||||
page.save()
|
||||
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-config-json-cell': {
|
||||
'name': 'Foobar',
|
||||
'url': 'http://foo?var=[identifier]',
|
||||
'form': [
|
||||
{
|
||||
"varname": "identifier",
|
||||
"type": "string",
|
||||
"label": "Identifier"
|
||||
}
|
||||
]
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
cell = ConfigJsonCell()
|
||||
cell.key = 'test-config-json-cell'
|
||||
cell.parameters = {'identifier': 'plop'}
|
||||
cell.page = page
|
||||
cell.title = 'Example Site'
|
||||
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()})
|
||||
resp = app.get(url)
|
||||
assert requests_get.call_count == 1
|
||||
assert requests_get.call_args[0][0] == 'http://foo?var=plop'
|
||||
|
||||
def test_json_force_async():
|
||||
cell = JsonCellBase()
|
||||
cell.url = 'http://example.net/test-force-async'
|
||||
|
|
Loading…
Reference in New Issue