You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/06/24 22:03:25 UTC
[1/2] git commit: [#6359] Test to confirm find_shortlinks called with
unescaped text
Updated Branches:
refs/heads/master 0c5787e98 -> a1aae4e17
[#6359] Test to confirm find_shortlinks called with unescaped text
Signed-off-by: Tim Van Steenburgh <tv...@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/a1aae4e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a1aae4e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a1aae4e1
Branch: refs/heads/master
Commit: a1aae4e170f70d7cb6aa838cff77f6628a43f582
Parents: 2205b93
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Jun 24 19:08:44 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Jun 24 20:03:13 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/a1aae4e1/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/a1aae4e1/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')
[2/2] git commit: [#6359] Find shortlinks in raw text,
not escaped html
Posted by br...@apache.org.
[#6359] Find shortlinks in raw text, not escaped html
Signed-off-by: Tim Van Steenburgh <tv...@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/2205b937
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/2205b937
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/2205b937
Branch: refs/heads/master
Commit: 2205b93717c772d7c1b61bd7c85dfe74e83d3e11
Parents: 0c5787e
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Jun 18 18:22:49 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Jun 24 20:03:13 2013 +0000
----------------------------------------------------------------------
Allura/allura/tasks/index_tasks.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2205b937/Allura/allura/tasks/index_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/index_tasks.py b/Allura/allura/tasks/index_tasks.py
index 27ada83..767cd89 100644
--- a/Allura/allura/tasks/index_tasks.py
+++ b/Allura/allura/tasks/index_tasks.py
@@ -55,8 +55,10 @@ def add_artifacts(ref_ids, update_solr=True, update_refs=True, solr_hosts=None):
if update_refs:
if isinstance(artifact, M.Snapshot):
continue
+ # Find shortlinks in the raw text, not the escaped html
+ # created by the `solarize()`.
ref.references = [
- link.ref_id for link in find_shortlinks(s['text']) ]
+ link.ref_id for link in find_shortlinks(artifact.index().get('text', ''))]
except Exception:
log.error('Error indexing artifact %s', ref._id)
exceptions.append(sys.exc_info())