From 817a96bd97240cb61e32cd74ecf37f951c084edb Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Mon, 6 Feb 2023 17:29:53 -0800 Subject: [PATCH] Unit testing --- test_zoho_auth.py | 24 ++++++++++++++++++++++++ zoho_auth.py | 2 -- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test_zoho_auth.py diff --git a/test_zoho_auth.py b/test_zoho_auth.py new file mode 100644 index 0000000..7faa01d --- /dev/null +++ b/test_zoho_auth.py @@ -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() \ No newline at end of file diff --git a/zoho_auth.py b/zoho_auth.py index f9e09b6..3719ade 100644 --- a/zoho_auth.py +++ b/zoho_auth.py @@ -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