Unit testing
This commit is contained in:
parent
6ed0f49cce
commit
817a96bd97
|
@ -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()
|
|
@ -31,8 +31,6 @@ class ZohoToken:
|
||||||
self.update_token()
|
self.update_token()
|
||||||
return self.access_token
|
return self.access_token
|
||||||
|
|
||||||
zoho_token = ZohoToken(ZOHO_CLIENT_ID, ZOHO_CLIENT_SECRET, ZOHO_REFRESH_TOKEN)
|
|
||||||
|
|
||||||
def authenticate(token, key):
|
def authenticate(token, key):
|
||||||
ret = False
|
ret = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue