Change CryptoToFiatConverter._is_supported_fiat to Static method

We do not need to load the whole object to know if a pair is
in a static list.
Unittest passed from 1.25s to 0.08s
This commit is contained in:
Gerald Lonlas 2018-01-21 13:51:11 -08:00
parent 408f120612
commit 074a4ef65b
2 changed files with 9 additions and 10 deletions

View File

@ -87,7 +87,7 @@ class CryptoToFiatConverter():
fiat_symbol = fiat_symbol.upper()
# Check if the fiat convertion you want is supported
if not self._is_supported_fiat(fiat=fiat_symbol):
if not CryptoToFiatConverter.is_supported_fiat(fiat=fiat_symbol):
raise ValueError('The fiat {} is not supported.'.format(fiat_symbol))
# Get the pair that interest us and return the price in fiat
@ -131,7 +131,7 @@ class CryptoToFiatConverter():
return price
def _is_supported_fiat(self, fiat: str) -> bool:
def is_supported_fiat(fiat: str) -> bool:
"""
Check if the FIAT your want to convert to is supported
:param fiat: FIAT to check (e.g USD)
@ -140,7 +140,7 @@ class CryptoToFiatConverter():
fiat = fiat.upper()
return fiat in self.SUPPORTED_FIAT
return fiat in CryptoToFiatConverter.SUPPORTED_FIAT
def _find_price(self, crypto_symbol: str, fiat_symbol: str) -> float:
"""
@ -150,7 +150,7 @@ class CryptoToFiatConverter():
:return: float, price of the crypto-currency in Fiat
"""
# Check if the fiat convertion you want is supported
if not self._is_supported_fiat(fiat=fiat_symbol):
if not CryptoToFiatConverter.is_supported_fiat(fiat=fiat_symbol):
raise ValueError('The fiat {} is not supported.'.format(fiat_symbol))
try:
return float(

View File

@ -36,12 +36,11 @@ def test_pair_convertion_object():
assert pair_convertion.price == 30000.123
def test_fiat_convert_is_supported():
fiat_convert = CryptoToFiatConverter()
assert fiat_convert._is_supported_fiat(fiat='USD') is True
assert fiat_convert._is_supported_fiat(fiat='usd') is True
assert fiat_convert._is_supported_fiat(fiat='abc') is False
assert fiat_convert._is_supported_fiat(fiat='ABC') is False
def test_fiat_convert_is_supported(mocker):
assert CryptoToFiatConverter.is_supported_fiat(fiat='USD') is True
assert CryptoToFiatConverter.is_supported_fiat(fiat='usd') is True
assert CryptoToFiatConverter.is_supported_fiat(fiat='abc') is False
assert CryptoToFiatConverter.is_supported_fiat(fiat='ABC') is False
def test_fiat_convert_add_pair():