Projet

Général

Profil

0001-environment-display-netloc-on-network-checks-service.patch

Nicolas Roche, 09 février 2021 17:28

Télécharger (3,08 ko)

Voir les différences:

Subject: [PATCH] environment: display netloc on network checks service
 (#50451)

 hobo/environment/validators.py | 7 ++++---
 tests/test_cook.py             | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)
hobo/environment/validators.py
1 1
from django.core.exceptions import ValidationError
2
from django.utils.six.moves.urllib import parse as urlparse
2 3
from django.utils.translation import gettext_lazy as _
3 4

  
4 5
from hobo.environment.models import ServiceBase
5 6

  
6 7

  
7 8
def validate_service_url(url):
8 9
    service = ServiceBase(title='dummy', base_url=url)
9 10
    if not service.is_resolvable():
10 11
        raise ValidationError(
11
            _('Error: %(url)s is not resolvable'),
12
            _('Error: %(netloc)s is not resolvable in URL %(url)s'),
12 13
            code='not-resolvable',
13
            params={'url': url}
14
            params={'netloc': urlparse.urlsplit(url).netloc, 'url': url}
14 15
        )
15 16
    if not service.has_valid_certificate():
16 17
        raise ValidationError(
17
            _('Error: %(url)s has no valid certificate'),
18
            _('Error: no valid certificate for %(url)s'),
18 19
            code='invalid-certificate',
19 20
            params={'url': url}
20 21
        )
tests/test_cook.py
43 43
    command = Command()
44 44
    command.server_action = 'mock a server_action handler (ex: hobo-create)'
45 45
    action, action_args = 'server-action', {u'url': u'https://test.org/'}
46 46

  
47 47
    monkeypatch.setattr(ServiceBase, 'is_resolvable', lambda x: False)
48 48
    monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: True)
49 49
    with pytest.raises(CommandError) as e_info:
50 50
        command.check_action(action, action_args)
51
    assert 'is not resolvable' in str(e_info.value)
51
    assert 'test.org is not resolvable in URL https://test.org/' in str(e_info.value)
52 52

  
53 53
def test_check_action_invalid_certificat(monkeypatch):
54 54
    """raise CommandError"""
55 55
    command = Command()
56 56
    command.server_action = 'mock a server_action handler (ex: hobo-create)'
57 57
    action, action_args = 'server-action', {u'url': u'https://test.org/'}
58 58

  
59 59
    monkeypatch.setattr(ServiceBase, 'is_resolvable', lambda x: True)
60 60
    monkeypatch.setattr(ServiceBase, 'has_valid_certificate', lambda x: False)
61 61
    with pytest.raises(CommandError) as e_info:
62 62
        command.check_action(action, action_args)
63
    assert 'has no valid certificate' in str(e_info.value)
63
    assert 'no valid certificate for https://test.org/' in str(e_info.value)
64 64

  
65 65
def test_handle():
66 66
    kwargs = {'verbosity': 0,
67 67
              'timeout': 'timeout value',
68 68
              'permissive': 'permissive value'}
69 69
    command = Command()
70 70
    command.run_cook = Mock()
71 71

  
72
-