Unit testing

This commit is contained in:
George Hotelling 2023-02-06 17:29:53 -08:00
parent 6ed0f49cce
commit 817a96bd97
2 changed files with 24 additions and 2 deletions

24
test_zoho_auth.py Normal file
View File

@ -0,0 +1,24 @@
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()

View File

@ -31,8 +31,6 @@ class ZohoToken:
self.update_token()
return self.access_token
zoho_token = ZohoToken(ZOHO_CLIENT_ID, ZOHO_CLIENT_SECRET, ZOHO_REFRESH_TOKEN)
def authenticate(token, key):
ret = False