Browse Source

A bit of utils unit tests

Cqoicebordel 10 years ago
parent
commit
cfe81d741c
2 changed files with 23 additions and 1 deletions
  1. 22
    0
      searx/tests/test_utils.py
  2. 1
    1
      searx/utils.py

+ 22
- 0
searx/tests/test_utils.py View File

@@ -10,6 +10,11 @@ class TestUtils(SearxTestCase):
10 10
         self.assertIsNotNone(utils.gen_useragent())
11 11
         self.assertTrue(utils.gen_useragent().startswith('Mozilla'))
12 12
 
13
+    def test_searx_useragent(self):
14
+        self.assertIsInstance(utils.searx_useragent(), str)
15
+        self.assertIsNotNone(utils.searx_useragent())
16
+        self.assertTrue(utils.searx_useragent().startswith('searx'))
17
+
13 18
     def test_highlight_content(self):
14 19
         self.assertEqual(utils.highlight_content(0, None), None)
15 20
         self.assertEqual(utils.highlight_content(None, None), None)
@@ -29,6 +34,23 @@ class TestUtils(SearxTestCase):
29 34
         query = 'a test'
30 35
         self.assertEqual(utils.highlight_content(content, query), content)
31 36
 
37
+    def test_html_to_text(self):
38
+        html = """
39
+        <a href="/testlink" class="link_access_account">
40
+            <span class="toto">
41
+                <span>
42
+                    <img src="test.jpg" />
43
+                </span>
44
+            </span>
45
+            <span class="titi">
46
+                            Test text
47
+            </span>
48
+        </a>
49
+        """
50
+        self.assertIsInstance(utils.html_to_text(html), unicode)
51
+        self.assertIsNotNone(utils.html_to_text(html))
52
+        self.assertEqual(utils.html_to_text(html), "Test text")
53
+
32 54
 
33 55
 class TestHTMLTextExtractor(SearxTestCase):
34 56
 

+ 1
- 1
searx/utils.py View File

@@ -115,7 +115,7 @@ class HTMLTextExtractor(HTMLParser):
115 115
         self.result.append(name)
116 116
 
117 117
     def get_text(self):
118
-        return u''.join(self.result)
118
+        return u''.join(self.result).strip()
119 119
 
120 120
 
121 121
 def html_to_text(html):