##// END OF EJS Templates
tests: add tests for c3d83238afa1 and git hook installation in general
Branko Majic -
r5466:28d9e9f0 default
parent child Browse files
Show More
@@ -9,6 +9,7 b' from kallithea.lib.vcs.backends.git impo'
9 9 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
10 10 from kallithea.lib.vcs.nodes import NodeKind, FileNode, DirNode, NodeState
11 11 from kallithea.lib.vcs.utils.compat import unittest
12 from kallithea.model.scm import ScmModel
12 13 from kallithea.tests.vcs.base import _BackendTestMixin
13 14 from kallithea.tests.vcs.conf import TEST_GIT_REPO, TEST_GIT_REPO_CLONE, get_new_dir
14 15
@@ -754,5 +755,81 b' class GitRegressionTest(_BackendTestMixi'
754 755 self.assertEqual(paths(*cs.get_nodes('bot/build/templates')), ['bot/build/templates/err.html', 'bot/build/templates/err2.html'])
755 756 self.assertEqual(paths(*cs.get_nodes('bot/templates/')), ['bot/templates/404.html', 'bot/templates/500.html'])
756 757
758
759 class GitHooksTest(unittest.TestCase):
760 """
761 Tests related to hook functionality of Git repositories.
762 """
763
764 def setUp(self):
765 # For each run we want a fresh repo.
766 self.repo_directory = get_new_dir("githookrepo")
767 self.repo = GitRepository(self.repo_directory, create=True)
768
769 # Create a dictionary where keys are hook names, and values are paths to
770 # them. Deduplicates code in tests a bit.
771 self.hook_directory = self.repo.get_hook_location()
772 self.kallithea_hooks = {h: os.path.join(self.hook_directory, h) for h in ("pre-receive", "post-receive")}
773
774 def test_hooks_created_if_missing(self):
775 """
776 Tests if hooks are installed in repository if they are missing.
777 """
778
779 for hook, hook_path in self.kallithea_hooks.iteritems():
780 if os.path.exists(hook_path):
781 os.remove(hook_path)
782
783 ScmModel().install_git_hooks(repo=self.repo)
784
785 for hook, hook_path in self.kallithea_hooks.iteritems():
786 self.assertTrue(os.path.exists(hook_path))
787
788 def test_kallithea_hooks_updated(self):
789 """
790 Tests if hooks are updated if they are Kallithea hooks already.
791 """
792
793 for hook, hook_path in self.kallithea_hooks.iteritems():
794 with open(hook_path, "w") as f:
795 f.write("KALLITHEA_HOOK_VER=0.0.0\nJUST_BOGUS")
796
797 ScmModel().install_git_hooks(repo=self.repo)
798
799 for hook, hook_path in self.kallithea_hooks.iteritems():
800 with open(hook_path) as f:
801 self.assertNotIn("JUST_BOGUS", f.read())
802
803 def test_custom_hooks_untouched(self):
804 """
805 Tests if hooks are left untouched if they are not Kallithea hooks.
806 """
807
808 for hook, hook_path in self.kallithea_hooks.iteritems():
809 with open(hook_path, "w") as f:
810 f.write("#!/bin/bash\n#CUSTOM_HOOK")
811
812 ScmModel().install_git_hooks(repo=self.repo)
813
814 for hook, hook_path in self.kallithea_hooks.iteritems():
815 with open(hook_path) as f:
816 self.assertIn("CUSTOM_HOOK", f.read())
817
818 def test_custom_hooks_forced_update(self):
819 """
820 Tests if hooks are forcefully updated even though they are custom hooks.
821 """
822
823 for hook, hook_path in self.kallithea_hooks.iteritems():
824 with open(hook_path, "w") as f:
825 f.write("#!/bin/bash\n#CUSTOM_HOOK")
826
827 ScmModel().install_git_hooks(repo=self.repo, force_create=True)
828
829 for hook, hook_path in self.kallithea_hooks.iteritems():
830 with open(hook_path) as f:
831 self.assertIn("KALLITHEA_HOOK_VER", f.read())
832
833
757 834 if __name__ == '__main__':
758 835 unittest.main()
General Comments 0
You need to be logged in to leave comments. Login now