Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    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')
Beispiel #4
0
    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')
Beispiel #5
0
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
Beispiel #6
0
 def test_http(self):
     s = OpenExchangeRates(app_id='', use_https=False)
     assert 'http' in s.get_url('')
     assert 'https' not in s.get_url('')
Beispiel #7
0
 def test_endpoint(self):
     s = OpenExchangeRates(app_id='')
     assert 'endpoint.json' in s.get_url('endpoint')
     assert 'endpoint.json' in s.get_url('endpoint.json')
Beispiel #8
0
 def test_https(self):
     s = OpenExchangeRates(app_id='', use_https=True)
     assert 'https' in s.get_url('')
Beispiel #9
0
 def test_http(self):
     s = OpenExchangeRates(app_id='', use_https=False)
     assert 'http' in s.get_url('')
     assert 'https' not in s.get_url('')
Beispiel #10
0
 def test_endpoint(self):
     s = OpenExchangeRates(app_id='')
     assert 'endpoint.json' in s.get_url('endpoint')
     assert 'endpoint.json' in s.get_url('endpoint.json')
Beispiel #11
0
 def test_https(self):
     s = OpenExchangeRates(app_id='', use_https=True)
     assert 'https' in s.get_url('')
Beispiel #12
0
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