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_dailymotion.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_dailymotion.py')
-rw-r--r-- | tests/unit/engines/test_dailymotion.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/unit/engines/test_dailymotion.py b/tests/unit/engines/test_dailymotion.py index 368b3a7a5..72071af66 100644 --- a/tests/unit/engines/test_dailymotion.py +++ b/tests/unit/engines/test_dailymotion.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from collections import defaultdict import mock from searx.engines import dailymotion @@ -72,3 +73,39 @@ class TestDailymotionEngine(SearxTestCase): results = dailymotion.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 0) + + def test_fetch_supported_languages(self): + json = r""" + {"list":[{"code":"af","name":"Afrikaans","native_name":"Afrikaans", + "localized_name":"Afrikaans","display_name":"Afrikaans"}, + {"code":"ar","name":"Arabic","native_name":"\u0627\u0644\u0639\u0631\u0628\u064a\u0629", + "localized_name":"Arabic","display_name":"Arabic"}, + {"code":"la","name":"Latin","native_name":null, + "localized_name":"Latin","display_name":"Latin"} + ]} + """ + response = mock.Mock(text=json) + languages = dailymotion._fetch_supported_languages(response) + self.assertEqual(type(languages), dict) + self.assertEqual(len(languages), 3) + self.assertIn('af', languages) + self.assertIn('ar', languages) + self.assertIn('la', languages) + + self.assertEqual(type(languages['af']), dict) + self.assertEqual(type(languages['ar']), dict) + self.assertEqual(type(languages['la']), dict) + + self.assertIn('name', languages['af']) + self.assertIn('name', languages['ar']) + self.assertNotIn('name', languages['la']) + + self.assertIn('english_name', languages['af']) + self.assertIn('english_name', languages['ar']) + self.assertIn('english_name', languages['la']) + + self.assertEqual(languages['af']['name'], 'Afrikaans') + self.assertEqual(languages['af']['english_name'], 'Afrikaans') + self.assertEqual(languages['ar']['name'], u'العربية') + self.assertEqual(languages['ar']['english_name'], 'Arabic') + self.assertEqual(languages['la']['english_name'], 'Latin') |