add test for new fiat_convert logic
This commit is contained in:
parent
b1c53ec656
commit
8549201502
@ -54,17 +54,19 @@ def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> Non
|
||||
:param mocker: mocker to patch coinmarketcap class
|
||||
:return: None
|
||||
"""
|
||||
mock = MagicMock()
|
||||
|
||||
if value:
|
||||
mock.ticker = {'price_usd': 12345.0}
|
||||
mock.listings = {'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
|
||||
'website_slug': 'bitcoin'},
|
||||
{'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH',
|
||||
'website_slug': 'ethereum'}
|
||||
]}
|
||||
tickermock = MagicMock(return_value={'price_usd': 12345.0})
|
||||
listmock = MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
|
||||
'website_slug': 'bitcoin'},
|
||||
{'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH',
|
||||
'website_slug': 'ethereum'}
|
||||
]})
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.fiat_convert.Market',
|
||||
ticker=tickermock,
|
||||
listings=listmock,
|
||||
|
||||
mocker.patch('freqtrade.fiat_convert.Market', mock)
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
|
@ -7,6 +7,7 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from freqtrade.fiat_convert import CryptoFiat, CryptoToFiatConverter
|
||||
from freqtrade.tests.conftest import patch_coinmarketcap
|
||||
|
||||
|
||||
def test_pair_convertion_object():
|
||||
@ -123,6 +124,15 @@ def test_fiat_convert_get_price(mocker):
|
||||
assert fiat_convert._pairs[0]._expiration is not expiration
|
||||
|
||||
|
||||
def test_loadcryptomap(mocker):
|
||||
patch_coinmarketcap(mocker)
|
||||
|
||||
fiat_convert = CryptoToFiatConverter()
|
||||
assert len(fiat_convert._cryptomap) == 2
|
||||
|
||||
assert fiat_convert._cryptomap["BTC"] == "1"
|
||||
|
||||
|
||||
def test_fiat_convert_without_network():
|
||||
# Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user