36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
|
import unittest
|
||
|
from unittest.mock import patch
|
||
|
|
||
|
from api import Tronscan
|
||
|
|
||
|
|
||
|
class TestExternalAPICalls(unittest.TestCase):
|
||
|
|
||
|
def setUp(self):
|
||
|
# Setup code runs before every test method
|
||
|
self.tronscan = Tronscan(api_key='cc87d361-7cd6-4f69-a57b-f0a77a213355')
|
||
|
|
||
|
@unittest.skip("Skipping this test temporarily")
|
||
|
@patch('requests.get')
|
||
|
def test_real_api_call(self, mock_get):
|
||
|
# Mocking API response
|
||
|
mock_response = {
|
||
|
"data": [{"name": "ExampleToken", "symbol": "ETK"}]
|
||
|
}
|
||
|
mock_get.return_value.status_code = 200
|
||
|
mock_get.return_value.json.return_value = mock_response
|
||
|
|
||
|
# Call the method
|
||
|
response = self.tronscan.search(term="example", type="token")
|
||
|
|
||
|
# Assert the response
|
||
|
self.assertEqual(response, mock_response)
|
||
|
mock_get.assert_called_once_with(
|
||
|
"https://apilist.tronscanapi.com/api/search/v2",
|
||
|
headers={'TRON-PRO-API-KEY': self.api_key},
|
||
|
params={"term": "example", "type": "token", "start": 0, "limit": 10}
|
||
|
)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
unittest.main()
|