24 lines
854 B
Python
24 lines
854 B
Python
|
import unittest
|
||
|
from unittest.mock import patch, MagicMock
|
||
|
from zoho_auth import ZohoToken
|
||
|
|
||
|
class TestZohoToken(unittest.TestCase):
|
||
|
"""Test the ZohoToken class"""
|
||
|
|
||
|
@patch('zoho_auth.request')
|
||
|
def test_fetches_token(self, mock_request):
|
||
|
"""Test that the ZohoAuth class fetches a token from the web service"""
|
||
|
mock_response = MagicMock()
|
||
|
mock_response.read.return_value.decode.return_value = '{"access_token": "mock_access_token", "expires_in": 3600}'
|
||
|
mock_request.urlopen.return_value.__enter__.return_value = mock_response
|
||
|
|
||
|
# __init__ calls update_token()
|
||
|
auth = ZohoToken('mock_client_id', 'mock_client_secret', 'mock_refresh_token')
|
||
|
|
||
|
# Assert that the token was fetched
|
||
|
self.assertEqual(auth.access_token, 'mock_access_token')
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|