|
@@ -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')
|