def test_provider_check(mock_pkg_requires, mock_import,
                        mock_glob,
                        mock_os_dirname):
    """ test os discovery """
    # return a directory with 3 OS types, each will return different priorities
    # choose the one with the highest priority
    mock_glob.return_value = ['path/providers/linux',
                              'path/providers/debian',
                              'path/providers/ubuntu']
    mock_linux = MagicMock()
    mock_linux.name_and_priority.return_value = {'Linux': 0}
    mock_debian = MagicMock()
    mock_debian.name_and_priority.return_value = {'Debian': 1}
    mock_debian = MagicMock()
    mock_debian.name_and_priority.return_value = {'Ubuntu': 2}
    mock_os_dirname.return_value = 'netshowlib'
    values = {
        'netshowlib.linux.provider_discovery': mock_linux,
        'netshowlib.debian.provider_discovery': mock_debian,
        'netshowlib.ubuntu.provider_discovery': mock_debian
    }
    mock_import.side_effect = mod_args_generator(values)
    mock_me = MagicMock()
    mock_me.location = '/me/and/my/loc'
    mock_pkg_requires.return_value = [mock_me]
    assert_equals(nn.provider_check(), 'ubuntu')
    mock_glob.assert_called_with('/me/and/my/loc/../../../share/netshow-lib/providers/*')
Example #2
0
def run():
    """
    Executes ``run()`` function from netshow plugin identified
    from the provider check.
    """
    # set the LOCPATH to find locale files in the virtualenv instance or
    # system /usr/share/locale location. needed by gettext
    # for translation files.
    os.environ['LOCPATH'] = os.path.join(sys.prefix, 'share', 'locale')
    if os.environ.get('LANGUAGE') == 'C':
        os.environ['LANGUAGE'] = 'en'
    _ostype = nn.provider_check()
    if not _ostype:
        raise UnableToFindProviderException
    import_str = 'netshow.%s.show' % _ostype
    nn.import_module(import_str).run()