def test_unknown_service(): mock_stats_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'haproxy_stats.csv') with open(mock_stats_path, 'rb') as fd: with mock.patch('urllib.request.urlopen', return_value=fd), mock.patch( 'nerve_tools.updown_service.get_my_ip_address', return_value='127.0.0.1'), mock.patch('sys.exit') as mock_exit: updown_service.check_haproxy_state('unknown_service', True) mock_exit.assert_called_once_with(1)
def test_unknown_service(): mock_stats_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'haproxy_stats.csv') with open(mock_stats_path) as fd: with contextlib.nested( mock.patch('urllib2.urlopen', return_value=fd), mock.patch('nerve_tools.updown_service.get_my_ip_address', return_value='127.0.0.1'), mock.patch('sys.exit')) as (_, _, mock_exit): updown_service.check_haproxy_state('unknown_service', True) mock_exit.assert_called_once_with(1)
def test_check_haproxy_state(): tests = [ # Up ['10.0.0.1', 'up', True], ['10.0.0.1', 'down', False], # Down ['10.0.0.2', 'up', False], ['10.0.0.2', 'down', True], # Maintenance ['10.0.0.3', 'up', False], ['10.0.0.3', 'down', True], # Missing ['10.0.0.4', 'up', False], ['10.0.0.4', 'down', True], ] mock_stats_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'haproxy_stats.csv') for test in tests: my_ip_address, expected_state, expected_result = test with open(mock_stats_path, 'rb') as fd: with mock.patch('urllib.request.urlopen', return_value=fd), mock.patch( 'nerve_tools.updown_service.get_my_ip_address', return_value=my_ip_address): actual_result = updown_service.check_haproxy_state( 'service_three.main', expected_state) assert actual_result == expected_result, test
def test_check_haproxy_state(): tests = [ # Up ['10.0.0.1', 'up', True], ['10.0.0.1', 'down', False], # Down ['10.0.0.2', 'up', False], ['10.0.0.2', 'down', True], # Maintenance ['10.0.0.3', 'up', False], ['10.0.0.3', 'down', True], # Missing ['10.0.0.4', 'up', False], ['10.0.0.4', 'down', True], ] mock_stats_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'haproxy_stats.csv') for test in tests: my_ip_address, expected_state, expected_result = test with open(mock_stats_path) as fd: with contextlib.nested( mock.patch('urllib2.urlopen', return_value=fd), mock.patch('nerve_tools.updown_service.get_my_ip_address', return_value=my_ip_address)): actual_result = updown_service.check_haproxy_state( 'service_three.main', expected_state) assert actual_result == expected_result, test