def test_wait_healthcheck_timeout(self, requests): nginx = Nginx() def side_effect(method, url, timeout, **params): raise Exception('some error') requests.request.side_effect = side_effect with self.assertRaises(Exception): nginx.wait_healthcheck('myhost.com', timeout=2) self.assertGreaterEqual(requests.request.call_count, 2) requests.request.assert_called_with('get', 'http://myhost.com:8089/healthcheck', timeout=2)
def test_wait_healthcheck_timeout(self, requests): nginx = Nginx() def side_effect(url, timeout): raise Exception('some error') requests.get.side_effect = side_effect with self.assertRaises(Exception): nginx.wait_healthcheck('myhost.com', timeout=2) self.assertGreaterEqual(requests.get.call_count, 2) requests.get.assert_called_with('http://myhost.com:8089/healthcheck', timeout=2)
def test_wait_healthcheck_timeout(self, requests): nginx = Nginx() def side_effect(url, timeout): raise Exception("some error") requests.get.side_effect = side_effect with self.assertRaises(Exception): nginx.wait_healthcheck("myhost.com", timeout=2) self.assertGreaterEqual(requests.get.call_count, 2) requests.get.assert_has_call("http://myhost.com:8089/healthcheck", timeout=2)
def test_wait_app_healthcheck(self, requests): nginx = Nginx() count = [0] response = mock.Mock() response.status_code = 200 response.text = '\n\nWORKING' def side_effect(method, url, timeout, **params): count[0] += 1 if count[0] < 2: raise Exception('some error') return response requests.request.side_effect = side_effect nginx.wait_healthcheck('myhost.com', timeout=5, manage_healthcheck=False) self.assertEqual(requests.request.call_count, 2) requests.request.assert_called_with('get', 'http://myhost.com:8080/_nginx_healthcheck/', timeout=2)
def test_wait_healthcheck(self, requests): nginx = Nginx() count = [0] response = mock.Mock() response.status_code = 200 response.text = 'WORKING' def side_effect(url, timeout): count[0] += 1 if count[0] < 2: raise Exception('some error') return response requests.get.side_effect = side_effect nginx.wait_healthcheck('myhost.com', timeout=5) self.assertEqual(requests.get.call_count, 2) requests.get.assert_has_call('http://myhost.com:8089/healthcheck', timeout=2)
def test_wait_app_healthcheck(self, requests): nginx = Nginx() count = [0] response = mock.Mock() response.status_code = 200 response.text = '\n\nWORKING' def side_effect(url, timeout): count[0] += 1 if count[0] < 2: raise Exception('some error') return response requests.get.side_effect = side_effect nginx.wait_healthcheck('myhost.com', timeout=5, manage_healthcheck=False) self.assertEqual(requests.get.call_count, 2) requests.get.assert_called_with('http://myhost.com:8080/_nginx_healthcheck/', timeout=2)
def test_wait_healthcheck(self, requests): nginx = Nginx() count = [0] response = mock.Mock() response.status_code = 200 response.text = 'WORKING' def side_effect(method, url, timeout, **params): count[0] += 1 if count[0] < 2: raise Exception('some error') return response requests.request.side_effect = side_effect nginx.wait_healthcheck('myhost.com', timeout=5) self.assertEqual(requests.request.call_count, 2) requests.request.assert_called_with( 'get', 'http://myhost.com:8089/healthcheck', timeout=2)
def test_wait_app_healthcheck_invalid_response(self, requests): nginx = Nginx() count = [0] response = mock.Mock() response.status_code = 200 response.text = '\nFAIL\n' def side_effect(method, url, timeout, **params): count[0] += 1 if count[0] < 2: raise Exception('some error') return response requests.request.side_effect = side_effect with self.assertRaises(NginxError): nginx.wait_healthcheck('myhost.com', timeout=5, manage_healthcheck=False) self.assertEqual(requests.request.call_count, 6) requests.request.assert_called_with( 'get', 'http://myhost.com:8080/_nginx_healthcheck/', timeout=2)