allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [20/20] git commit: [#7257] ticket:587 Add unit tests
Date Wed, 21 May 2014 14:45:08 GMT
[#7257] ticket:587 Add unit tests


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

Branch: refs/heads/master
Commit: edddaf2fd875f4cda462c9f82080e3b578bfa65a
Parents: 2d7c518
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed May 14 10:52:24 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed May 21 14:44:23 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/unit/test_project.py | 13 +++++++++++++
 Allura/allura/tests/unit/test_session.py | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/edddaf2f/Allura/allura/tests/unit/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_project.py b/Allura/allura/tests/unit/test_project.py
index b4108e0..28ba7fa 100644
--- a/Allura/allura/tests/unit/test_project.py
+++ b/Allura/allura/tests/unit/test_project.py
@@ -86,3 +86,16 @@ class TestProject(unittest.TestCase):
         self.assertEqual(p.social_account('Twitter')
                          .accounturl, 'http://twitter.com/allura')
         self.assertEqual(p.twitter_handle, 'http://twitter.com/allura')
+
+    def test_should_update_index(self):
+        p = M.Project()
+        self.assertFalse(p.should_update_index({}, {}))
+        old = {'last_updated': 1}
+        new = {'last_updated': 2}
+        self.assertFalse(p.should_update_index(old, new))
+        old = {'last_updated': 1, 'a': 1}
+        new = {'last_updated': 2, 'a': 1}
+        self.assertFalse(p.should_update_index(old, new))
+        old = {'last_updated': 1, 'a': 1}
+        new = {'last_updated': 2, 'a': 2}
+        self.assertTrue(p.should_update_index(old, new))

http://git-wip-us.apache.org/repos/asf/allura/blob/edddaf2f/Allura/allura/tests/unit/test_session.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_session.py b/Allura/allura/tests/unit/test_session.py
index 29a66ca..7562b73 100644
--- a/Allura/allura/tests/unit/test_session.py
+++ b/Allura/allura/tests/unit/test_session.py
@@ -81,6 +81,7 @@ class TestIndexerSessionExtension(TestCase):
 
     def _mock_indexable(self, **kw):
         m = mock.Mock(**kw)
+        m.__ming__ = mock.MagicMock()
         m.index_id.return_value = id(m)
         return m
 
@@ -95,6 +96,22 @@ class TestIndexerSessionExtension(TestCase):
         self.tasks['add'].post.assert_called_once_with([1, 2, 3, 4, 5])
         self.tasks['del'].post.assert_called_once_with(map(id, deleted))
 
+    def test_flush_skips_update(self):
+        modified = [self._mock_indexable(_id=i) for i in range(5)]
+        modified[1].should_update_index.return_value = False
+        modified[4].should_update_index.return_value = False
+        self.extension.objects_modified = modified
+        self.extension.after_flush()
+        self.tasks['add'].post.assert_called_once_with([0, 2, 3])
+
+    def test_flush_skips_task_if_all_objects_filtered_out(self):
+        modified = [self._mock_indexable(_id=i) for i in range(5)]
+        for m in modified:
+            m.should_update_index.return_value = False
+        self.extension.objects_modified = modified
+        self.extension.after_flush()
+        assert self.tasks['add'].post.call_count == 0
+
 
 class TestBatchIndexer(TestCase):
 


Mime
View raw message