From bbce745aab99042c6dae6f4930efafe0547815ef Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Fri, 6 Oct 2023 11:25:04 +0530 Subject: [PATCH] add test --- apps/fyle/actions.py | 1 + tests/test_fyle/test_actions.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/fyle/actions.py b/apps/fyle/actions.py index 69577e1d..2f778110 100644 --- a/apps/fyle/actions.py +++ b/apps/fyle/actions.py @@ -227,6 +227,7 @@ def update_complete_expenses(exported_expenses: List[Expense], url: str) -> None __bulk_update_expenses(expense_to_be_updated) + @retry(n=3, backoff=1, exceptions=InternalServerError) def bulk_post_accounting_export_summary(platform: PlatformConnector, payload: List[dict]): """ diff --git a/tests/test_fyle/test_actions.py b/tests/test_fyle/test_actions.py index 6bfeab3c..982ec376 100644 --- a/tests/test_fyle/test_actions.py +++ b/tests/test_fyle/test_actions.py @@ -1,11 +1,22 @@ +from unittest import mock + from django.conf import settings from django.db.models import Q +from fyle_integrations_platform_connector import PlatformConnector +from fyle.platform.exceptions import InternalServerError, RetryException + from apps.fyle.models import Expense, ExpenseGroup -from apps.fyle.actions import update_expenses_in_progress, mark_expenses_as_skipped, \ - mark_accounting_export_summary_as_synced, update_failed_expenses, update_complete_expenses +from apps.fyle.actions import ( + update_expenses_in_progress, + mark_expenses_as_skipped, + mark_accounting_export_summary_as_synced, + update_failed_expenses, + update_complete_expenses, + bulk_post_accounting_export_summary +) from apps.fyle.helpers import get_updated_accounting_export_summary -from apps.workspaces.models import Workspace +from apps.workspaces.models import Workspace, FyleCredential def test_update_expenses_in_progress(db): @@ -89,3 +100,15 @@ def test_update_complete_expenses(db): assert expense.accounting_export_summary['error_type'] == None assert expense.accounting_export_summary['url'] == 'https://qbo.google.com' assert expense.accounting_export_summary['id'] == expense.expense_id + + +def test_bulk_post_accounting_export_summary(db): + fyle_credentails = FyleCredential.objects.get(workspace_id=3) + platform = PlatformConnector(fyle_credentails) + + with mock.patch('fyle.platform.apis.v1beta.admin.Expenses.post_bulk_accounting_export_summary') as mock_call: + mock_call.side_effect = InternalServerError('Timeout') + try: + bulk_post_accounting_export_summary(platform, {}) + except RetryException: + assert mock_call.call_count == 3