environment: display netloc on network checks service (#50451)

This commit is contained in:
Nicolas Roche 2021-02-09 15:13:45 +01:00
parent d1636eeece
commit 24e7c657a0
2 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,5 @@
from django.core.exceptions import ValidationError
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import gettext_lazy as _
from hobo.environment.models import ServiceBase
@ -8,13 +9,13 @@ def validate_service_url(url):
service = ServiceBase(title='dummy', base_url=url)
if not service.is_resolvable():
raise ValidationError(
_('Error: %(url)s is not resolvable'),
_('Error: %(netloc)s is not resolvable in URL %(url)s'),
code='not-resolvable',
params={'url': url}
params={'netloc': urlparse.urlsplit(url).netloc, 'url': url}
)
if not service.has_valid_certificate():
raise ValidationError(
_('Error: %(url)s has no valid certificate'),
_('Error: no valid certificate for %(url)s'),
code='invalid-certificate',
params={'url': url}
)

View File

@ -48,7 +48,7 @@ def test_check_action_unresolvable(monkeypatch):
monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: True)
with pytest.raises(CommandError) as e_info:
command.check_action(action, action_args)
assert 'is not resolvable' in str(e_info.value)
assert 'test.org is not resolvable in URL https://test.org/' in str(e_info.value)
def test_check_action_invalid_certificat(monkeypatch):
"""raise CommandError"""
@ -60,7 +60,7 @@ def test_check_action_invalid_certificat(monkeypatch):
monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: False)
with pytest.raises(CommandError) as e_info:
command.check_action(action, action_args)
assert 'has no valid certificate' in str(e_info.value)
assert 'no valid certificate for https://test.org/' in str(e_info.value)
def test_handle():
kwargs = {'verbosity': 0,