def test_latest(self): s = OpenExchangeRates(app_id='123') s.get_url = mock.Mock() s.url_opener.open = mock.Mock(return_value={'base': '', 'rates': {}}) # if we don't consume all the generator the assertion doesn't works list(s.latest()) assert s.get_url.called assert s.url_opener.open.called
def test_result(self): s = OpenExchangeRates(app_id='123') s.get_url = mock.Mock() s.url_opener.open = mock.Mock( return_value={'base': 'USD', 'rates': {'EUR': '0.78'}}) usd_clp, = list(s.latest()) assert usd_clp.code_from == 'USD' assert usd_clp.code_to == 'EUR' assert usd_clp.rate == decimal.Decimal('0.78')
def test_result(self): s = OpenExchangeRates(app_id='123') s.get_url = mock.Mock() s.url_opener.open = mock.Mock(return_value={ 'base': 'USD', 'rates': { 'EUR': '0.78' } }) usd_clp, = list(s.latest()) assert usd_clp.code_from == 'USD' assert usd_clp.code_to == 'EUR' assert usd_clp.rate == decimal.Decimal('0.78')
from rockefeller.services import OpenExchangeRates, ServiceError from rockefeller.utils import basic_config_logging_handler # use this for log the openexchangerates service request and response to the # console. basic_config_logging_handler() APP_ID = 'your app id here' service = OpenExchangeRates(app_id=APP_ID) try: exchange_rates = service.latest() except ServiceError as e: print e.message else: for exchange_rate in exchange_rates: print exchange_rate