summaryrefslogtreecommitdiff
path: root/searx/tests
diff options
context:
space:
mode:
authorCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-31 17:29:22 +0100
committerCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-31 17:29:22 +0100
commitd20ddf9da147647710127385a3ee95ff273d4fea (patch)
treee9607635f06d1a0d01585a58e9a9132526cb5c43 /searx/tests
parent787fee6a09f5569f67e7bddaf73d52e159c0431c (diff)
downloadsearxng-d20ddf9da147647710127385a3ee95ff273d4fea.tar.gz
searxng-d20ddf9da147647710127385a3ee95ff273d4fea.zip
Stackoverflow's unit test
Diffstat (limited to 'searx/tests')
-rw-r--r--searx/tests/engines/test_stackoverflow.py106
-rw-r--r--searx/tests/test_engines.py1
2 files changed, 107 insertions, 0 deletions
diff --git a/searx/tests/engines/test_stackoverflow.py b/searx/tests/engines/test_stackoverflow.py
new file mode 100644
index 000000000..e69bafb4c
--- /dev/null
+++ b/searx/tests/engines/test_stackoverflow.py
@@ -0,0 +1,106 @@
+from collections import defaultdict
+import mock
+from searx.engines import stackoverflow
+from searx.testing import SearxTestCase
+
+
+class TestStackoverflowEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 0
+ params = stackoverflow.request(query, dicto)
+ self.assertTrue('url' in params)
+ self.assertTrue(query in params['url'])
+ self.assertTrue('stackoverflow.com' in params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, stackoverflow.response, None)
+ self.assertRaises(AttributeError, stackoverflow.response, [])
+ self.assertRaises(AttributeError, stackoverflow.response, '')
+ self.assertRaises(AttributeError, stackoverflow.response, '[]')
+
+ response = mock.Mock(text='<html></html>')
+ self.assertEqual(stackoverflow.response(response), [])
+
+ html = """
+ <div class="question-summary search-result" id="answer-id-1783426">
+ <div class="statscontainer">
+ <div class="statsarrow"></div>
+ <div class="stats">
+ <div class="vote">
+ <div class="votes answered">
+ <span class="vote-count-post "><strong>2583</strong></span>
+ <div class="viewcount">votes</div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="summary">
+ <div class="result-link">
+ <span>
+ <a href="/questions/this.is.the.url"
+ data-searchsession="/questions"
+ title="Checkout remote Git branch">
+ This is the title
+ </a>
+ </span>
+ </div>
+ <div class="excerpt">
+ This is the content
+ </div>
+ <div class="tags user-tags t-git t-git-checkout t-remote-branch">
+ </div>
+ <div class="started fr">
+ answered <span title="2009-11-23 14:26:08Z" class="relativetime">nov 23 '09</span> by
+ <a href="/users/214090/hallski">hallski</a>
+ </div>
+ </div>
+ </div>
+ """
+ response = mock.Mock(text=html)
+ results = stackoverflow.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0]['title'], 'This is the title')
+ self.assertEqual(results[0]['url'], 'http://stackoverflow.com/questions/this.is.the.url')
+ self.assertEqual(results[0]['content'], 'This is the content')
+
+ html = """
+ <div class="statscontainer">
+ <div class="statsarrow"></div>
+ <div class="stats">
+ <div class="vote">
+ <div class="votes answered">
+ <span class="vote-count-post "><strong>2583</strong></span>
+ <div class="viewcount">votes</div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="summary">
+ <div class="result-link">
+ <span>
+ <a href="/questions/this.is.the.url"
+ data-searchsession="/questions"
+ title="Checkout remote Git branch">
+ This is the title
+ </a>
+ </span>
+ </div>
+ <div class="excerpt">
+ This is the content
+ </div>
+ <div class="tags user-tags t-git t-git-checkout t-remote-branch">
+ </div>
+ <div class="started fr">
+ answered <span title="2009-11-23 14:26:08Z" class="relativetime">nov 23 '09</span> by
+ <a href="/users/214090/hallski">hallski</a>
+ </div>
+ </div>
+ """
+ response = mock.Mock(text=html)
+ results = stackoverflow.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 0)
diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py
index 4ed1a9bba..31ad9cd4e 100644
--- a/searx/tests/test_engines.py
+++ b/searx/tests/test_engines.py
@@ -16,4 +16,5 @@ from searx.tests.engines.test_mixcloud import * # noqa
from searx.tests.engines.test_searchcode_code import * # noqa
from searx.tests.engines.test_searchcode_doc import * # noqa
from searx.tests.engines.test_soundcloud import * # noqa
+from searx.tests.engines.test_stackoverflow import * # noqa
from searx.tests.engines.test_youtube import * # noqa