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

TDL-14799 added an extra check to verify if the error has message in … #69

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions tap_zendesk/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def raise_or_log_zenpy_apiexception(schema, stream, e):
# it doesn't have access.
if not isinstance(e, zenpy.lib.exception.APIException):
raise ValueError("Called with a bad exception type") from e
if json.loads(e.args[0])['error']['message'] == "You do not have access to this page. Please contact the account owner of this help desk for further help.":
LOGGER.warning("The account credentials supplied do not have access to `%s` custom fields.",

error = json.loads(e.args[0]).get('error')
if isinstance(error, dict) and error.get('message', None) == "You do not have access to this page. Please contact the account owner of this help desk for further help.":
KrisPersonal marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.warning("The account credentials supplied do not have access to `%s` custom fields.",
stream)
return schema
else:
Expand Down
46 changes: 46 additions & 0 deletions test/unittests/test_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import unittest
from tap_zendesk import get_session
from unittest import mock
from pytest import raises
from tap_zendesk.streams import raise_or_log_zenpy_apiexception, zenpy, json, LOGGER

class ValueError(Exception):
def __init__(self, m):
self.message = m

def __str__(self):
return self.message


class TestException(unittest.TestCase):
@mock.patch("tap_zendesk.streams.LOGGER.warning")
def test_exception_logger(self, mocked_logger):
schema = {}
stream = 'test_stream'
error_string = '{"error":{"message": "You do not have access to this page. Please contact the account owner of this help desk for further help."}' + "}"
e = zenpy.lib.exception.APIException(error_string)
raise_or_log_zenpy_apiexception(schema, stream, e)
mocked_logger.assert_called_with(
"The account credentials supplied do not have access to `%s` custom fields.",
stream)

def test_zenpy_exception_raised(self):
try:
schema = {}
stream = 'test_stream'
error_string = '{"error": "invalid_token", "error_description": "The access token provided is expired, revoked, malformed or invalid for other reasons."}'
e = zenpy.lib.exception.APIException(error_string)
raise_or_log_zenpy_apiexception(schema, stream, e)
except zenpy.lib.exception.APIException as ex:
self.assertEqual(str(ex), error_string)


def test_zenpy_exception_but_different_message_raised(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here.

Added comments

try:
schema = {}
stream = 'test_stream'
error_string = '{"error":{"message": "Could not authenticate you"}' + "}"
e = zenpy.lib.exception.APIException(error_string)
raise_or_log_zenpy_apiexception(schema, stream, e)
except zenpy.lib.exception.APIException as ex:
self.assertEqual(str(ex), error_string)