Skip to content

Commit

Permalink
Starts to fix Issue #651: begins with deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptomail committed Sep 12, 2024
1 parent dc007f7 commit 22e1bc1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_api/test_other_zendesk_objects.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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")

9 changes: 9 additions & 0 deletions zenpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 22e1bc1

Please sign in to comment.