wcs: don't warn on 404 for user URIs (#32148)

This commit is contained in:
Frédéric Péters 2019-04-16 15:27:45 +02:00
parent 3e20f19aa7
commit 0220713ea2
2 changed files with 35 additions and 1 deletions

View File

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

View File

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