allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: [#6359] Test to confirm find_shortlinks called with unescaped text
Date Mon, 24 Jun 2013 19:09:03 GMT
Updated Branches:
  refs/heads/tv/6359 4e6c4b6d1 -> 11929a438


[#6359] Test to confirm find_shortlinks called with unescaped text

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


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

Branch: refs/heads/tv/6359
Commit: 11929a438adef89c5947b41719c5f18e917a811c
Parents: 4e6c4b6
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Mon Jun 24 19:08:44 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Jun 24 19:08:44 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tasks/index_tasks.py |  2 +-
 Allura/allura/tests/test_tasks.py  | 42 +++++++++++++++++++--------------
 2 files changed, 25 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11929a43/Allura/allura/tasks/index_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/index_tasks.py b/Allura/allura/tasks/index_tasks.py
index 767cd89..0833bbb 100644
--- a/Allura/allura/tasks/index_tasks.py
+++ b/Allura/allura/tasks/index_tasks.py
@@ -58,7 +58,7 @@ def add_artifacts(ref_ids, update_solr=True, update_refs=True, solr_hosts=None):
                     # Find shortlinks in the raw text, not the escaped html
                     # created by the `solarize()`.
                     ref.references = [
-                        link.ref_id for link in find_shortlinks(artifact.index().get('text',
''))]
+                        link.ref_id for link in find_shortlinks(artifact.index().get('text')
or '')]
             except Exception:
                 log.error('Error indexing artifact %s', ref._id)
                 exceptions.append(sys.exc_info())

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11929a43/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 2d9e54c..e1885c0 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -85,24 +85,30 @@ class TestIndexTasks(unittest.TestCase):
 
     @td.with_wiki
     def test_add_artifacts(self):
-        old_shortlinks = M.Shortlink.query.find().count()
-        old_solr_size = len(g.solr.db)
-        artifacts = [ _TestArtifact() for x in range(5) ]
-        for i, a in enumerate(artifacts):
-            a._shorthand_id = 't%d' % i
-            a.text = 'This is a reference to [t3]'
-        arefs = [ M.ArtifactReference.from_artifact(a) for a in artifacts ]
-        ref_ids = [ r._id for r in arefs ]
-        M.artifact_orm_session.flush()
-        index_tasks.add_artifacts(ref_ids)
-        new_shortlinks = M.Shortlink.query.find().count()
-        new_solr_size = len(g.solr.db)
-        assert old_shortlinks + 5 == new_shortlinks, 'Shortlinks not created'
-        assert old_solr_size + 5 == new_solr_size, "Solr additions didn't happen"
-        M.main_orm_session.flush()
-        M.main_orm_session.clear()
-        a = _TestArtifact.query.get(_shorthand_id='t3')
-        assert len(a.backrefs) == 5, a.backrefs
+        from allura.lib.search import find_shortlinks
+        with mock.patch('allura.lib.search.find_shortlinks') as find_slinks:
+            find_slinks.side_effect = lambda s: find_shortlinks(s)
+
+            old_shortlinks = M.Shortlink.query.find().count()
+            old_solr_size = len(g.solr.db)
+            artifacts = [ _TestArtifact() for x in range(5) ]
+            for i, a in enumerate(artifacts):
+                a._shorthand_id = 't%d' % i
+                a.text = 'This is a reference to [t3]'
+            arefs = [ M.ArtifactReference.from_artifact(a) for a in artifacts ]
+            ref_ids = [ r._id for r in arefs ]
+            M.artifact_orm_session.flush()
+            index_tasks.add_artifacts(ref_ids)
+            new_shortlinks = M.Shortlink.query.find().count()
+            new_solr_size = len(g.solr.db)
+            assert old_shortlinks + 5 == new_shortlinks, 'Shortlinks not created'
+            assert old_solr_size + 5 == new_solr_size, "Solr additions didn't happen"
+            M.main_orm_session.flush()
+            M.main_orm_session.clear()
+            a = _TestArtifact.query.get(_shorthand_id='t3')
+            assert len(a.backrefs) == 5, a.backrefs
+            assert_equal(find_slinks.call_args_list,
+                    [mock.call(a.index().get('text')) for a in artifacts])
 
     @td.with_wiki
     @mock.patch('allura.tasks.index_tasks.g.solr')


Mime
View raw message