From 0220713ea2f0989f13e6438bd5c57645987af234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 16 Apr 2019 15:27:45 +0200 Subject: [PATCH] wcs: don't warn on 404 for user URIs (#32148) --- combo/apps/wcs/models.py | 6 +++++- tests/test_wcs.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py index 252e0167..7d4e4ff8 100644 --- a/combo/apps/wcs/models.py +++ b/combo/apps/wcs/models.py @@ -188,6 +188,7 @@ class WcsBlurpMixin(object): is_enabled = classmethod(is_wcs_enabled) cache_duration = 5 api_url = None + warn_on_404 = True def get_api_url(self, context): return self.api_url @@ -238,7 +239,8 @@ class WcsBlurpMixin(object): item['site_slug'] = wcs_slug if not 200 in returns: # not a single valid answer - logging.error('failed to get data from any %s (%r)', api_url, returns) + if returns != set([404]) or self.warn_on_404: + logging.error('failed to get data from any %s (%r)', api_url, returns) return wcs_sites @@ -287,6 +289,8 @@ class WcsDataBaseCell(CellBase, WcsBlurpMixin): class WcsUserDataBaseCell(WcsDataBaseCell): + warn_on_404 = False + class Meta: abstract = True diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 9add0ead..0cfe7501 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -169,6 +169,15 @@ class MockUser(object): def get_name_id(self): return None + +class MockUserWithNameId(object): + email = 'foo@example.net' + def is_authenticated(self): + return True + def get_name_id(self): + return 'xyz' + + def run_wcs_script(script, hostname): script_path = os.path.join(WCS_DIR, script + '.py') fd = open(script_path, 'w') @@ -431,6 +440,27 @@ def test_current_forms_cell_render_single_site(context): assert 'http://127.0.0.2:8999/form-title/1/' not in result assert 'http://127.0.0.2:8999/form-title/22/' not in result +@wcsctl_present +def test_current_forms_unknown_name_id(caplog, context): + page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard') + page.save() + cell = WcsCurrentFormsCell(page=page, placeholder='content', order=0) + cell.wcs_site = 'default' + cell.save() + + context['request'].user = MockUserWithNameId() + + # query should fail as nothing is cached + cache.clear() + with pytest.raises(NothingInCacheException): + result = cell.render(context) + + context['synchronous'] = True # to get fresh content + + result = cell.render(context) + assert 'http://127.0.0.1:8999/' not in result + assert len(caplog.records) == 0 + @wcsctl_present def test_forms_of_category_cell_setup(): cell = WcsFormsOfCategoryCell()