Beispiel #1
0
def test_git_repo(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(os.path.join(test_path, 'test-git'))
    test.render(dirname, {}, {})

    assert are_dir_trees_equal(dirname,
                               os.path.join(test_path, 'test-git-result'))
Beispiel #2
0
def test_autotest(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(os.path.join(test_path, 'test-autotest'))
    test.render(dirname, {'name': 'user'}, {})

    assert are_dir_trees_equal(dirname,
                               os.path.join(test_path, 'test-autotest-result'))
Beispiel #3
0
def test_parse_config_error(tmpdir):
    conf_file = os.path.join(str(tmpdir), 'config.sq')
    with open(conf_file, 'w') as wfile:
        print('conf.d', file=wfile)

    render = template.DirectoryRender(test_path)
    with pytest.raises(ValueError) as ex:
        render.parse_config_sq(conf_file, {})

    assert ex is not None

    conf_file = os.path.join(str(tmpdir), 'config2.sq')
    with open(conf_file, 'w') as wfile:
        print('conf.d/ atomic:true mdoe:0000', file=wfile)

    with pytest.raises(ValueError) as ex:
        render.parse_config_sq(conf_file, {})

    assert ex is not None

    conf_file = os.path.join(str(tmpdir), 'config3.sq')
    with open(conf_file, 'w') as wfile:
        print('conf.d/', file=wfile)

    with pytest.raises(ValueError) as ex:
        render.parse_config_sq(conf_file, {})

    assert ex is not None
Beispiel #4
0
def test_template_with_config_dir_error(tmpdir):
    dirname = str(tmpdir)

    with pytest.raises(ValueError) as ex:
        test = template.DirectoryRender(
            os.path.join(test_path, 'config-dir-error'))
        result = test.render(dirname, {'name': 'user'}, {})
    assert ex is not None
Beispiel #5
0
def test_autotest_fail(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(os.path.join(test_path, 'test-autotest2'))

    with pytest.raises(ValueError) as ex:
        test.render(dirname, {'name': 'user'}, {})

    assert ex is not None
Beispiel #6
0
def test_template_chown_problem(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(
        os.path.join(test_path, 'test1-notpermitted'))

    with pytest.raises(OSError) as ex:
        test.render(dirname, {'name': 'user'}, {}, False)

    test.render(dirname, {'name': 'user'}, {}, True)

    assert are_dir_trees_equal(dirname, os.path.join(test_path, 'test1result'))
Beispiel #7
0
def test_git_repo_chmod(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(os.path.join(test_path, 'test-git-chmod'))
    test.render(dirname, {}, {})

    result_dir = os.path.join(test_path, 'test-git-result')
    assert are_dir_trees_equal(dirname, result_dir)

    st = os.stat(os.path.join(dirname, 'test', 'install'))
    # Chose some weird mode that wouldn't normally be set
    assert stat.S_IMODE(st.st_mode) == 0604
Beispiel #8
0
def test_ext_created_dir(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(
        os.path.join(test_path, 'test-ext-created-dir'))
    atomic = test.render(dirname, {}, {})

    assert 'testdir/' in atomic
    assert atomic['testdir/'] == True
    assert 'dir1/testdir/' in atomic
    assert atomic['dir1/testdir/'] == True

    result = os.path.join(dirname, 'testdir')
    assert os.path.isdir(result) == True
    assert len(os.listdir(result)) == 0  # Should be empty

    result = os.path.join(dirname, 'dir1', 'testdir')
    assert os.path.isdir(result) == True
    assert len(os.listdir(result)) == 0  # Should be empty
Beispiel #9
0
def test_template_with_config(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(os.path.join(test_path, 'test2'))
    result = test.render(dirname, {'name': 'user'}, {})

    assert are_dir_trees_equal(dirname, os.path.join(test_path, 'test2result'))

    assert len(result) == 3
    assert result['test2/'] == True
    assert result['test3/'] == False
    assert result['test3/atomic/'] == True

    st_file = os.stat(os.path.join(dirname, 'file'))
    assert stat.S_IMODE(st_file.st_mode) == 0642

    st_test3 = os.stat(os.path.join(dirname, 'test3'))
    assert stat.S_IMODE(st_test3.st_mode) == 0775

    st_test3_file = os.stat(os.path.join(dirname, 'test3', 'hello.txt'))
    assert stat.S_IMODE(st_test3_file.st_mode) != 0775  # not recursive
Beispiel #10
0
def test_parse_config(tmpdir):
    conf_file = os.path.join(str(tmpdir), 'config.sq')
    with open(conf_file, 'w') as wfile:
        print('# this is a comment', file=wfile)
        print('conf.d/ atomic:@atomic', file=wfile)
        print('', file=wfile)
        print('httpd.conf user:sean group:@{group.name} mode:0644', file=wfile)

    cfg = {'atomic': True, 'group': {'name': 'dudes'}}
    render = template.DirectoryRender(test_path)
    result = render.parse_config_sq(conf_file, cfg)

    assert len(result) == 2
    assert result[0].filepath == 'conf.d/'
    assert result[0].atomic == True
    assert result[0].user == None
    assert result[0].group == None
    assert result[0].mode == None

    assert result[1].filepath == 'httpd.conf'
    assert result[1].atomic == False
    assert result[1].user == 'sean'
    assert result[1].group == 'dudes'
    assert result[1].mode == '0644'
Beispiel #11
0
def test_template_basic(tmpdir):
    dirname = str(tmpdir)
    test = template.DirectoryRender(os.path.join(test_path, 'test1'))
    test.render(dirname, {'name': 'user', 'variable': 'test3'}, {})

    assert are_dir_trees_equal(dirname, os.path.join(test_path, 'test1result'))