Esempio n. 1
0
def test_dependencies():
    content = [{
        'include_role': {
            'name': 'foo'
        }
    }, {
        'import_role': {
            'name': 'bar',
            'tasks_from': 'install.yml'
        }
    }]
    task_dependencies = {RoleFactory('foo'), RoleFactory('bar', 'install.yml')}

    tasks = Tasks(content, 'irrelevant')

    assert task_dependencies == set(tasks.dependencies())
Esempio n. 2
0
def test_build_task_success(tmpdir, content, expected):
    tasks_path = tmpdir.join('roles', 'my_role', 'tasks')
    task_file = tasks_path.join('main.yml')

    tasks_path.ensure(dir=True)
    task_file.write(yaml.dump(content))

    assert expected == Tasks.build_task(str(task_file))
Esempio n. 3
0
def test_build_success(tmpdir, contents, expected_content):
    role_path = tmpdir.join('roles', 'my_role')
    tasks_path = role_path.join('tasks')
    tasks_path.ensure(dir=True)

    for (file, content) in contents.items():
        task_path = tasks_path.join(file)
        task_path.write(yaml.dump(content))

    assert expected_content == Tasks.build(role_path).content
Esempio n. 4
0
def test_build_task_success(mocker):
    content = []
    role_path = os.path.join('path', 'to', 'myrole')

    mock_build_tasks = mocker.patch('ansiblediscover.entity.role.Tasks.build')
    mock_build_tasks.return_value = Tasks(content, role_path)

    tasks = Role.build_tasks(role_path)

    assert content == tasks.content
    assert role_path == tasks.role_path
    mock_build_tasks.assert_called_with(role_path)
Esempio n. 5
0
def test_build_task_content_invalid_yaml(tmpdir):
    task_file = tmpdir.join("mytask.yml")
    task_file.write('foo: bar: baz')

    with pytest.raises(RuntimeError):
        Tasks.build_task(str(task_file))
Esempio n. 6
0
def test_build_task_content_not_a_list(tmpdir):
    task_file = tmpdir.join("mytask.yml")
    task_file.write(yaml.dump({'some': 'item'}))

    with pytest.raises(ValueError):
        Tasks.build_task(str(task_file))
Esempio n. 7
0
def test_build_task_file_not_found(tmpdir):
    task_file = tmpdir.join("mytask.yml")
    with pytest.raises(RuntimeError):
        Tasks.build_task(str(task_file))
Esempio n. 8
0
def test_main_path():
    role_path = os.path.join('my', 'custom', 'roles', 'path', 'foobar')
    assert os.path.join(role_path, 'tasks',
                        'main.yml') == Tasks.main_path(role_path)
Esempio n. 9
0
def test_task_path():
    role_path = os.path.join('my', 'custom', 'roles', 'path', 'foobar')
    assert os.path.join(role_path, 'tasks', 'install.yml') == Tasks.task_path(
        role_path, 'install.yml')
Esempio n. 10
0
def test_role_path():
    role_path = os.path.join('my', 'custom', 'roles', 'path', 'foobar')
    assert role_path == Tasks(None, role_path).role_path
Esempio n. 11
0
def test_task_includes(content, expected):
    assert set(expected) == set(Tasks.task_includes(content))