[refactor] engines: migrate to SXNG_Response.html() (#6718)

This commit is contained in:
Bnyro
2026-09-13 14:01:58 +02:00
parent 3169aafd28
commit 274b63b677
75 changed files with 102 additions and 178 deletions

View File

@@ -2,6 +2,7 @@
# pylint: disable=missing-module-docstring,disable=missing-class-docstring,invalid-name
from collections import defaultdict
import lxml.html
import mock
from searx.engines import xpath
@@ -27,6 +28,7 @@ class TestXpathEngine(SearxTestCase):
</div>
</div>
"""
empty_html = """<html></html>"""
def setUp(self):
super().setUp()
@@ -65,10 +67,14 @@ class TestXpathEngine(SearxTestCase):
self.assertRaises(AttributeError, xpath.response, '')
self.assertRaises(AttributeError, xpath.response, '[]')
response = mock.Mock(text='<html></html>', status_code=200)
response = mock.Mock(
text=self.empty_html, status_code=200, html=mock.Mock(return_value=lxml.html.fromstring(self.empty_html))
)
self.assertEqual(xpath.response(response), [])
response = mock.Mock(text=self.html, status_code=200)
response = mock.Mock(
text=self.html, status_code=200, html=mock.Mock(return_value=lxml.html.fromstring(self.html))
)
results = xpath.response(response)
self.assertIsInstance(results, list)
self.assertEqual(len(results), 2)
@@ -107,10 +113,16 @@ class TestXpathEngine(SearxTestCase):
self.assertRaises(AttributeError, xpath.response, '')
self.assertRaises(AttributeError, xpath.response, '[]')
response = mock.Mock(text='<html></html>', status_code=200)
response = mock.Mock(
text=self.empty_html, status_code=200, html=mock.Mock(return_value=lxml.html.fromstring(self.empty_html))
)
self.assertEqual(xpath.response(response), [])
response = mock.Mock(text=self.html, status_code=200)
response = mock.Mock(
text=self.html,
status_code=200,
html=mock.Mock(return_value=lxml.html.fromstring(self.html)),
)
results = xpath.response(response)
self.assertIsInstance(results, list)
self.assertEqual(len(results), 2)