Example #1
0
def test_git_hook_creation_permissions(workspace_with_git):
    """create_git_hooks helper function should create hooks files with correct permissions"""
    githooks_dir = os.path.join(workspace_with_git, '.git/hooks')
    configfile_path = os.path.join(workspace_with_git, '.githooks.ini')
    create_config_file(configfile_path=configfile_path)
    create_git_hooks(configfile_path, githooks_dir)
    assert os.access(os.path.join(githooks_dir, 'pre-commit'), os.X_OK) is True
Example #2
0
def test_git_hook_creation_permissions(workspace_with_git):
    """create_git_hooks helper function should create hooks files with correct permissions"""
    create_config_file(configfile_path=workspace_with_git.config)
    create_git_hooks(configfile_path=workspace_with_git.config,
                     githooks_dir=workspace_with_git.hooks)
    for hook_name in AVAILABLE_HOOKS:
        assert os.access(os.path.join(workspace_with_git.hooks, hook_name),
                         os.X_OK)
Example #3
0
def test_git_hook_creation(workspace_with_git):
    """create_git_hooks helper function should create hooks files in the git hook folder"""
    githooks_dir = os.path.join(workspace_with_git, '.git/hooks')
    assert os.path.isfile(os.path.join(githooks_dir, 'pre-commit')) is False
    configfile_path = os.path.join(workspace_with_git, '.githooks.ini')
    create_config_file(configfile_path=configfile_path)
    create_git_hooks(configfile_path, githooks_dir)
    assert os.path.isfile(os.path.join(githooks_dir, 'pre-commit')) is True
Example #4
0
def test_config_file_default_values(workspace_without_git):
    """create_config_file helper function should create file with defaults values"""
    create_config_file(configfile_path=workspace_without_git.config)
    config = ConfigParser()
    config.read(workspace_without_git.config)
    assert config.sections() == sorted(AVAILABLE_HOOKS)
    assert config["pre-commit"]["command"] == DEFAULT_COMMANDS.get(
        "pre-commit")
Example #5
0
def test_config_file_default_values(workspace_without_git):
    """create_config_file helper function should create file with defaults values"""
    configfile_path = os.path.join(workspace_without_git, '.githooks.ini')
    create_config_file(configfile_path=configfile_path)
    config = ConfigParser()
    config.read(configfile_path)
    assert config.sections() == ['pre-commit']
    assert config['pre-commit'][
        'command'] == 'echo Pre commit hook installed. Replace this line with your own command'
Example #6
0
def test_git_hook_creation_preservation(workspace_with_git):
    """create_git_hooks helper function should preserve valid existing hook values"""
    with open(os.path.join(workspace_with_git.hooks, "pre-commit"), "w") as f:
        f.write("echo successfully preserved")
    with open(os.path.join(workspace_with_git.hooks, "post-commit"), "w") as f:
        f.write("githooks donotkeep")

    create_config_file(configfile_path=workspace_with_git.config)
    create_git_hooks(configfile_path=workspace_with_git.config,
                     githooks_dir=workspace_with_git.hooks)
    config = ConfigParser()
    config.read(workspace_with_git.config)
    assert config["pre-commit"]["command"] == "echo successfully preserved"
    assert config["post-commit"]["command"] == ""
Example #7
0
def test_git_hook_creation(workspace_with_git):
    """create_git_hooks helper function should create hooks files in the git hook folder"""
    for hook_name in AVAILABLE_HOOKS:
        assert not os.path.isfile(
            os.path.join(workspace_with_git.hooks, hook_name))

    create_config_file(configfile_path=workspace_with_git.config)
    create_git_hooks(configfile_path=workspace_with_git.config,
                     githooks_dir=workspace_with_git.hooks)

    for hook_name in AVAILABLE_HOOKS:
        assert os.path.isfile(os.path.join(workspace_with_git.hooks,
                                           hook_name))
        with open(os.path.join(workspace_with_git.hooks, hook_name), "r") as f:
            assert f.read() == "githooks {}".format(hook_name)
Example #8
0
def test_git_hook_deletion_preservation(workspace_with_git):
    """delete_git_hooks helper function should preserve valid existing hook values"""
    with open(os.path.join(workspace_with_git.hooks, "pre-commit"), "w") as f:
        f.write("echo successfully preserved")
    with open(os.path.join(workspace_with_git.hooks, "post-commit"), "w") as f:
        f.write("githooks donotkeep")

    create_config_file(configfile_path=workspace_with_git.config)
    create_git_hooks(configfile_path=workspace_with_git.config,
                     githooks_dir=workspace_with_git.hooks)
    with open(os.path.join(workspace_with_git.hooks, "post-commit"), "w") as f:
        f.write("echo also keep this new command")

    delete_git_hooks(configfile_path=workspace_with_git.config,
                     githooks_dir=workspace_with_git.hooks)
    with open(os.path.join(workspace_with_git.hooks, "pre-commit"), "r") as f:
        assert f.read() == "echo successfully preserved"
    with open(os.path.join(workspace_with_git.hooks, "post-commit"), "r") as f:
        assert f.read() == "echo also keep this new command"
Example #9
0
def test_config_file_creation(workspace_without_git):
    """create_config_file helper function should create file"""
    configfile_path = os.path.join(workspace_without_git, '.githooks.ini')
    create_config_file(configfile_path=configfile_path)
    assert os.path.isfile(configfile_path)
Example #10
0
def test_config_file_creation(workspace_without_git):
    """create_config_file helper function should create file"""
    create_config_file(configfile_path=workspace_without_git.config)
    assert os.path.isfile(workspace_without_git.config)
Example #11
0
def workspace_with_config(workspace_with_git):
    create_config_file(__GITHOOKS_CONFIGFILE_PATH__)
    yield __PATHS__
    os.remove(__GITHOOKS_CONFIGFILE_PATH__)