def test_uninstall_commit_msg_hook(isdir, path_exists, remove): lint_config = LintConfig(target="/foo/bar") read_data = "#!/bin/sh\n" + GITLINT_HOOK_IDENTIFIER with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True): GitHookInstaller.uninstall_commit_msg_hook(lint_config) expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH) isdir.assert_called_once_with('/foo/bar/.git/hooks') path_exists.assert_called_once_with(expected_dst) remove.assert_called_once_with(expected_dst)
def test_uninstall_commit_msg_hook(isdir, path_exists, remove): lint_config = LintConfig() lint_config.target = u"/foo/bår" read_data = "#!/bin/sh\n" + GITLINT_HOOK_IDENTIFIER with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True): GitHookInstaller.uninstall_commit_msg_hook(lint_config) expected_dst = os.path.join(u"/foo/bår", COMMIT_MSG_HOOK_DST_PATH) isdir.assert_called_with(os.path.join(u"/foo/bår", '.git/hooks')) path_exists.assert_called_once_with(expected_dst) remove.assert_called_with(expected_dst)
def test_uninstall_commit_msg_hook(git_hooks_dir, isdir, path_exists, remove): lint_config = LintConfig() git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git", "hooks") lint_config.target = os.path.join(u"/hür", u"dur") read_data = "#!/bin/sh\n" + GITLINT_HOOK_IDENTIFIER with patch('gitlint.hooks.io.open', mock_open(read_data=read_data), create=True): GitHookInstaller.uninstall_commit_msg_hook(lint_config) expected_dst = os.path.join(git_hooks_dir.return_value, COMMIT_MSG_HOOK_DST_PATH) isdir.assert_called_with(git_hooks_dir.return_value) path_exists.assert_called_once_with(expected_dst) remove.assert_called_with(expected_dst) git_hooks_dir.assert_called_with(lint_config.target)
def test_uninstall_commit_msg_hook_negative(self, isdir, path_exists, remove): lint_config = LintConfig() lint_config.target = u"/foo/bår" # mock that the current directory is not a git repo isdir.return_value = False expected_msg = u"{0} is not a git repository".format(u"/foo/bår") with self.assertRaisesRegex(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) isdir.assert_called_with(os.path.join(u"/foo/bår", '.git/hooks')) path_exists.assert_not_called() remove.assert_not_called() # mock that there is no commit hook present isdir.return_value = True path_exists.return_value = False expected_dst = os.path.join(u"/foo/bår", COMMIT_MSG_HOOK_DST_PATH) expected_msg = u"There is no commit-msg hook present in {0}.".format(expected_dst) with self.assertRaisesRegex(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) isdir.assert_called_with(os.path.join(u"/foo/bår", '.git/hooks')) path_exists.assert_called_once_with(expected_dst) remove.assert_not_called() # mock that there is a different (=not gitlint) commit hook isdir.return_value = True path_exists.return_value = True read_data = "#!/bin/sh\nfoo" expected_dst = os.path.join(u"/foo/bår", COMMIT_MSG_HOOK_DST_PATH) expected_msg = u"The commit-msg hook in {0} was not installed by gitlint ".format(expected_dst) + \ r"\(or it was modified\).\nUninstallation of 3th party or modified gitlint hooks " + \ "is not supported." with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True): with self.assertRaisesRegex(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) remove.assert_not_called()
def test_uninstall_commit_msg_hook_negative(self, isdir, path_exists, remove): lint_config = LintConfig() lint_config.target = self.SAMPLES_DIR # mock that the current directory is not a git repo isdir.return_value = False expected_msg = "{0} is not a git repository".format(self.SAMPLES_DIR) with self.assertRaisesRegex(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) isdir.assert_called_with(os.path.join(self.SAMPLES_DIR, '.git/hooks')) path_exists.assert_not_called() remove.assert_not_called() # mock that there is no commit hook present isdir.return_value = True path_exists.return_value = False expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH) expected_msg = "There is no commit-msg hook present in {0}.".format(expected_dst) with self.assertRaisesRegex(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) isdir.assert_called_with(os.path.join(self.SAMPLES_DIR, '.git/hooks')) path_exists.assert_called_once_with(expected_dst) remove.assert_not_called() # mock that there is a different (=not gitlint) commit hook isdir.return_value = True path_exists.return_value = True read_data = "#!/bin/sh\nfoo" expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH) expected_msg = "The commit-msg hook in {0} was not installed by gitlint ".format(expected_dst) + \ r"\(or it was modified\).\nUninstallation of 3th party or modified gitlint hooks " + \ "is not supported." with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True): with self.assertRaisesRegex(GitHookInstallerError, expected_msg): GitHookInstaller.uninstall_commit_msg_hook(lint_config) remove.assert_not_called()