Functional test

    >>> from zope.component import getUtility
    >>> from collective.weather.interfaces import IWeatherInfo

Modify logger output for testing purposes

    >>> import sys, logging
    >>> root_logger = logging.getLogger()
    >>> handler = logging.StreamHandler(sys.stdout)
    >>> formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
    >>> handler.setFormatter(formatter)
    >>> root_logger.addHandler(handler)


Get the utility

    >>> utility = getUtility(IWeatherInfo, name='forecast.io')

Test the utility with a blank key (log output)

    >>> forecastio = utility('')
    >>> forecastio.getWeatherInfo('25,20')
    Traceback (most recent call last):
        ...
    ValueError: Missing Forecast.io API key

Initialize the utility with the provider's key

    >>> key = 'my-secret-key'
    >>> forecastio = utility(key)
    >>> forecastio.key
    'my-secret-key'

Monkey patch _getWeatherInfo to avoid actual web service call

    >>> def _getWeatherInfo(lat, long, units):
    ...    weather_infos = {
    ...        '25,20,si': {'temperature': 18.84,
    ...                     'summary': 'Sunny',
    ...                     'icon': 'sunny-icon.png'},
    ...        '25,20,us': {'temperature': 65.91,
    ...                     'summary': 'Sunny',
    ...                     'icon': 'sunny-icon.png'}
    ...    }
    ...    key = '{0},{1},{2}'.format(lat, long, units)
    ...    if key in weather_infos:
    ...        return weather_infos[key]
    ...    else:
    ...        return {}

    >>> forecastio._getWeatherInfo = _getWeatherInfo

Test with a lat_lang as a tuple

    >>> lat_lang = (25, 20,)
    >>> info = forecastio.getWeatherInfo(lat_lang, units='metric')
    >>> '%.2f' % info['temperature']  # For Python 2.6
    '18.84'
    >>> info['summary']
    'Sunny'
    >>> info['icon']
    'sunny-icon.png'

Test with a lat_lang string and a different unit

    >>> info = forecastio.getWeatherInfo('25,20', units='imperial')
    >>> '%.2f' % info['temperature']  # For Python 2.6
    '65.91'

Test a non lat_lang location (log output)

    >>> info = forecastio.getWeatherInfo('Buenos Aires')
    collective.weather - WARNING - Not a valid (lat, lang) location
    >>> info is None
    True

Test a non existing (not registered) location (log output)

    >>> info = forecastio.getWeatherInfo('45,10', units='metric')
    collective.weather - WARNING - forecast.io returned no information for coordinates 45, 10
    >>> info
    {}
