misc: don't check validity for links with multiple variables (#41139)

This commit is contained in:
Frédéric Péters 2020-03-29 13:37:17 +02:00
parent 27ce2bbaeb
commit 23966b3504
2 changed files with 34 additions and 0 deletions

View File

@ -1171,6 +1171,10 @@ class LinkCell(CellBase):
self.mark_as_invalid('data_url_not_defined')
return
if self.url.count('{{') > 1:
self.mark_as_valid()
return
resp = None
try:
resp = requests.get(self.get_url(), timeout=settings.REQUESTS_TIMEOUT)

View File

@ -204,6 +204,36 @@ def test_link_cell_validity():
assert validity_info.invalid_reason_code == 'data_url_invalid'
assert validity_info.invalid_since is not None
# external link with a single variable
cell.link_page = None
cell.anchor = ''
cell.url = '{{test_url}}'
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net/'}):
with mock.patch('combo.data.models.requests.get') as requests_get:
mock_json = mock.Mock(status_code=200)
requests_get.return_value = mock_json
cell.save()
assert requests_get.call_args_list[0][0][0] == 'http://www.example.net/'
assert ValidityInfo.objects.exists() is False
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net/'}):
with mock.patch('combo.data.models.requests.get') as requests_get:
mock_json = mock.Mock(status_code=404)
requests_get.return_value = mock_json
cell.save()
assert requests_get.call_args_list[0][0][0] == 'http://www.example.net/'
assert ValidityInfo.objects.exists() is True
# external link with two variables
cell.url = '{{test_url}}/path/{{other}}'
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net/'}):
with mock.patch('combo.data.models.requests.get') as requests_get:
mock_json = mock.Mock(status_code=200)
requests_get.return_value = mock_json
cell.save()
assert requests_get.call_args_list == []
assert ValidityInfo.objects.exists() is False
def test_link_list_cell():
page = Page.objects.create(title='example page', slug='example-page')