Skip to content

Commit e168d92

Browse files
authored
Merge pull request #653 from facetoe/zendesk/deprecation_of_passwords
Starts to fix Issue #651: begins with deprecation warning
2 parents 3302ba9 + 22e1bc1 commit e168d92

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/test_api/test_other_zendesk_objects.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import logging
12
from time import sleep
2-
3+
from zenpy.lib.api import ZenpyException
4+
from zenpy import Zenpy
35
from test_api.fixtures import ZenpyApiTestCase
46

57
from test_api.fixtures.__init__ import (
@@ -36,6 +38,7 @@
3638
from zenpy.lib import util
3739
from datetime import datetime, timezone
3840
from unittest import TestCase
41+
from unittest.mock import MagicMock
3942

4043
class DateTimeTest(TestCase):
4144
def test_datetime_import(self):
@@ -428,3 +431,24 @@ def test_users_me(self):
428431
me = self.zenpy_client.users.me()
429432
self.assertNotEqual(me, None, "me is valid")
430433
self.assertNotEqual(me.email, "", "email is valid in me")
434+
435+
class TestPasswordDeprecation(ZenpyApiTestCase):
436+
__test__ = True
437+
def test_password_failure(self):
438+
log = logging.getLogger()
439+
log.error = MagicMock(return_value="error issued")
440+
with self.assertRaises(ZenpyException):
441+
zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer", password_treatment_level="error")
442+
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")
443+
def test_password_passes(self):
444+
log = logging.getLogger()
445+
log.warning = MagicMock(return_value="warning issued")
446+
zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer", password_treatment_level="warning")
447+
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")
448+
449+
def test_password_passes_no_deprecation(self):
450+
log = logging.getLogger()
451+
log.warning = MagicMock(return_value="warning issued")
452+
zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer")
453+
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")
454+

zenpy/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(
8383
proactive_ratelimit=None,
8484
proactive_ratelimit_request_interval=10,
8585
disable_cache=False,
86+
password_treatment_level="warning"
8687
):
8788
"""
8889
Python Wrapper for the Zendesk API.
@@ -107,6 +108,14 @@ def __init__(
107108
seconds to wait when over proactive_ratelimit.
108109
:param disable_cache: disable caching of objects
109110
"""
111+
if password_treatment_level == "warning":
112+
if password is not None:
113+
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")
114+
115+
if password_treatment_level == "error":
116+
if password is not None:
117+
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")
118+
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")
110119

111120
session = self._init_session(email, token, oauth_token,
112121
password, session, anonymous)

0 commit comments

Comments
 (0)