[damned-lies] Add test for commit_po method
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Add test for commit_po method
- Date: Thu, 6 Feb 2014 15:16:38 +0000 (UTC)
commit 3e8b365d4fd94ad740a36d81ad81fcd0b43da993
Author: Claude Paroz <claude 2xlibre net>
Date: Thu Feb 6 15:51:18 2014 +0100
Add test for commit_po method
stats/tests/tests.py | 39 +++++++++++++++++++++++++++++++++++++--
1 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 4c639d7..a874ca6 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -30,7 +30,7 @@ from django.core.urlresolvers import reverse
from django.conf import settings
from stats.models import Module, Domain, Branch, Release, Statistics, FakeLangStatistics
-from stats.utils import check_program_presence, run_shell_command
+from stats import utils
from languages.models import Language
from fixture_factory import *
@@ -61,6 +61,23 @@ def mocked_checkout(branch):
raise
return
+class patch_shell_command:
+ """
+ Mock utils.run_shell_commands and gather all passed commands
+ """
+ def __enter__(self):
+ self.cmds = []
+ def mocked_run_shell_command(cmd, *args, **kwargs):
+ self.cmds.append(cmd)
+ return 0, '', ''
+ self.saved_run_shell_command = utils.run_shell_command
+ utils.run_shell_command = mocked_run_shell_command
+ return self.cmds
+
+ def __exit__(self, type, value, traceback):
+ utils.run_shell_command = self.saved_run_shell_command
+
+
class ModuleTestCase(TestCase):
fixtures = ['sample_data.json']
SYS_DEPENDENCIES = (
@@ -71,7 +88,7 @@ class ModuleTestCase(TestCase):
def __init__(self, name):
TestCase.__init__(self, name)
for package, prog in self.SYS_DEPENDENCIES:
- if not check_program_presence(prog):
+ if not utils.check_program_presence(prog):
raise Exception("You are missing a required system package needed by Damned Lies (%s)" %
package)
def setUp(self):
@@ -214,6 +231,24 @@ class ModuleTestCase(TestCase):
self.assertContains(response, """# Tamil translation for gnome-hello.""")
@test_scratchdir
+ def test_commit_po(self):
+ branch = self.mod.get_head_branch()
+ po_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.po')
+ domain = self.mod.domain_set.get(name='po')
+ lang = Language.objects.get(locale='fr')
+ with self.assertRaisesRegexp(Exception, 'read-only mode'):
+ branch.commit_po(po_file, domain, lang, 'Author <someone example org>')
+ self.mod.vcs_root = self.mod.vcs_root.replace('git://', 'ssh://')
+ self.mod.save()
+ with patch_shell_command() as cmds:
+ branch.commit_po(po_file, domain, lang, 'Author <someone example org>')
+ git_ops = ('git checkout master', 'git pull', 'git add fr.po',
+ 'git commit -m "Updated French translation" --author "Author <someone example org>"',
+ 'git push origin master')
+ for idx, cmd in enumerate(git_ops):
+ self.assertIn(cmd, cmds[idx])
+
+ @test_scratchdir
def test_branch_file_changed(self):
# file_hashes is empty in fixture, so first call should always return True
self.assertTrue(self.mod.get_head_branch().file_changed("gnome-hello.doap"))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]