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
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
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)
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"] == ""
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)
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"
def test_git_hook_creation_exit(mocker, workspace_with_git): """create_git_hooks helper function should exit if not valid configuration file is provided""" mocked_sys_exit = mocker.patch('sys.exit') githooks_dir = os.path.join(workspace_with_git, '.git/hooks') create_git_hooks('wrong_config_file.ini', githooks_dir) mocked_sys_exit.assert_called_once_with(1)
def test_git_hook_creation_exit(mocker, workspace_with_git): """create_git_hooks helper function should exit if not valid configuration file is provided""" mocked_sys_exit = mocker.patch("sys.exit") create_git_hooks(configfile_path="wrong_config_file.ini", githooks_dir=workspace_with_git.hooks) mocked_sys_exit.assert_called_once_with(1)