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-20208 Add warning message for pro account plan. #49

Open
wants to merge 6 commits into
base: TDL-20359-add-custom-exception-handling
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Added warning message for pro account plan.
prijendev committed Aug 24, 2022
commit c7254816cf782932647c8aee436bd43653ef808c
7 changes: 6 additions & 1 deletion tap_freshdesk/client.py
Original file line number Diff line number Diff line change
@@ -134,7 +134,12 @@ def check_access_token(self):
"""
Check if the access token is valid.
"""
self.request(self.base_url+"/api/v2/roles", {"per_page": 1, "page": 1})
try:
self.request(self.base_url+"/api/v2/tickets/1/time_entries", {"per_page": 1, "page": 1})
except FresdeskAccessDeniedError:
LOGGER.warning("The `Surveys` and the `Timesheets` features are not supported in your current plan. "\
"So, Data collection cannot be initiated for satisfaction_ratings and time_entries streams. "\
"Please upgrade your account to `Pro` plan to use it.")

Choose a reason for hiding this comment

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

it is not the only reason so we should write this in might context like this might be the reason so check your account.

Copy link
Author

Choose a reason for hiding this comment

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

Updated warning message.


@backoff.on_exception(backoff.expo,
(TimeoutError, ConnectionError, Server5xxError),
56 changes: 56 additions & 0 deletions tests/unittests/test_check_access_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import unittest
from unittest import mock

from tap_freshdesk import client
from parameterized import parameterized


@mock.patch("tap_freshdesk.client.FreshdeskClient.request")
class TestAccessToken(unittest.TestCase):
"""
Test case to verify the `check_access_token` method.
"""
@parameterized.expand([
('free_account_with_invalid_token', client.FresdeskAuthenticationError, 'The Authorization header is either missing or incorrect.'),
('free_account_with_invalid_domain', client.FresdeskNotFoundError, 'The request contains invalid ID/Freshdesk domain in the URL or an invalid URL itself.')
])
def test_invalid_domain_or_token(self, mock_request, name, error, err_message):
"""
Verify that tap raise error for an invalid token or invalid domain name.
"""
config = {}
mock_request.side_effect = error(err_message)
_client = client.FreshdeskClient(config)
with self.assertRaises(error) as e:
_client.check_access_token()

# Verify that an error message is expected
self.assertEqual(str(e.exception), err_message)

@mock.patch("tap_freshdesk.client.LOGGER.warning")
def test_free_account(self, mock_request, mock_logger):
"""
Verify that tap provide a warning message to upgrade the current free account to the pro account.
Because `satisfaction_ratings` and `time_entries` streams are accessible only for the pro account.
"""
config = {}
mock_request.side_effect = client.FresdeskAccessDeniedError
_client = client.FreshdeskClient(config)

_client.check_access_token()

# Verify that `LOGGER.warning` is called for 1 time.
self.assertEqual(mock_logger.call_count, 1)
dbshah1212 marked this conversation as resolved.
Show resolved Hide resolved

@mock.patch("tap_freshdesk.client.LOGGER.warning")
def test_pro_account_plan(self, mock_logger, mock_request):
"""
Verify that tap does not raise any error or provide any warning message for the pro account plan.
"""
config = {}
_client = client.FreshdeskClient(config)

_client.check_access_token()

# Verify that `LOGGER.warning` is not called.
self.assertEqual(mock_logger.call_count, 0)