[damned-lies] Add more test coverage for checkout process and fix discovered errors



commit 382363999c6431d8f2fe097eb11b8fc70d570859
Author: Claude Paroz <claude 2xlibre net>
Date:   Sun Oct 7 21:57:22 2018 +0200

    Add more test coverage for checkout process and fix discovered errors
    
    Fixes #108.

 stats/repos.py       |  6 +++---
 stats/tests/tests.py | 13 ++++++++-----
 2 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/stats/repos.py b/stats/repos.py
index bc8f09df..8d3d6fa6 100644
--- a/stats/repos.py
+++ b/stats/repos.py
@@ -49,9 +49,9 @@ class GitRepo(RepoBase):
 
     def init_checkout(self):
         # We are assuming here that master is the first branch created
-        if self.name == "master":
+        if self.branch.name == "master":
             commands = [
-                ['git', 'clone', self.branch.module.vcs_root, self.branch.co_path.parent],
+                ['git', 'clone', self.branch.module.vcs_root, str(self.branch.co_path.parent)],
                 ['git', 'remote', 'update'],
                 ['git', 'checkout', self.branch.name],
             ]
@@ -64,7 +64,7 @@ class GitRepo(RepoBase):
         commands.append("if [ -e .gitmodules ]; then git submodule update --init; fi")
         for cmd in commands:
             working_dir = self.branch.co_path.parent if 'clone' in cmd else self.branch.co_path
-            run_shell_command(command, raise_on_error=True, cwd=working_dir)
+            run_shell_command(cmd, raise_on_error=True, cwd=working_dir)
 
     def update(self):
         # test "git checkout %(branch)s && git clean -dfq && git pull origin/%(branch)s"?
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index ec160aa4..4ff3ce14 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -55,7 +55,6 @@ class ModuleTestCase(TestCase):
 
     def setUp(self):
         Branch.checkout_on_creation = False
-        Branch.checkout = mocked_checkout
         self.mod = Module.objects.get(name="gnome-hello")
         self.branch = self.mod.branch_set.get(name="master")
 
@@ -131,7 +130,8 @@ class ModuleTestCase(TestCase):
         lang = Language.objects.create(name='xxx', locale='xxx')
         ghost_stat = Statistics.objects.create(branch=self.branch, 
domain=self.mod.domain_set.get(name='po'), language=lang)
         # Check stats
-        self.branch.update_stats(force=True)
+        with patch_shell_command(only=['git ']):
+            self.branch.update_stats(force=True)
         fr_po_stat = Statistics.objects.get(branch=self.branch, domain__name='po', language__locale='fr')
         self.assertEqual(fr_po_stat.translated(), 44)
         self.assertEqual(fr_po_stat.translated(scope='part'), 44)
@@ -191,7 +191,8 @@ class ModuleTestCase(TestCase):
     def test_create_unexisting_branch(self):
         """ Try to create a non-existing branch """
         Branch.checkout_on_creation = True
-        branch = Branch(name="trunk2", module = self.mod)
+        Branch.checkout = mocked_checkout
+        branch = Branch(name="trunk2", module=self.mod)
         self.assertRaises(ValidationError, branch.clean)
 
     def test_edit_branches_form(self):
@@ -248,7 +249,8 @@ class ModuleTestCase(TestCase):
     def test_string_frozen_mail(self):
         """ String change for a module of a string_frozen release should generate a message """
         mail.outbox = []
-        self.branch.update_stats(force=False)
+        with patch_shell_command(only=['git ']):
+            self.branch.update_stats(force=False)
 
         # Create a new file with translation
         new_file_path = self.branch.co_path / "dummy_file.py"
@@ -270,7 +272,8 @@ class ModuleTestCase(TestCase):
     def test_dynamic_po(self):
         """ Test the creation of a blank po file for a new language """
         tamil = Language.objects.create(name="Tamil", locale="ta")
-        self.branch.update_stats(force=False) # At least POT stats needed
+        with patch_shell_command(only=['git ']):
+            self.branch.update_stats(force=False) # At least POT stats needed
         pot_stats = Statistics.objects.get(
             branch=self.branch, domain__name='po', language__isnull=True
         )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]