Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starts to fix Issue #651: begins with deprecation warning #653

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
cryptomail marked this conversation as resolved.
Show resolved Hide resolved
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