def test_request_fail_response_error(mock_logging, mock_request):
    """Test unexpected return value"""
    mock_request.return_value = _get_error_response()
    result = gce.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    msg = '\tMessage: Test server failure'
    mock_logging.warning.assert_called_with(msg)
def test_request_fail_parse_response(mock_logging, mock_request):
    """Test unexpected return value"""
    mock_request.return_value = _get_unexpected_response()
    result = gce.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    msg = 'Unable to form region string from text: '
    msg += 'projects/284177885636/zones/us-central1'
    mock_logging.warning.assert_called_with(msg)
def test_request_fail(mock_logging, mock_request):
    """Test proper exception handling when request to metadata server fails"""
    mock_request.side_effect = Exception
    result = gce.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    msg = 'Unable to determine zone information from "'
    msg += 'http://169.254.169.254/computeMetadata/v1/instance/zone'
    msg += '"'
    mock_logging.warning.assert_called_with(msg)
def test_request_succeed(mock_request):
    """Test behavior with expected return value"""
    mock_request.return_value = _get_expected_response()
    result = gce.generateRegionSrvArgs()
    assert 'regionHint=us-central1' == result