Projet

Général

Profil

0001-cook-allow-ports-in-url-provided-by-the-recipe-38964.patch

Nicolas Roche, 15 janvier 2020 14:32

Télécharger (3,59 ko)

Voir les différences:

Subject: [PATCH] cook: allow ports in url provided by the recipe (#38964)

 hobo/environment/models.py |  4 ++--
 tests/test_health_api.py   | 18 +++++++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)
hobo/environment/models.py
205 205

  
206 206
    def is_resolvable(self):
207 207
        try:
208
            netloc = urlparse(self.base_url).netloc
209
            if netloc and socket.gethostbyname(netloc):
208
            hostname = urlparse(self.base_url).hostname
209
            if hostname and socket.gethostbyname(hostname):
210 210
                return True
211 211
        except socket.gaierror:
212 212
            return False
tests/test_health_api.py
23 23
    a.save()
24 24
    c = Combo(title='jazz', slug='jazz', base_url='https://jazz.example.publik')
25 25
    c.save()
26
    c = Combo(title='rock', slug='rock', base_url='https://rock.example.publik:443')
27
    c.save()
26 28

  
27 29

  
28 30
def test_response(app, admin_user, services, monkeypatch):
......
34 36
    content = json.loads(response.content)
35 37
    assert 'blues' in content['data'].keys()
36 38
    assert 'jazz' in content['data'].keys()
39
    assert 'rock' in content['data'].keys()
37 40

  
38 41

  
39 42
def test_is_resolvable(app, admin_user, services, monkeypatch):
40 43
    cache.clear()
41
    def gethostname(netloc):
42
        if netloc == "jazz.example.publik":
44
    def gethostname(hostname):
45
        if hostname == "jazz.example.publik" or hostname == "rock.example.publik":
43 46
            return '176.31.123.109'
44 47
        else:
45 48
            raise socket.gaierror
......
49 52
    content = json.loads(response.content)
50 53
    blues = content['data']['blues']
51 54
    jazz = content['data']['jazz']
55
    rock = content['data']['rock']
52 56
    assert not blues['is_resolvable']
53 57
    assert jazz['is_resolvable']
58
    assert rock['is_resolvable']
54 59

  
55 60

  
56 61
def test_is_running(app, admin_user, services, monkeypatch):
......
67 72
    def blues_mock(url, request):
68 73
        return {'status_code': 404}
69 74

  
70
    with HTTMock(blues_mock, jazz_mock) as mock:
75
    @urlmatch(netloc='rock.example.publik')
76
    @remember_called
77
    def rock_mock(url, request):
78
        return {'status_code': 200}
79

  
80
    with HTTMock(blues_mock, jazz_mock, rock_mock) as mock:
71 81
        response = app.get('/api/health/')
72 82
        content = json.loads(response.content)
73 83
        blues = content['data']['blues']
......
76 86
        assert jazz['is_running']
77 87
        assert blues_mock.call['count'] == 2
78 88
        assert jazz_mock.call['count'] == 2
89
        assert rock_mock.call['count'] == 2
79 90

  
80 91
        # check it gets results from cache
81 92
        response = app.get('/api/health/')
......
86 97
        assert jazz['is_running']
87 98
        assert blues_mock.call['count'] == 2
88 99
        assert jazz_mock.call['count'] == 2
100
        assert rock_mock.call['count'] == 2
89 101

  
90 102

  
91 103
def test_is_operational(app, admin_user, services, monkeypatch):
92
-