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='wunderground')

Test the utility with a blank key (log output)

    >>> wunderground = utility('')
    >>> wunderground.getWeatherInfo('Argentina/Buenos_Aires')
    Traceback (most recent call last):
        ...
    ValueError: Missing Weather Underground API key

Initialize the utility with the provider's key

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

Monkey patch _getWeatherInfo to avoid actual web service call

    >>> def _getWeatherInfo(location, units, lang):
    ...    supported_languages = ['SP', 'EN',]
    ...    if not lang in supported_languages:
    ...        lang = 'EN'
    ...    weather_infos = {
    ...        'Argentina/Buenos_Aires,C,SP': {'temperature': 18.84,
    ...                                        'summary': 'Soleado',
    ...                                        'icon': 'sunny-icon.png'},
    ...        'Argentina/Buenos_Aires,F,EN': {'temperature': 65.91,
    ...                                        'summary': 'Sunny',
    ...                                        'icon': 'sunny-icon.png'}
    ...    }
    ...    key = '{0},{1},{2}'.format(location, units, lang)
    ...    if key in weather_infos:
    ...        return weather_infos[key]
    ...    else:
    ...        return {}

    >>> wunderground._getWeatherInfo = _getWeatherInfo

Test with a known location and special lang code

    >>> info = wunderground.getWeatherInfo('Argentina/Buenos Aires', \
    ...                                    lang='es')
    >>> '%.2f' % info['temperature']  # For Python 2.6
    '18.84'
    >>> info['summary']
    'Soleado'
    >>> info['icon']
    'sunny-icon.png'

Test with a known location without unit and unknown lang code

    >>> info = wunderground.getWeatherInfo('Argentina/Buenos Aires', \
    ...                                    units='imperial', lang='XX')
    >>> '%.2f' % info['temperature']  # For Python 2.6
    '65.91'
    >>> info['summary']
    'Sunny'

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

    >>> info = wunderground.getWeatherInfo('Hogwarts/The Kitchen', \
    ...                                    units='metric')
    collective.weather - WARNING - Weather Underground api returned no information for location Hogwarts/The_Kitchen
    >>> info
    {}
