Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2012-11-29 21:38:10 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2012-11-29 21:38:10 (GMT)
commit7df65ab65c28983f1792e1ac5f8326842b87ba2d (patch)
tree2133bf3a53d177866a05fe28569048b4e7dec0df /tests
parent69982ce0d1b712ccfe5797fb83721ab856ec951b (diff)
Add a devbot.git module with unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/devbot/test_git.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/devbot/test_git.py b/tests/devbot/test_git.py
new file mode 100644
index 0000000..9468814
--- /dev/null
+++ b/tests/devbot/test_git.py
@@ -0,0 +1,106 @@
+import os
+import tempfile
+import unittest
+import subprocess
+
+from devbot import git
+
+class TestGit(unittest.TestCase):
+ def _create_repo(self):
+ path = tempfile.mkdtemp()
+ os.chdir(path)
+
+ subprocess.check_call(["git", "init"])
+
+ with open("README", "w") as f:
+ f.write("")
+
+ subprocess.check_call(["git", "add", "README"])
+
+ self._commit(path, "Initial commit")
+
+ return path
+
+ def _commit(self, remote, log):
+ os.chdir(remote)
+ subprocess.check_call(["git", "commit", "-a", "-m", log])
+
+ def _get_head(self, remote):
+ os.chdir(remote)
+ return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
+
+ def _read_file(self, module):
+ content = None
+
+ f = open(os.path.join(module.local, "README"))
+ content = f.read()
+ f.close()
+
+ return content
+
+ def _create_branch(self, remote, name):
+ os.chdir(remote)
+ subprocess.check_call(["git", "checkout", "-b", name])
+
+ def _write_file(self, remote, content):
+ f = open(os.path.join(remote, "README"), "w")
+ f.write(content)
+ f.close()
+
+ def _create_module(self, remote, branch="master", tag=None):
+ path = tempfile.mkdtemp()
+ name = "test"
+
+ return git.Module(path, name, remote, branch, tag)
+
+ def _setup_module(self):
+ remote = self._create_repo()
+
+ module = self._create_module(remote)
+ module.update()
+
+ return module
+
+ def test_clone(self):
+ module = self._setup_module()
+ self.assertTrue(os.path.exists(os.path.join(module.local, "README")))
+
+ def test_update_on_master(self):
+ module = self._setup_module()
+
+ self._write_file(module.remote, "masterchange")
+ self._commit(module.remote, "masterchange")
+
+ module.update()
+
+ self.assertEquals("masterchange", self._read_file(module))
+
+ def test_update_on_branch(self):
+ remote = self._create_repo()
+ self._create_branch(remote, "test")
+
+ module = self._create_module(remote, branch="test")
+
+ self._write_file(module.remote, "branchchange")
+ self._commit(module.remote, "branchchange")
+
+ module.update()
+
+ self.assertEquals("branchchange", self._read_file(module))
+
+ def test_update_detached(self):
+ remote = self._create_repo()
+
+ module = self._create_module(remote, tag=self._get_head(remote))
+ module.update()
+
+ self._write_file(module.remote, "detachedchange")
+ self._commit(module.remote, "detachedchange")
+
+ module.tag = self._get_head(remote)
+ module.update()
+
+ self.assertEquals("detachedchange", self._read_file(module))
+
+if __name__ == '__main__':
+ unittest.main()