wcs: fix card cell display when card reference is not set (#60397)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-01-07 12:02:10 +01:00
parent 3a1b8aeade
commit 8d1735134c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 14 additions and 9 deletions

View File

@ -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

View File

@ -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