Browse Source

Currency converter's unit test + DDG correction

Cqoicebordel 10 years ago
parent
commit
1ea5bc63a5

+ 44
- 0
searx/tests/engines/test_currency_convert.py View File

@@ -0,0 +1,44 @@
1
+from collections import defaultdict
2
+from datetime import datetime
3
+import mock
4
+from searx.engines import currency_convert
5
+from searx.testing import SearxTestCase
6
+
7
+
8
+class TestCurrencyConvertEngine(SearxTestCase):
9
+
10
+    def test_request(self):
11
+        query = 'test_query'
12
+        dicto = defaultdict(dict)
13
+        dicto['pageno'] = 1
14
+        params = currency_convert.request(query, dicto)
15
+        self.assertNotIn('url', params)
16
+
17
+        query = '1.1.1 EUR in USD'
18
+        params = currency_convert.request(query, dicto)
19
+        self.assertNotIn('url', params)
20
+
21
+        query = '10 eur in usd'
22
+        params = currency_convert.request(query, dicto)
23
+        self.assertIn('url', params)
24
+        self.assertIn('finance.yahoo.com', params['url'])
25
+        self.assertIn('EUR', params['url'])
26
+        self.assertIn('USD', params['url'])
27
+
28
+    def test_response(self):
29
+        dicto = defaultdict(dict)
30
+        dicto['ammount'] = 10
31
+        dicto['from'] = "EUR"
32
+        dicto['to'] = "USD"
33
+        response = mock.Mock(text='a,b,c,d', search_params=dicto)
34
+        self.assertEqual(currency_convert.response(response), [])
35
+
36
+        csv = "2,0.5,1"
37
+        response = mock.Mock(text=csv, search_params=dicto)
38
+        results = currency_convert.response(response)
39
+        self.assertEqual(type(results), list)
40
+        self.assertEqual(len(results), 1)
41
+        self.assertEqual(results[0]['answer'], '10 EUR = 5.0 USD (1 EUR = 0.5 USD)')
42
+        now_date = datetime.now().strftime('%Y%m%d')
43
+        self.assertEqual(results[0]['url'], 'http://finance.yahoo.com/currency/converter-results/' +
44
+                                            now_date + '/10-eur-to-usd.html')

+ 1
- 1
searx/tests/engines/test_duckduckgo.py View File

@@ -4,7 +4,7 @@ from searx.engines import duckduckgo
4 4
 from searx.testing import SearxTestCase
5 5
 
6 6
 
7
-class TestBingEngine(SearxTestCase):
7
+class TestDuckduckgoEngine(SearxTestCase):
8 8
 
9 9
     def test_request(self):
10 10
         query = 'test_query'

+ 1
- 0
searx/tests/test_engines.py View File

@@ -2,6 +2,7 @@ from searx.tests.engines.test_bing import *  # noqa
2 2
 from searx.tests.engines.test_bing_images import *  # noqa
3 3
 from searx.tests.engines.test_bing_news import *  # noqa
4 4
 from searx.tests.engines.test_btdigg import *  # noqa
5
+from searx.tests.engines.test_currency_convert import *  # noqa
5 6
 from searx.tests.engines.test_dailymotion import *  # noqa
6 7
 from searx.tests.engines.test_deezer import *  # noqa
7 8
 from searx.tests.engines.test_deviantart import *  # noqa