Add test, invert logic
This commit is contained in:
@@ -16,10 +16,11 @@ class FtCoinGeckoApi(CoinGeckoAPI):
|
|||||||
# Doint' pass api_key to parent, instead set the header on the session directly
|
# Doint' pass api_key to parent, instead set the header on the session directly
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
|
|
||||||
if api_key and is_demo:
|
if api_key and not is_demo:
|
||||||
# Use demo api key
|
|
||||||
self.api_base_url = self.__API_URL_BASE
|
|
||||||
self.session.params.update({"x_cg_demo_api_key": api_key})
|
|
||||||
else:
|
|
||||||
self.api_base_url = self.__PRO_API_URL_BASE
|
self.api_base_url = self.__PRO_API_URL_BASE
|
||||||
self.session.params.update({"x_cg_pro_api_key": api_key})
|
self.session.params.update({"x_cg_pro_api_key": api_key})
|
||||||
|
else:
|
||||||
|
# Use demo api key
|
||||||
|
self.api_base_url = self.__API_URL_BASE
|
||||||
|
if api_key:
|
||||||
|
self.session.params.update({"x_cg_demo_api_key": api_key})
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import pytest
|
|||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
||||||
|
from freqtrade.util.coin_gecko import FtCoinGeckoApi
|
||||||
from tests.conftest import log_has, log_has_re
|
from tests.conftest import log_has, log_has_re
|
||||||
|
|
||||||
|
|
||||||
@@ -201,3 +202,18 @@ def test_convert_amount(mocker):
|
|||||||
crypto_amount="1.23", crypto_symbol="BTC", fiat_symbol="BTC"
|
crypto_amount="1.23", crypto_symbol="BTC", fiat_symbol="BTC"
|
||||||
)
|
)
|
||||||
assert result == 1.23
|
assert result == 1.23
|
||||||
|
|
||||||
|
|
||||||
|
def test_FtCoinGeckoApi():
|
||||||
|
ftc = FtCoinGeckoApi()
|
||||||
|
assert ftc._api_key == ""
|
||||||
|
assert ftc.api_base_url == "https://api.coingecko.com/api/v3/"
|
||||||
|
|
||||||
|
# defaults to demo
|
||||||
|
ftc = FtCoinGeckoApi(api_key="123456")
|
||||||
|
assert ftc._api_key == "123456"
|
||||||
|
assert ftc.api_base_url == "https://api.coingecko.com/api/v3/"
|
||||||
|
|
||||||
|
ftc = FtCoinGeckoApi(api_key="123456", is_demo=False)
|
||||||
|
assert ftc._api_key == "123456"
|
||||||
|
assert ftc.api_base_url == "https://pro-api.coingecko.com/api/v3/"
|
||||||
|
|||||||
Reference in New Issue
Block a user