mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
added return value mock + added test for get_coins
This commit is contained in:
@@ -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()
|
||||
|
||||
1
tests/data/btc_usd_test_data.json
Normal file
1
tests/data/btc_usd_test_data.json
Normal file
File diff suppressed because one or more lines are too long
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user