Skip to content

Commit

Permalink
Handled UnsuccessfulAuthentication during import (#353)
Browse files Browse the repository at this point in the history
* Handled UnsuccessfulAuthentication during import

* Updated sdk version
  • Loading branch information
Hrishabh17 authored Apr 29, 2024
1 parent 6fcacf7 commit beadfbf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
17 changes: 13 additions & 4 deletions apps/mappings/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
WrongParamsError,
RetryException
)
from xerosdk.exceptions import InvalidGrant
from xerosdk.exceptions import InvalidTokenError as XeroInvalidTokenError
from xerosdk.exceptions import UnsuccessfulAuthentication
from xerosdk.exceptions import WrongParamsError as XeroWrongParamsError

from xerosdk.exceptions import (
InvalidGrant,
InvalidTokenError as XeroInvalidTokenError,
UnsuccessfulAuthentication,
WrongParamsError as XeroWrongParamsError
)

from apps.workspaces.models import XeroCredentials
from fyle_integrations_imports.models import ImportLog
Expand Down Expand Up @@ -115,6 +118,12 @@ def new_fn(expense_attribute_instance, *args):
error['response'] = exception.__dict__
import_log.status = 'FAILED'

except UnsuccessfulAuthentication as exception:
error["message"] = "Invalid xero tenant ID or xero-tenant-id header missing in workspace_id - {0}".format(workspace_id)
error["alert"] = False
error['response'] = exception.__dict__
import_log.status = 'FAILED'

except Exception:
response = traceback.format_exc()
error['message'] = 'Something went wrong'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Unidecode==1.1.2
urllib3==1.26.11
wcwidth==0.1.8
wrapt==1.12.1
xerosdk==0.14.0
xerosdk==0.14.1
pytest==7.1.2
pytest-cov==3.0.0
pytest-django==4.5.2
Expand Down
19 changes: 17 additions & 2 deletions tests/test_mappings/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from apps.xero.utils import XeroConnector
from apps.mappings.exceptions import handle_import_exceptions_v2
from fyle.platform.exceptions import InternalServerError, InvalidTokenError, WrongParamsError
from xerosdk.exceptions import InvalidTokenError as XeroInvalidTokenError
from xerosdk.exceptions import WrongParamsError as XeroWrongParamsError
from xerosdk.exceptions import (
InvalidTokenError as XeroInvalidTokenError,
UnsuccessfulAuthentication,
WrongParamsError as XeroWrongParamsError
)


def test_handle_import_exceptions(db, create_temp_workspace, add_xero_credentials, add_fyle_credentials):
Expand Down Expand Up @@ -96,6 +99,18 @@ def to_be_decoreated(expense_attribute_instance, import_log):
assert import_log.error_log['message'] == 'Invalid Token or Xero credentials does not exist workspace_id - 3'
assert import_log.error_log['alert'] == False

# Exception
@handle_import_exceptions_v2
def to_be_decoreated(expense_attribute_instance, import_log):
raise UnsuccessfulAuthentication('Invalid xero tenant ID')

to_be_decoreated(project, import_log)

assert import_log.status == 'FAILED'
assert import_log.error_log['task'] == 'Import PROJECT to Fyle and Auto Create Mappings'
assert import_log.error_log['message'] == 'Invalid xero tenant ID or xero-tenant-id header missing in workspace_id - 3'
assert import_log.error_log['alert'] == False

# Exception
@handle_import_exceptions_v2
def to_be_decoreated(expense_attribute_instance, import_log):
Expand Down

0 comments on commit beadfbf

Please sign in to comment.