incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: Add tests for new event
Date Tue, 06 Nov 2012 14:44:35 GMT
Updated Branches:
  refs/heads/tv/5230 dda8d5246 -> ae634b33e


Add tests for new event


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ae634b33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ae634b33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ae634b33

Branch: refs/heads/tv/5230
Commit: ae634b33e75d25e5f7f9e134dc8c8dc1890eb0fc
Parents: dda8d52
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Tue Nov 6 14:44:16 2012 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Nov 6 14:44:16 2012 +0000

----------------------------------------------------------------------
 ForgeGit/forgegit/tests/model/test_repository.py |   22 ++++++++++++++-
 ForgeHg/forgehg/tests/model/test_repository.py   |   22 ++++++++++++++-
 ForgeSVN/forgesvn/tests/model/test_repository.py |   24 ++++++++++++++++-
 3 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ae634b33/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index deb8b63..756a36f 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -148,7 +148,8 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         assert os.path.exists('/tmp/testgit.git/hooks/post-receive')
         assert os.access('/tmp/testgit.git/hooks/post-receive', os.X_OK)
 
-    def test_clone(self):
+    @mock.patch('forgegit.model.git_repo.g.post_event')
+    def test_clone(self, post_event):
         repo = GM.Repository(
             name='testgit.git',
             fs_path='/tmp/',
@@ -162,6 +163,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from(repo_path)
+        post_event.assert_any_call('repo_cloned', repo_path)
         assert len(repo.log())
         assert not os.path.exists('/tmp/testgit.git/hooks/update')
         assert not os.path.exists('/tmp/testgit.git/hooks/post-receive-user')
@@ -172,6 +174,24 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         self.assertIn('exec $DIR/post-receive-user\n', c)
         shutil.rmtree(dirname)
 
+    @mock.patch('forgegit.model.git_repo.g.post_event')
+    @mock.patch('forgegit.model.git_repo.traceback')
+    def test_clone_from_posts_event_on_failure(self, traceback, post_event):
+        fake_source_url = 'fake_source_url'
+        fake_traceback = 'fake_traceback'
+        traceback.format_exc.return_value = fake_traceback
+        repo = GM.Repository(
+            name='testgit.git',
+            fs_path='/tmp/',
+            url_path = '/test/',
+            tool = 'git',
+            status = 'creating')
+        try:
+            repo._impl.clone_from(fake_source_url)
+        except:
+            pass
+        post_event.assert_any_call('repo_clone_failed', fake_source_url, fake_traceback)
+
     def test_index(self):
         i = self.repo.index()
         assert i['type_s'] == 'Git Repository', i

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ae634b33/ForgeHg/forgehg/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeHg/forgehg/tests/model/test_repository.py b/ForgeHg/forgehg/tests/model/test_repository.py
index c88a406..ddedac2 100644
--- a/ForgeHg/forgehg/tests/model/test_repository.py
+++ b/ForgeHg/forgehg/tests/model/test_repository.py
@@ -143,7 +143,8 @@ class TestHgRepo(unittest.TestCase, RepoImplTestBase):
         assert not os.path.exists('/tmp/testrepo.hg/.hg/undo.branch')
         shutil.rmtree(dirname)
 
-    def test_clone(self):
+    @mock.patch('forgehg.model.hg.g.post_event')
+    def test_clone(self, post_event):
         repo = HM.Repository(
             name='testrepo.hg',
             fs_path='/tmp/',
@@ -157,6 +158,7 @@ class TestHgRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from(repo_path)
+        post_event.assert_any_call('repo_cloned', repo_path)
         assert len(repo.log())
         assert not os.path.exists('/tmp/testrepo.hg/.hg/external-changegroup')
         assert not os.path.exists('/tmp/testrepo.hg/.hg/nested/nested-file')
@@ -171,6 +173,24 @@ class TestHgRepo(unittest.TestCase, RepoImplTestBase):
         assert not os.path.exists('/tmp/testrepo.hg/.hg/undo.branch')
         shutil.rmtree(dirname)
 
+    @mock.patch('forgehg.model.hg.g.post_event')
+    @mock.patch('forgehg.model.hg.traceback')
+    def test_clone_from_posts_event_on_failure(self, traceback, post_event):
+        fake_source_url = 'fake_source_url'
+        fake_traceback = 'fake_traceback'
+        traceback.format_exc.return_value = fake_traceback
+        repo = HM.Repository(
+            name='testrepo.hg',
+            fs_path='/tmp/',
+            url_path = '/test/',
+            tool = 'hg',
+            status = 'creating')
+        try:
+            repo._impl.clone_from(fake_source_url)
+        except:
+            pass
+        post_event.assert_any_call('repo_clone_failed', fake_source_url, fake_traceback)
+
     def test_index(self):
         i = self.repo.index()
         assert i['type_s'] == 'Hg Repository', i

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ae634b33/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 9e9270c..d317b70 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -144,7 +144,8 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         self.assertIn('exec $DIR/post-commit-user "$@"\n', c)
         shutil.rmtree(dirname)
 
-    def test_clone(self):
+    @mock.patch('forgesvn.model.svn.g.post_event')
+    def test_clone(self, post_event):
         repo = SM.Repository(
             name='testsvn',
             fs_path='/tmp/',
@@ -158,6 +159,7 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from('file://' + repo_path)
+        post_event.assert_any_call('repo_cloned', 'file://' + repo_path)
         assert len(repo.log())
         assert os.path.exists('/tmp/testsvn/hooks/pre-revprop-change')
         assert os.access('/tmp/testsvn/hooks/pre-revprop-change', os.X_OK)
@@ -172,6 +174,26 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         self.assertIn('exec $DIR/post-commit-user "$@"\n', c)
         shutil.rmtree(dirname)
 
+    @mock.patch('forgesvn.model.svn.g.post_event')
+    @mock.patch('forgesvn.model.svn.Popen')
+    def test_clone_from_posts_event_on_failure(self, popen, post_event):
+        fake_source_url = 'fake_source_url'
+        fake_traceback = 'fake_traceback'
+        popen_mock = mock.Mock(returncode=1)
+        popen_mock.communicate.return_value = '', fake_traceback
+        popen.return_value = popen_mock
+        repo = SM.Repository(
+            name='testsvn',
+            fs_path='/tmp/',
+            url_path = '/test/',
+            tool = 'svn',
+            status = 'creating')
+        try:
+            repo._impl.clone_from(fake_source_url)
+        except:
+            pass
+        post_event.assert_any_call('repo_clone_failed', fake_source_url, fake_traceback)
+
     def test_index(self):
         i = self.repo.index()
         assert i['type_s'] == 'SVN Repository', i


Mime
View raw message