Projet

Général

Profil

0002-wcs-add-some-non-regression-tests-53213.patch

Lauréline Guérin, 27 avril 2021 15:11

Télécharger (3,46 ko)

Voir les différences:

Subject: [PATCH 2/2] wcs: add some non-regression tests (#53213)

cells on specific category or card: be sure that only the correct site
is requested
 combo/apps/wcs/models.py |  5 ++---
 tests/test_wcs.py        | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)
combo/apps/wcs/models.py
851 851

  
852 852
    def get_api_url(self, context):
853 853
        parts = self.carddef_reference.split(':')
854
        url = 'api/cards/%s/list' % parts[1]
854
        url = '/api/cards/%s/list' % parts[1]
855 855
        if len(parts) > 2:
856 856
            url = '%s/%s' % (url, parts[2])
857 857
        user = self.get_concerned_user(context)
......
861 861

  
862 862
    def get_cell_extra_context(self, context):
863 863
        extra_context = super().get_cell_extra_context(context)
864
        extra_context.update(WcsBlurpMixin.get_cell_extra_context(self, context))
865 864
        extra_context['title'] = self.cached_title
866 865

  
867 866
        pages_with_sub_slug = Page.objects.exclude(sub_slug='')
......
963 962
        if not card_id:
964 963
            return extra_context
965 964
        card_slug = self.carddef_reference.split(':')[1]
966
        api_url = 'api/cards/%s/%s/' % (card_slug, card_id)
965
        api_url = '/api/cards/%s/%s/' % (card_slug, card_id)
967 966

  
968 967
        wcs_site = get_wcs_services().get(self.wcs_site)
969 968

  
tests/test_wcs.py
948 948
    with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
949 949
        mock_json = mock.Mock(status_code=200)
950 950
        requests_get.return_value = mock_json
951
        cell.render(context)
952 951
        result = cell.render(context)
953 952
        assert '<h2>' not in result
954 953
        context['combo_display_even_empty_categories'] = True
954
        assert len(requests_get.call_args_list) == 1
955
        assert requests_get.call_args_list[0][0][0] == '/api/categories/test-9/formdefs/'
956
        assert requests_get.call_args_list[0][1]['remote_service']['url'] == 'http://127.0.0.1:8999/'
957

  
955 958
        result = cell.render(context)
956 959
        assert '<h2>' in result
957 960
        context.pop('combo_display_even_empty_categories')
......
1369 1372
    assert '<a href="/foo/12"><span class="card-title">bb</span></a>' in result
1370 1373
    assert '<a href="/foo/13"><span class="card-title">cc</span></a>' not in result
1371 1374

  
1375
    with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
1376
        mock_json = mock.Mock(status_code=200)
1377
        requests_get.return_value = mock_json
1378
        cell.render(context)
1379
    assert len(requests_get.call_args_list) == 1
1380
    assert requests_get.call_args_list[0][0][0] == '/api/cards/card_model_1/list/foo'
1381
    assert requests_get.call_args_list[0][1]['remote_service']['url'] == 'http://127.0.0.1:8999/'
1382

  
1372 1383

  
1373 1384
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
1374 1385
def test_cards_cell_only_for_user(mock_send, context):
1375
-