wcs: fix card cell display when card reference is not set (#60397)
This commit is contained in:
parent
3a1b8aeade
commit
8d1735134c
|
@ -970,7 +970,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
|
|||
return '%s-card-ids' % self.get_reference()
|
||||
|
||||
def modify_global_context(self, context, request):
|
||||
if self.global_context_key not in context:
|
||||
if self.carddef_reference and self.global_context_key not in context:
|
||||
card_ids = self.get_card_ids(context, request)
|
||||
context[self.global_context_key] = card_ids
|
||||
|
||||
|
|
|
@ -1835,12 +1835,24 @@ def test_card_cell_load(mock_send):
|
|||
def test_card_cell_render(mock_send, context, app):
|
||||
page = Page.objects.create(title='xxx', template_name='standard')
|
||||
cell = WcsCardInfosCell(page=page, placeholder='content', order=0)
|
||||
cell.carddef_reference = 'default:card_model_1'
|
||||
cell.title_type = 'manual'
|
||||
cell.custom_title = 'Foo bar {{ card.fields.title }}'
|
||||
cell.save()
|
||||
|
||||
# carddef_reference is not defined
|
||||
context['card_model_1_id'] = 11
|
||||
request = RequestFactory().get('/')
|
||||
cell.modify_global_context(context, request)
|
||||
context['synchronous'] = True # to get fresh content
|
||||
|
||||
result = cell.render(context)
|
||||
assert '<h2>Card Model 1</h2>' not in result
|
||||
assert '<p>Unknown Card</p>' in result
|
||||
|
||||
# card id not in context
|
||||
cell.carddef_reference = 'default:card_model_1'
|
||||
cell.save()
|
||||
del context['card_model_1_id']
|
||||
assert 'card_model_1_id' not in context
|
||||
result = cell.render(context)
|
||||
assert '<h2>Card Model 1</h2>' in result # default value
|
||||
|
@ -1851,13 +1863,6 @@ def test_card_cell_render(mock_send, context, app):
|
|||
cell.modify_global_context(context, request)
|
||||
cell.repeat_index = 0
|
||||
|
||||
# query should fail as nothing is cached
|
||||
cache.clear()
|
||||
with pytest.raises(NothingInCacheException):
|
||||
result = cell.render(context)
|
||||
|
||||
context['synchronous'] = True # to get fresh content
|
||||
|
||||
with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
|
||||
mock_resp = Response()
|
||||
mock_resp.status_code = 500
|
||||
|
|
Loading…
Reference in New Issue