예제 #1
0
def test_mode_ensures_mode_for_directories(root):
    path = "path"
    os.makedirs("work/mycomponent/path")
    mode = Mode(path, mode=0o000)
    root.component += mode
    root.component.deploy()
    assert S_IMODE(os.stat(mode.path).st_mode) == 0o000

    mode.mode = 0o777
    root.component.deploy()
    assert S_IMODE(os.stat(mode.path).st_mode) == 0o777
    assert mode.changed

    root.component.deploy()
    assert not mode.changed
예제 #2
0
def test_mode_ensures_mode_for_files(root):
    path = "path"
    open("work/mycomponent/" + path, "w").close()
    mode = Mode(path, mode=0o000)
    root.component += mode
    root.component.deploy()
    assert S_IMODE(os.stat(mode.path).st_mode) == 0o000

    mode.mode = 0o777
    root.component.deploy()
    assert S_IMODE(os.stat(mode.path).st_mode) == 0o777
    assert mode.changed

    root.component.deploy()
    assert not mode.changed
예제 #3
0
def test_mode_converts_to_numeric(root):
    path = "path"
    open("work/mycomponent/" + path, "w").close()

    with pytest.raises(batou.ConfigurationError) as e:
        mode = Mode(path)
        root.component += mode
    assert str(
        e.value) == '`mode` is required and `None` is not a valid value.`'

    mode = Mode(path, mode='rwx------')
    root.component += mode
    assert mode.mode == 0o700

    mode = Mode(path, mode='500')
    root.component += mode
    assert mode.mode == 0o500
예제 #4
0
def test_mode_ensures_mode_for_symlinks(root):
    # This test is only relevant on platforms that support managing the mode of
    # symlinks.
    link_to = "link_to"
    open(link_to, "w").close()
    os.symlink(link_to, "work/mycomponent/path")
    mode = Mode("path", mode=0o000)
    root.component += mode
    root.component.deploy()
    assert S_IMODE(os.lstat("work/mycomponent/path").st_mode) == 0o000

    mode.mode = 0o777
    root.component.deploy()
    assert S_IMODE(os.lstat("work/mycomponent/path").st_mode) == 0o777
    assert mode.changed

    root.component.deploy()
    assert not mode.changed
예제 #5
0
def test_mode_does_not_break_on_platforms_without_lchmod(root):
    # This test is only relevant on platforms without lchmod. We basically
    # ensure that deploying the component doesn't break but it's a noop
    # anyway.
    path = "path"
    link_to = "link_to"
    open(link_to, "w").close()
    mode = Mode(path, mode=0o000)
    root.component += mode
    os.symlink(link_to, mode.path)
    root.component.deploy()
예제 #6
0
def test_mode_verifies_for_nonexistent_file(root):
    mode = Mode("asdf", mode=0o000)
    with pytest.raises(AssertionError):
        mode.verify()