Skip to content

Commit

Permalink
✨ Move CBR currency codes to Currency class
Browse files Browse the repository at this point in the history
  • Loading branch information
esemi committed May 8, 2021
1 parent eeea022 commit 1539322
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
19 changes: 13 additions & 6 deletions investments/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Currency(Enum):
EUR = (('€', 'EUR'), '978', 'R01239')

def __init__(self, aliases: Tuple[str], iso_code: str, cbr_code: str):
self.iso_code = iso_code
self.cbr_code = cbr_code
self._iso_code = iso_code
self._cbr_code = cbr_code
self.aliases = aliases

@staticmethod
Expand All @@ -35,10 +35,17 @@ def iso_numeric_code(self) -> str:
"""
Код валюты в соответствии с общероссийским классификатором валют (ОК (МК (ИСО 4217) 003-97) 014-2000).
see https://classifikators.ru/okv
@see https://classifikators.ru/okv
Raises:
ValueError: if currency is unsupported
"""
return self._iso_code

@property
def cbr_code(self) -> str:
"""
Код валюты в соответствии с классификатором ЦБ РФ.
@see http://www.cbr.ru/scripts/XML_daily_eng.asp?date_req=22/01/2020
"""
return self.iso_code
return self._cbr_code
9 changes: 9 additions & 0 deletions tests/currency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ def test_repr(currency: Currency, expected_repr: str):
])
def test_iso_numeric_code(currency: Currency, expected: str):
assert currency.iso_numeric_code == expected


@pytest.mark.parametrize('currency,expected', [
(Currency.USD, 'R01235'),
(Currency.RUB, ''),
(Currency.EUR, 'R01239'),
])
def test_cbr_code(currency: Currency, expected: str):
assert currency.cbr_code == expected

0 comments on commit 1539322

Please sign in to comment.