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 15 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
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ jobs:
virtualenv -p python3 /usr/local/share/virtualenvs/tap-zendesk
source /usr/local/share/virtualenvs/tap-zendesk/bin/activate
pip install .[test]
pip install coverage
- run:
name: 'pylint'
command: |
source /usr/local/share/virtualenvs/tap-zendesk/bin/activate
make test
pylint tap_zendesk -d missing-docstring,invalid-name,line-too-long,too-many-locals,too-few-public-methods,fixme,stop-iteration-return,too-many-branches,useless-import-alias,no-else-return,logging-not-lazy
nosetests --with-coverage --cover-erase --cover-package=tap_zendesk --cover-html-dir=htmlcov test/unittests
coverage html
- add_ssh_keys
- store_test_results:
path: test_output/report.xml
- store_artifacts:
path: htmlcov
- run:
name: 'Integration Tests'
command: |
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'pylint==2.8.3',
'nose',
'nose-watch',
'pytest'
]
},
entry_points='''
Expand Down
6 changes: 5 additions & 1 deletion tap_zendesk/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ 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.":

error = json.loads(e.args[0]).get('error')
# check if the error is of type dictionary and the message retrieved from the dictionary
# is the expected message. If so, only then print the logger message and return the schema
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
Expand Down
55 changes: 55 additions & 0 deletions test/unittests/test_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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):
"""
Test whether the specific logger message is correctly printed when access error occurs and the error is a dict
"""
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):
"""
Test whether the no logger message is printed in case of errors other then access error and the exception is raised
"""
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

"""
Test whether the exception is raised when the error is a dict but with different error message
"""
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)