allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [4/7] allura git commit: [#7830] ticket:729 Add tests
Date Fri, 20 Mar 2015 20:41:57 GMT
[#7830] ticket:729 Add tests


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

Branch: refs/heads/master
Commit: 02a3fca193c95e436f0b18023c6e8ab2d12bb6f8
Parents: b0a908c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Feb 19 15:53:48 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Mar 20 20:40:29 2015 +0000

----------------------------------------------------------------------
 Allura/allura/tests/model/test_repo.py          | 38 ++++++++++++++++
 Allura/allura/tests/test_tasks.py               | 11 +++++
 .../forgegit/tests/model/test_repository.py     | 46 ++++++++++++++++++++
 3 files changed, 95 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/02a3fca1/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 9e2af07..669f940 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -713,3 +713,41 @@ class TestModelCache(unittest.TestCase):
         session.assert_called_once_with(tree1)
         session.return_value.flush.assert_called_once_with(tree1)
         session.return_value.expunge.assert_called_once_with(tree1)
+
+
+class TestMergeRequest(object):
+
+    def setUp(self):
+        setup_basic_test()
+        setup_global_objects()
+        self.mr = M.MergeRequest(app_config=mock.Mock(_id=ObjectId()))
+        self.mr.app = mock.Mock(forkable=True)
+
+    def test_can_merge(self):
+        assert_equal(self.mr.can_merge(),
+                     self.mr.app.repo.can_merge.return_value)
+        self.mr.app.repo.can_merge.assert_called_once_with(self.mr)
+
+        self.mr.app.reset_mock()
+        self.mr.app.forkable = False
+        assert_equal(self.mr.can_merge(), False)
+        assert_equal(self.mr.app.repo.can_merge.called, False)
+
+    @mock.patch('allura.tasks.repo_tasks.merge', autospec=True)
+    def test_merge(self, merge_task):
+        self.mr.merge_task_status = lambda: None
+        self.mr.merge()
+        merge_task.post.assert_called_once_with(self.mr._id)
+
+        merge_task.reset_mock()
+        self.mr.merge_task_status = lambda: 'ready'
+        self.mr.merge()
+        assert_equal(merge_task.post.called, False)
+
+    def test_merge_task_status(self):
+        from allura.tasks import repo_tasks
+        assert_equal(self.mr.merge_task_status(), None)
+        repo_tasks.merge.post(self.mr._id)
+        assert_equal(self.mr.merge_task_status(), 'ready')
+        M.MonQTask.run_ready()
+        assert_equal(self.mr.merge_task_status(), 'complete')

http://git-wip-us.apache.org/repos/asf/allura/blob/02a3fca1/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 13d5c17..d822229 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -64,6 +64,17 @@ class TestRepoTasks(unittest.TestCase):
         assert_equal(post_event.call_args[0][2], None)
         # ignore args[3] which is a traceback string
 
+    @mock.patch('allura.tasks.repo_tasks.session', autospec=True)
+    @mock.patch.object(M, 'MergeRequest', autospec=True)
+    def test_merge(self, MR, session):
+        mr = mock.Mock(_id='_id')
+        MR.query.get.return_value = mr
+        repo_tasks.merge(mr._id)
+        mr.app.repo.merge.assert_called_once_with(mr)
+        assert_equal(mr.status, 'merged')
+        session.assert_called_once_with(mr)
+        session.return_value.flush.assert_called_once_with(mr)
+
 
 class TestEventTasks(unittest.TestCase):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/02a3fca1/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 231e479..d79fc7b 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -592,6 +592,52 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         }
         assert_equals(payload, expected_payload)
 
+    def test_can_merge(self):
+        mr = mock.Mock(downstream_repo_url='downstream-url',
+                       source_branch='source-branch',
+                       target_branch='target-branch',
+                       downstream=mock.Mock(commit_id='cid'))
+        git = mock.Mock()
+        git.merge_tree.return_value = 'clean merge'
+        self.repo._impl._git.git = git
+        assert_equal(self.repo.can_merge(mr), True)
+        git.fetch.assert_called_once_with('downstream-url', 'source-branch')
+        git.merge_base.assert_called_once_with('cid', 'target-branch')
+        git.merge_tree.assert_called_once_with(
+            git.merge_base.return_value,
+            'target-branch',
+            'cid')
+        git.merge_tree.return_value = '+<<<<<<<'
+        assert_equal(self.repo.can_merge(mr), False)
+
+    @mock.patch('forgegit.model.git_repo.tempfile', autospec=True)
+    @mock.patch('forgegit.model.git_repo.git', autospec=True)
+    @mock.patch('forgegit.model.git_repo.GitImplementation', autospec=True)
+    @mock.patch('forgegit.model.git_repo.shutil', autospec=True)
+    def test_merge(self, shutil, GitImplementation, git, tempfile):
+        mr = mock.Mock(downstream_repo_url='downstream-url',
+                       source_branch='source-branch',
+                       target_branch='target-branch',
+                       downstream=mock.Mock(commit_id='cid'))
+        _git = mock.Mock()
+        self.repo._impl._git.git = _git
+        self.repo.merge(mr)
+        git.Repo.clone_from.assert_called_once_with(
+            self.repo.clone_url('rw'),
+            to_path=tempfile.mkdtemp.return_value,
+            bare=False)
+        tmp_repo = GitImplementation.return_value._git
+        assert_equal(
+            tmp_repo.git.fetch.call_args_list,
+            [mock.call('origin', 'target-branch'),
+             mock.call('downstream-url', 'source-branch')])
+        tmp_repo.git.checkout.assert_called_once_with('target-branch')
+        tmp_repo.git.merge.assert_called_once_with('cid')
+        tmp_repo.git.push.assert_called_once_with('origin', 'target-branch')
+        shutil.rmtree.assert_called_once_with(
+            tempfile.mkdtemp.return_value,
+            ignore_errors=True)
+
 
 class TestGitImplementation(unittest.TestCase):
 


Mime
View raw message