示例#1
0
def test_execute_list_collection_specific_duplicate(mocker, capsys,
                                                    mock_collection_objects,
                                                    mock_from_path):
    """Test listing a specific collection that exists at multiple paths"""

    collection_name = 'sandwiches.pbj'
    mock_from_path(collection_name)

    cliargs(collection_name=collection_name)
    mocker.patch('os.path.exists', path_exists)
    mocker.patch('os.path.isdir', return_value=True)
    mocker.patch('assible.galaxy.collection.validate_collection_name',
                 collection_name)

    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list', collection_name])
    gc.execute_list_collection()

    out, err = capsys.readouterr()
    out_lines = out.splitlines()

    assert len(out_lines) == 10
    assert out_lines[0] == ''
    assert out_lines[1] == '# /root/.assible/collections/assible_collections'
    assert out_lines[2] == 'Collection     Version'
    assert out_lines[3] == '-------------- -------'
    assert out_lines[4] == 'sandwiches.pbj 1.5.0  '
    assert out_lines[5] == ''
    assert out_lines[
        6] == '# /usr/share/assible/collections/assible_collections'
    assert out_lines[7] == 'Collection     Version'
    assert out_lines[8] == '-------------- -------'
    assert out_lines[9] == 'sandwiches.pbj 1.0.0  '
示例#2
0
def test_execute_list_collection_one_invalid_path(mocker, capsys,
                                                  mock_collection_objects):
    """Test listing all collections when one invalid path is given"""

    cliargs()
    mocker.patch('os.path.exists', return_value=True)
    mocker.patch('os.path.isdir', isdir)
    mocker.patch('assible.cli.galaxy.GalaxyCLI._resolve_path',
                 side_effect=['/root/.assible/collections', 'nope'])
    mocker.patch('assible.utils.color.ASSIBLE_COLOR', False)

    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list', '-p', 'nope'])
    gc.execute_list_collection()

    out, err = capsys.readouterr()
    out_lines = out.splitlines()

    assert out_lines[0] == ''
    assert out_lines[1] == '# /root/.assible/collections/assible_collections'
    assert out_lines[2] == 'Collection        Version'
    assert out_lines[3] == '----------------- -------'
    assert out_lines[4] == 'sandwiches.pbj    1.5.0  '
    # Only a partial test of the output

    assert err == '[WARNING]: - the configured path nope, exists, but it is not a directory.\n'
示例#3
0
def test_execute_list_collection_specific(mocker, capsys,
                                          mock_collection_objects,
                                          mock_from_path):
    """Test listing a specific collection"""

    collection_name = 'sandwiches.ham'
    mock_from_path(collection_name)

    cliargs(collection_name=collection_name)
    mocker.patch('os.path.exists', path_exists)
    mocker.patch('os.path.isdir', return_value=True)
    mocker.patch('assible.galaxy.collection.validate_collection_name',
                 collection_name)
    mocker.patch('assible.cli.galaxy._get_collection_widths',
                 return_value=(14, 5))

    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list', collection_name])
    gc.execute_list_collection()

    out, err = capsys.readouterr()
    out_lines = out.splitlines()

    assert len(out_lines) == 5
    assert out_lines[0] == ''
    assert out_lines[
        1] == '# /usr/share/assible/collections/assible_collections'
    assert out_lines[2] == 'Collection     Version'
    assert out_lines[3] == '-------------- -------'
    assert out_lines[4] == 'sandwiches.ham 1.0.0  '
示例#4
0
def test_execute_list_collection_all(mocker, capsys, mock_collection_objects):
    """Test listing all collections from multiple paths"""

    cliargs()

    mocker.patch('os.path.exists', return_value=True)
    mocker.patch('os.path.isdir', return_value=True)
    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list'])
    gc.execute_list_collection()

    out, err = capsys.readouterr()
    out_lines = out.splitlines()

    assert len(out_lines) == 12
    assert out_lines[0] == ''
    assert out_lines[1] == '# /root/.assible/collections/assible_collections'
    assert out_lines[2] == 'Collection        Version'
    assert out_lines[3] == '----------------- -------'
    assert out_lines[4] == 'sandwiches.pbj    1.5.0  '
    assert out_lines[5] == 'sandwiches.reuben 2.5.0  '
    assert out_lines[6] == ''
    assert out_lines[
        7] == '# /usr/share/assible/collections/assible_collections'
    assert out_lines[8] == 'Collection     Version'
    assert out_lines[9] == '-------------- -------'
    assert out_lines[10] == 'sandwiches.ham 1.0.0  '
    assert out_lines[11] == 'sandwiches.pbj 1.0.0  '
示例#5
0
def test_execute_list_collection_specific_invalid_fqcn(mocker):
    """Test an invalid fully qualified collection name (FQCN)"""

    collection_name = 'no.good.name'

    cliargs(collection_name=collection_name)
    mocker.patch('os.path.exists', return_value=True)
    mocker.patch('os.path.isdir', return_value=True)

    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list', collection_name])
    with pytest.raises(AssibleError, match='Invalid collection name'):
        gc.execute_list_collection()
示例#6
0
def test_execute_list_collection_called(mocker):
    """Make sure the correct method is called for a collection"""

    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list'])
    context.CLIARGS._store = {'type': 'collection'}
    execute_list_role_mock = mocker.patch('assible.cli.galaxy.GalaxyCLI.execute_list_role', side_effect=AttributeError('raised intentionally'))
    execute_list_collection_mock = mocker.patch('assible.cli.galaxy.GalaxyCLI.execute_list_collection', side_effect=AttributeError('raised intentionally'))
    with pytest.raises(AttributeError):
        gc.execute_list()

    assert execute_list_role_mock.call_count == 0
    assert execute_list_collection_mock.call_count == 1
def call_galaxy_cli(args):
    orig = co.GlobalCLIArgs._Singleton__instance
    co.GlobalCLIArgs._Singleton__instance = None
    try:
        GalaxyCLI(args=['assible-galaxy', 'collection'] + args).run()
    finally:
        co.GlobalCLIArgs._Singleton__instance = orig
示例#8
0
def test_execute_list_collection_no_valid_paths(mocker, capsys):
    """Test listing collections when no valid paths are given"""

    cliargs()

    mocker.patch('os.path.exists', return_value=True)
    mocker.patch('os.path.isdir', return_value=False)
    mocker.patch('assible.utils.color.ASSIBLE_COLOR', False)
    mocker.patch('assible.cli.galaxy.display.columns', 79)
    gc = GalaxyCLI(['assible-galaxy', 'collection', 'list'])

    with pytest.raises(AssibleOptionsError,
                       match=r'None of the provided paths were usable.'):
        gc.execute_list_collection()

    out, err = capsys.readouterr()

    assert '[WARNING]: - the configured path' in err
    assert 'exists, but it\nis not a directory.' in err