def test_response(self):
        dicto = defaultdict(dict)
        dicto['amount'] = float(10)
        dicto['from'] = "GBP"
        dicto['to'] = "USD"
        dicto['from_name'] = "pound sterling"
        dicto['to_name'] = "United States dollar"
        response = mock.Mock(text='a,b,c,d', search_params=dicto)
        self.assertEqual(currency_convert.response(response), [])
        body = """ddg_spice_currency(
            {
                "conversion":{
                    "converted-amount": "0.5"
                },
                "topConversions":[
                    {
                    },
                    {
                    }
                ]
            }
        );
        """
        response = mock.Mock(text=body, search_params=dicto)
        results = currency_convert.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['answer'], '10.0 GBP = 5.0 USD, 1 GBP (pound sterling)' +
                         ' = 0.5 USD (United States dollar)')

        target_url = 'https://duckduckgo.com/js/spice/currency/1/{}/{}'.format(
            dicto['from'], dicto['to'])
        self.assertEqual(results[0]['url'], target_url)
Beispiel #2
0
    def test_response(self):
        dicto = defaultdict(dict)
        dicto['amount'] = float(10)
        dicto['from'] = "GBP"
        dicto['to'] = "USD"
        dicto['from_name'] = "pound sterling"
        dicto['to_name'] = "United States dollar"
        response = mock.Mock(text='a,b,c,d', search_params=dicto)
        self.assertEqual(currency_convert.response(response), [])
        body = """ddg_spice_currency(
            {
                "conversion":{
                    "converted-amount": "0.5"
                },
                "topConversions":[
                    {
                    },
                    {
                    }
                ]
            }
        );
        """
        response = mock.Mock(text=body, search_params=dicto)
        results = currency_convert.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(
            results[0]['answer'],
            '10.0 GBP = 5.0 USD, 1 GBP (pound sterling)' +
            ' = 0.5 USD (United States dollar)')

        target_url = 'https://duckduckgo.com/js/spice/currency/1/{}/{}'.format(
            dicto['from'], dicto['to'])
        self.assertEqual(results[0]['url'], target_url)
Beispiel #3
0
    def test_response(self):
        dicto = defaultdict(dict)
        dicto['ammount'] = 10
        dicto['from'] = "EUR"
        dicto['to'] = "USD"
        response = mock.Mock(text='a,b,c,d', search_params=dicto)
        self.assertEqual(currency_convert.response(response), [])

        csv = "2,0.5,1"
        response = mock.Mock(text=csv, search_params=dicto)
        results = currency_convert.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['answer'], '10 EUR = 5.0 USD (1 EUR = 0.5 USD)')
        now_date = datetime.now().strftime('%Y%m%d')
        self.assertEqual(results[0]['url'], 'https://finance.yahoo.com/currency/converter-results/' +
                                            now_date + '/10-eur-to-usd.html')
Beispiel #4
0
    def test_response(self):
        dicto = defaultdict(dict)
        dicto['ammount'] = 10
        dicto['from'] = "EUR"
        dicto['to'] = "USD"
        response = mock.Mock(text='a,b,c,d', search_params=dicto)
        self.assertEqual(currency_convert.response(response), [])

        csv = "2,0.5,1"
        response = mock.Mock(text=csv, search_params=dicto)
        results = currency_convert.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['answer'], '10 EUR = 5.0 USD (1 EUR = 0.5 USD)')
        now_date = datetime.now().strftime('%Y%m%d')
        self.assertEqual(results[0]['url'], 'http://finance.yahoo.com/currency/converter-results/' +
                                            now_date + '/10-eur-to-usd.html')
    def test_response(self):
        dicto = defaultdict(dict)
        dicto['ammount'] = float(10)
        dicto['from'] = "GBP"
        dicto['to'] = "USD"
        dicto['from_name'] = "pound sterling"
        dicto['to_name'] = "United States dollar"
        response = mock.Mock(text='a,b,c,d', search_params=dicto)
        self.assertEqual(currency_convert.response(response), [])

        csv = "2,0.5,1"
        response = mock.Mock(text=csv, search_params=dicto)
        results = currency_convert.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['answer'], '10.0 GBP = 5.0 USD, 1 GBP (pound sterling)' +
                         ' = 0.5 USD (United States dollar)')
        now_date = datetime.now().strftime('%Y%m%d')
        self.assertEqual(results[0]['url'], 'https://finance.yahoo.com/currency/converter-results/' +
                                            now_date + '/10.0-gbp-to-usd.html')
    def test_response(self):
        dicto = defaultdict(dict)
        dicto['amount'] = float(10)
        dicto['from'] = "GBP"
        dicto['to'] = "USD"
        dicto['from_name'] = "pound sterling"
        dicto['to_name'] = "United States dollar"
        response = mock.Mock(text='a,b,c,d', search_params=dicto)
        self.assertEqual(currency_convert.response(response), [])

        body = "<span class=bld>0.5 {}</span>".format(dicto['to'])
        response = mock.Mock(text=body, search_params=dicto)
        results = currency_convert.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['answer'], '10.0 GBP = 5.0 USD, 1 GBP (pound sterling)' +
                         ' = 0.5 USD (United States dollar)')

        target_url = 'https://finance.google.com/finance?q={}{}'.format(
            dicto['from'], dicto['to'])
        self.assertEqual(results[0]['url'], target_url)