diff options
author | marc <a01200356@itesm.mx> | 2016-12-15 00:34:43 -0600 |
---|---|---|
committer | marc <a01200356@itesm.mx> | 2016-12-15 00:40:21 -0600 |
commit | af35eee10b98940c51c6e5e18629de514b4bd48d (patch) | |
tree | 804b0a4cfe08bb897541e9e8571b921a78e07992 /tests/unit/engines/test_swisscows.py | |
parent | e0c270bd72f7b2a40222e3ed264e25d36cb0fc30 (diff) | |
download | searxng-af35eee10b98940c51c6e5e18629de514b4bd48d.tar.gz searxng-af35eee10b98940c51c6e5e18629de514b4bd48d.zip |
tests for _fetch_supported_languages in engines
and refactor method to make it testable without making requests
Diffstat (limited to 'tests/unit/engines/test_swisscows.py')
-rw-r--r-- | tests/unit/engines/test_swisscows.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unit/engines/test_swisscows.py b/tests/unit/engines/test_swisscows.py index dbbc044da..27f33d70a 100644 --- a/tests/unit/engines/test_swisscows.py +++ b/tests/unit/engines/test_swisscows.py @@ -126,3 +126,30 @@ class TestSwisscowsEngine(SearxTestCase): self.assertEqual(results[2]['url'], 'http://de.wikipedia.org/wiki/Datei:This should.svg') self.assertEqual(results[2]['img_src'], 'http://ts2.mm.This/should.png') self.assertEqual(results[2]['template'], 'images.html') + + def test_fetch_supported_languages(self): + html = """<html></html>""" + response = mock.Mock(text=html) + languages = swisscows._fetch_supported_languages(response) + self.assertEqual(type(languages), list) + self.assertEqual(len(languages), 0) + + html = """ + <html> + <div id="regions-popup"> + <div> + <ul> + <li><a data-val="browser"></a></li> + <li><a data-val="de-CH"></a></li> + <li><a data-val="fr-CH"></a></li> + </ul> + </div> + </div> + </html> + """ + response = mock.Mock(text=html) + languages = swisscows._fetch_supported_languages(response) + self.assertEqual(type(languages), list) + self.assertEqual(len(languages), 3) + self.assertIn('de-CH', languages) + self.assertIn('fr-CH', languages) |