def test_moduleload_with_branch(): """ Test if branch gets updated """ mock_logger = mock.MagicMock() expected_mod = { 'roles': { 'ref': 'new_branch', 'url': 'https://github.com/vision-it/puppet-roles.git' } } directory = os.path.dirname(os.path.realpath(__file__)) ml = postrun.ModuleLoader(dir_path=directory, logger=mock_logger, environment='', module='roles', branch='new_branch', location='default') loaded_mod = ml.get_modules() assert (loaded_mod == expected_mod)
def test_moduleloader_no_file(): """ Test if empty dict is returned if no modules.yaml is available """ mock_logger = mock.MagicMock() ml = postrun.ModuleLoader(dir_path='/foobar', logger=mock_logger) loaded_mod = ml.get_modules() assert (loaded_mod == {})
def test_ModulesLoader_no_modulesyaml(mock_isfile, mock_logger, capfd): """ Test output with no modules.yaml """ ml = postrun.ModuleLoader(dir_path='/tmp', logger=mock_logger, environment='staging', location='some_loc') ml.load_modules_file() out, err = capfd.readouterr() assert ( out == '[ERROR]: /tmp/staging/modules.yaml not found for staging\n')
def test_moduleload_with_foobar_location(module): """ Test if default location gets loaded """ mock_logger = mock.MagicMock() expected_mod = module directory = os.path.dirname(os.path.realpath(__file__)) ml = postrun.ModuleLoader(dir_path=directory, logger=mock_logger, environment='', location='foobar_loc') loaded_mod = ml.get_modules() assert (loaded_mod == expected_mod)
def test_ModulesLoader_no_module(mock_logger, capfd): """ Test outwith with nonexisting module """ directory = os.path.dirname(os.path.realpath(__file__)) ml = postrun.ModuleLoader(dir_path=directory, logger=mock_logger, environment='', module='foobar', branch='new_branch', location='default') ml.get_modules() out, err = capfd.readouterr() assert (out == '[ERROR]: Module foobar not found in configuration\n')
def test_ModulesLoader_using_default(mock_isfile, mock_logger, capfd): """ Test output with default location """ ml = postrun.ModuleLoader(dir_path='/tmp', logger=mock_logger, environment='staging', location='some_loc') ml.load_modules_file = mock.MagicMock() ml.load_modules_file.return_value = {} ml.load_modules_from_yaml() out, err = capfd.readouterr() assert ( out == '[INFO]: configuration for location some_loc not found, using default\n' )
def test_moduleload_with_real_location(): """ Test if real location gets loaded """ mock_logger = mock.MagicMock() expected_mod = { 'other_mod': { 'ref': 'master', 'url': 'https://github.com/vision-it/puppet-roles.git' } } directory = os.path.dirname(os.path.realpath(__file__)) ml = postrun.ModuleLoader(dir_path=directory, logger=mock_logger, environment='', location='real_loc') loaded_mod = ml.get_modules() assert (loaded_mod == expected_mod)