diff --git a/tests/test_api/test_other_zendesk_objects.py b/tests/test_api/test_other_zendesk_objects.py index e40faac..640b971 100644 --- a/tests/test_api/test_other_zendesk_objects.py +++ b/tests/test_api/test_other_zendesk_objects.py @@ -1,5 +1,7 @@ +import logging from time import sleep - +from zenpy.lib.api import ZenpyException +from zenpy import Zenpy from test_api.fixtures import ZenpyApiTestCase from test_api.fixtures.__init__ import ( @@ -36,6 +38,7 @@ from zenpy.lib import util from datetime import datetime, timezone from unittest import TestCase +from unittest.mock import MagicMock class DateTimeTest(TestCase): def test_datetime_import(self): @@ -428,3 +431,24 @@ def test_users_me(self): me = self.zenpy_client.users.me() self.assertNotEqual(me, None, "me is valid") self.assertNotEqual(me.email, "", "email is valid in me") + +class TestPasswordDeprecation(ZenpyApiTestCase): + __test__ = True + def test_password_failure(self): + log = logging.getLogger() + log.error = MagicMock(return_value="error issued") + with self.assertRaises(ZenpyException): + zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer", password_treatment_level="error") + log.error.assert_called_once_with("ERROR **** PASSWORDS WILL BE DISABLED **** https://github.com/facetoe/zenpy/issues/651 https://support.zendesk.com/hc/en-us/articles/7386291855386-Announcing-the-deprecation-of-password-access-for-APIs") + def test_password_passes(self): + log = logging.getLogger() + log.warning = MagicMock(return_value="warning issued") + zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer", password_treatment_level="warning") + log.warning.assert_called_once_with("WARNING **** PASSWORDS WILL BE DISABLED **** https://github.com/facetoe/zenpy/issues/651 https://support.zendesk.com/hc/en-us/articles/7386291855386-Announcing-the-deprecation-of-password-access-for-APIs") + + def test_password_passes_no_deprecation(self): + log = logging.getLogger() + log.warning = MagicMock(return_value="warning issued") + zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer") + log.warning.assert_called_once_with("WARNING **** PASSWORDS WILL BE DISABLED **** https://github.com/facetoe/zenpy/issues/651 https://support.zendesk.com/hc/en-us/articles/7386291855386-Announcing-the-deprecation-of-password-access-for-APIs") + diff --git a/zenpy/__init__.py b/zenpy/__init__.py index b81892e..6dcd808 100644 --- a/zenpy/__init__.py +++ b/zenpy/__init__.py @@ -83,6 +83,7 @@ def __init__( proactive_ratelimit=None, proactive_ratelimit_request_interval=10, disable_cache=False, + password_treatment_level="warning" ): """ Python Wrapper for the Zendesk API. @@ -107,6 +108,14 @@ def __init__( seconds to wait when over proactive_ratelimit. :param disable_cache: disable caching of objects """ + if password_treatment_level == "warning": + if password is not None: + log.warning("WARNING **** PASSWORDS WILL BE DISABLED **** https://github.com/facetoe/zenpy/issues/651 https://support.zendesk.com/hc/en-us/articles/7386291855386-Announcing-the-deprecation-of-password-access-for-APIs") + + if password_treatment_level == "error": + if password is not None: + log.error("ERROR **** PASSWORDS WILL BE DISABLED **** https://github.com/facetoe/zenpy/issues/651 https://support.zendesk.com/hc/en-us/articles/7386291855386-Announcing-the-deprecation-of-password-access-for-APIs") + raise ZenpyException("ERROR **** PASSWORDS WILL BE DISABLED **** https://github.com/facetoe/zenpy/issues/651 https://support.zendesk.com/hc/en-us/articles/7386291855386-Announcing-the-deprecation-of-password-access-for-APIs") session = self._init_session(email, token, oauth_token, password, session, anonymous)