Skip to content

Commit

Permalink
Merge pull request #47 from almabekov/are-6130-python-wrapper-for-cur…
Browse files Browse the repository at this point in the history
…rencies-endpoint

ARE-6130: Python wrapper for currencies endpoint
  • Loading branch information
almabekov authored Feb 11, 2019
2 parents 2914d3d + 2a4c04a commit 8407f3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
10 changes: 9 additions & 1 deletion analyzere/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ def profile(self):
# Exchange rate tables

class ExchangeRateTable(DataResource):
pass
def currencies(self):
path = '{}/currencies'.format(self._get_path(self.id))
resp = request('get', path)
# response will be an embedded object with currencies list
# each element of the currencies list is again an embedded object with the structure like:
# {
# "code": "CAD"
# }
return convert_to_analyzere_object(resp)


class ExchangeRateSelectionRule(EmbeddedResource):
Expand Down
32 changes: 31 additions & 1 deletion tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import analyzere
from analyzere import MonetaryUnit, LayerPolicy
from analyzere.resources import PortfolioView, LayerView
from analyzere.resources import PortfolioView, LayerView, ExchangeRateTable


class SetBaseUrl(object):
Expand Down Expand Up @@ -80,3 +80,33 @@ def test_get_results(self, reqmock):
assert req_json['remove_layer_view_ids'][0]['ref_id'] == 'yyy'

assert pv.id == 'a1'

# ARE-6130 wrapper for the exchange rate table unique currencies function
def test_unique_currencies(self, reqmock):
# mock for the Exchange Rate table request
reqmock.get('https://api/exchange_rate_tables/abc_id',
status_code=200, text='{"id": "abc_id"}')

fx_table = ExchangeRateTable.retrieve('abc_id')
# mock for the currencies method call
reqmock.get('https://api/exchange_rate_tables/abc_id/currencies',
status_code=200, text='{"currencies": [{"code": "CAD"}, {"code": "EUR"}]}')
curr = fx_table.currencies()
assert hasattr(curr, 'currencies')
assert len(curr.currencies) == 2
currencies = set()
for c in curr.currencies:
currencies.add(c['code'])
assert currencies == {'EUR', 'CAD'}

# we still should have save the empty currencies list
def test_unique_currencies_empty(self, reqmock):
reqmock.get('https://api/exchange_rate_tables/abc_id',
status_code=200, text='{"id":"abc_id"}')
fx_table = ExchangeRateTable.retrieve('abc_id')

reqmock.get('https://api/exchange_rate_tables/abc_id/currencies',
status_code=200, text='{"currencies": []}')
curr = fx_table.currencies()
assert hasattr(curr, 'currencies')
assert len(curr.currencies) == 0

0 comments on commit 8407f3d

Please sign in to comment.