Ponysearch/tests/unit/engines/test_fdroid.py

61 lines
1.9 KiB
Python
Raw Normal View History

2016-03-26 22:50:44 +01:00
import mock
from collections import defaultdict
from searx.engines import fdroid
from searx.testing import SearxTestCase
class TestFdroidEngine(SearxTestCase):
def test_request(self):
query = 'test_query'
dic = defaultdict(dict)
dic['pageno'] = 1
params = fdroid.request(query, dic)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
2019-08-05 15:44:02 +02:00
self.assertTrue('search.f-droid.org' in params['url'])
2016-03-26 22:50:44 +01:00
2019-08-05 15:44:02 +02:00
def test_response_empty(self):
2016-03-26 22:50:44 +01:00
resp = mock.Mock(text='<html></html>')
self.assertEqual(fdroid.response(resp), [])
2019-08-05 15:44:02 +02:00
def test_response_oneresult(self):
2016-03-26 22:50:44 +01:00
html = """
2019-08-05 15:44:02 +02:00
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<div class="site-wrapper">
<div class="main-content">
<a class="package-header" href="https://example.com/app.url">
<img class="package-icon" src="https://example.com/appexample.logo.png" />
<div class="package-info">
<h4 class="package-name">
App Example 1
</h4>
<div class="package-desc">
<span class="package-summary">Description App Example 1</span>
<span class="package-license">GPL-3.0-only</span>
</div>
</div>
</a>
</div>
</div>
</body>
</html>
2016-03-26 22:50:44 +01:00
"""
resp = mock.Mock(text=html)
results = fdroid.response(resp)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
2019-08-05 15:44:02 +02:00
self.assertEqual(results[0]['url'], 'https://example.com/app.url')
self.assertEqual(results[0]['title'], 'App Example 1')
self.assertEqual(results[0]['content'], 'Description App Example 1 - GPL-3.0-only')
self.assertEqual(results[0]['img_src'], 'https://example.com/appexample.logo.png')