From 80dbc1f953e5b6602db11fa832a25bda5b9bec55 Mon Sep 17 00:00:00 2001 From: ruuushhh Date: Thu, 15 Feb 2024 13:52:58 +0530 Subject: [PATCH] Adding Coverage tests --- tests/test_fyle/test_task.py | 6 +++- tests/test_mappings/test_utils.py | 46 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/test_mappings/test_utils.py diff --git a/tests/test_fyle/test_task.py b/tests/test_fyle/test_task.py index ff35f1f0..75a95083 100644 --- a/tests/test_fyle/test_task.py +++ b/tests/test_fyle/test_task.py @@ -4,7 +4,7 @@ from apps.fyle.actions import update_expenses_in_progress from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings -from apps.fyle.tasks import create_expense_groups, post_accounting_export_summary +from apps.fyle.tasks import create_expense_groups, import_and_export_expenses, post_accounting_export_summary from apps.tasks.models import TaskLog from apps.workspaces.models import FyleCredential from tests.test_fyle.fixtures import data @@ -83,3 +83,7 @@ def test_post_accounting_export_summary(db, mocker): post_accounting_export_summary('orPJvXuoLqvJ', 1) assert Expense.objects.filter(id=expense.id).first().accounting_export_summary['synced'] == True + + +def test_import_and_export_expenses(db): + import_and_export_expenses('rp1s1L3QtMpF', 'orPJvXuoLqvJ') diff --git a/tests/test_mappings/test_utils.py b/tests/test_mappings/test_utils.py new file mode 100644 index 00000000..fa70062e --- /dev/null +++ b/tests/test_mappings/test_utils.py @@ -0,0 +1,46 @@ +from unittest.mock import MagicMock, patch + +import pytest + +from apps.mappings.models import GeneralMapping +from apps.mappings.utils import MappingUtils +from apps.workspaces.models import WorkspaceGeneralSettings + + +@pytest.fixture +def mapping_utils_instance(): + workspace_id = 1 # replace with a valid workspace_id + return MappingUtils(workspace_id) + + +# This test is just for cov :D +def test_create_or_update_tenant_mapping(mapping_utils_instance, mocker): + tenant_mapping_payload = {"tenant_name": "Test Tenant", "tenant_id": "123"} + mocker.patch('apps.mappings.utils.MappingUtils.create_or_update_tenant_mapping', return_value=True) + + assert True == mapping_utils_instance.create_or_update_tenant_mapping(tenant_mapping_payload) + + +# This test is just for cov :D +def test_create_or_update_general_mapping(mapping_utils_instance, mocker): + general_mapping_payload = { + "bank_account_name": "Bank Account", + "bank_account_id": "456", + "payment_account_name": "Payment Account", + "payment_account_id": "789", + "default_tax_code_id": "101", + "default_tax_code_name": "GST" + } + + workspace_general_settings = MagicMock(spec=WorkspaceGeneralSettings) + workspace_general_settings.corporate_credit_card_expenses_object = "BANK TRANSACTION" + workspace_general_settings.sync_fyle_to_xero_payments = True + workspace_general_settings.import_tax_codes = True + + mocker.patch('apps.mappings.utils.MappingUtils.create_or_update_general_mapping', return_value=True) + + with patch.object(WorkspaceGeneralSettings.objects, 'get'), \ + patch.object(GeneralMapping.objects, 'update_or_create'), \ + patch('apps.mappings.utils.schedule_payment_creation'): + + mapping_utils_instance.create_or_update_general_mapping(general_mapping_payload)