added return value mock + added test for get_coins

This commit is contained in:
Jamie
2021-04-08 08:40:21 -04:00
parent 7332c76136
commit bc610b84d4
3 changed files with 28 additions and 2 deletions

View File

@@ -1,5 +1,9 @@
from pycoingecko import CoinGeckoAPI
"""
Helper script that generates a dictionary to convert between symbols and IDs.
This allows the user to input (for example) "btc" instead of the expected "bitcoin"
"""
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()
coins = cg.get_coins()

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,6 @@
from unittest import mock, TestCase
import json
from pycoingecko import CoinGeckoAPI
from gamestonk_terminal.cryptocurrency.coin_api import load
# pylint: disable=unused-import
@@ -9,6 +11,25 @@ class TestCoinGeckoAPI(TestCase):
"gamestonk_terminal.cryptocurrency.coin_api.CoinGeckoAPI.get_coin_market_chart_by_id"
)
def test_coin_api_load(self, mock_load):
coin, _ = load(["-c", "bitcoin"])
"""
Mock load function through get_coin_market_chart_by_id.
Mock returns a dict saved as .json
"""
with open("tests/data/btc_usd_test_data.json") as f:
sample_return = json.load(f)
mock_load.return_value = sample_return
coin, mock_return = load(["-c", "bitcoin"])
self.assertEqual(coin, "bitcoin")
self.assertTrue(mock_load.called)
self.assertTrue(mock_return.shape == (722, 2))
def test_coin(self):
"""Test that pycoingecko retreives the major coins"""
coins = CoinGeckoAPI().get_coins()
coin_list = [coin["id"] for coin in coins]
test_coins = ["bitcoin", "ethereum", "dogecoin"]
for test in test_coins:
self.assertIn(test, coin_list)