wcs: add some non-regression tests (#53213)
gitea-wip/combo/pipeline/head Build started... Details
gitea/combo/pipeline/head Build started... Details

cells on specific category or card: be sure that only the correct site
is requested
This commit is contained in:
Lauréline Guérin 2021-04-26 16:30:16 +02:00
parent 085e729f6d
commit 9303dbc862
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 14 additions and 4 deletions

View File

@ -851,7 +851,7 @@ class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
def get_api_url(self, context):
parts = self.carddef_reference.split(':')
url = 'api/cards/%s/list' % parts[1]
url = '/api/cards/%s/list' % parts[1]
if len(parts) > 2:
url = '%s/%s' % (url, parts[2])
user = self.get_concerned_user(context)
@ -861,7 +861,6 @@ class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
def get_cell_extra_context(self, context):
extra_context = super().get_cell_extra_context(context)
extra_context.update(WcsBlurpMixin.get_cell_extra_context(self, context))
extra_context['title'] = self.cached_title
pages_with_sub_slug = Page.objects.exclude(sub_slug='')
@ -971,7 +970,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
if not card_id:
return extra_context
card_slug = self.carddef_reference.split(':')[1]
api_url = 'api/cards/%s/%s/' % (card_slug, card_id)
api_url = '/api/cards/%s/%s/' % (card_slug, card_id)
wcs_site = get_wcs_services().get(self.wcs_site)

View File

@ -948,10 +948,13 @@ def test_forms_of_category_cell_render(mock_send, context):
with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
mock_json = mock.Mock(status_code=200)
requests_get.return_value = mock_json
cell.render(context)
result = cell.render(context)
assert '<h2>' not in result
context['combo_display_even_empty_categories'] = True
assert len(requests_get.call_args_list) == 1
assert requests_get.call_args_list[0][0][0] == '/api/categories/test-9/formdefs/'
assert requests_get.call_args_list[0][1]['remote_service']['url'] == 'http://127.0.0.1:8999/'
result = cell.render(context)
assert '<h2>' in result
context.pop('combo_display_even_empty_categories')
@ -1369,6 +1372,14 @@ def test_cards_cell_render(mock_send, context):
assert '<a href="/foo/12"><span class="card-title">bb</span></a>' in result
assert '<a href="/foo/13"><span class="card-title">cc</span></a>' not in result
with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
mock_json = mock.Mock(status_code=200)
requests_get.return_value = mock_json
cell.render(context)
assert len(requests_get.call_args_list) == 1
assert requests_get.call_args_list[0][0][0] == '/api/cards/card_model_1/list/foo'
assert requests_get.call_args_list[0][1]['remote_service']['url'] == 'http://127.0.0.1:8999/'
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
def test_cards_cell_only_for_user(mock_send, context):