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_bing.py | |
| parent | e0c270bd72f7b2a40222e3ed264e25d36cb0fc30 (diff) | |
tests for _fetch_supported_languages in engines
and refactor method to make it testable without making requests
Diffstat (limited to 'tests/unit/engines/test_bing.py')
| -rw-r--r-- | tests/unit/engines/test_bing.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py index 886584229..61f8629d0 100644 --- a/tests/unit/engines/test_bing.py +++ b/tests/unit/engines/test_bing.py @@ -86,3 +86,35 @@ class TestBingEngine(SearxTestCase): self.assertEqual(results[0]['title'], 'This should be the title') self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') self.assertEqual(results[0]['content'], 'This should be the content.') + + def test_fetch_supported_languages(self): + html = """<html></html>""" + response = mock.Mock(text=html) + results = bing._fetch_supported_languages(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ + <html> + <body> + <form> + <div id="limit-languages"> + <div> + <div><input id="es" value="es"></input></div> + </div> + <div> + <div><input id="pt_BR" value="pt_BR"></input></div> + <div><input id="pt_PT" value="pt_PT"></input></div> + </div> + </div> + </form> + </body> + </html> + """ + response = mock.Mock(text=html) + languages = bing._fetch_supported_languages(response) + self.assertEqual(type(languages), list) + self.assertEqual(len(languages), 3) + self.assertIn('es', languages) + self.assertIn('pt-BR', languages) + self.assertIn('pt-PT', languages) |