incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [19/28] git commit: [#2835] ticket:308 Add tests for solarize()
Date Wed, 24 Apr 2013 17:16:28 GMT
[#2835] ticket:308 Add tests for solarize()


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

Branch: refs/heads/db/2835
Commit: 27016ef75322ab5efc25b6c31e9186c6990e704b
Parents: de200e8
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Apr 1 13:30:27 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 24 16:34:42 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/unit/test_solr.py |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/27016ef7/Allura/allura/tests/unit/test_solr.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_solr.py b/Allura/allura/tests/unit/test_solr.py
index aa0b939..e1b67c8 100644
--- a/Allura/allura/tests/unit/test_solr.py
+++ b/Allura/allura/tests/unit/test_solr.py
@@ -17,8 +17,10 @@
 
 import unittest
 import mock
+from nose.tools import assert_equal
 
 from allura.lib.solr import Solr
+from allura.lib.search import solarize
 
 class TestSolr(unittest.TestCase):
     @mock.patch('allura.lib.solr.pysolr')
@@ -45,3 +47,29 @@ class TestSolr(unittest.TestCase):
         s.delete('bar', somekw='value')
         pysolr.Solr.delete.assert_called_once_with(s, 'bar', commit=False,
                 somekw='value')
+
+class TestSolarize(unittest.TestCase):
+
+    def setUp(self):
+        self.obj = mock.MagicMock()
+        self.obj.index.return_value = {}
+
+    def test_no_object(self):
+        assert_equal(solarize(None), None)
+
+    def test_empty_index(self):
+        self.obj.index.return_value = None
+        assert_equal(solarize(self.obj), None)
+
+    def test_doc_without_text(self):
+        assert_equal(solarize(self.obj), {'text': ''})
+
+    def test_strip_markdown(self):
+        self.obj.index.return_value = {'text': '# Header'}
+        assert_equal(solarize(self.obj), {'text': 'Header'})
+
+    def test_html_in_text(self):
+        self.obj.index.return_value = {'text': '<script>alert(1)</script>'}
+        assert_equal(solarize(self.obj), {'text': ''})
+        self.obj.index.return_value = {'text': '&lt;script&gt;alert(1)&lt;/script&gt;'}
+        assert_equal(solarize(self.obj), {'text': '&lt;script&gt;alert(1)&lt;/script&gt;'})


Mime
View raw message