From 469efda078e73557fb7179d635b745afeb5315be Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Wed, 8 Nov 2023 14:44:55 +0530 Subject: [PATCH] employee mapping error test added --- apps/mappings/tasks.py | 2 -- tests/test_mappings/test_signals.py | 32 +++++++++++++++++++++- tests/test_mappings/test_tasks.py | 41 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index a54b83de..9f19486e 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -79,8 +79,6 @@ def resolve_expense_attribute_errors( type='{}_MAPPING'.format(source_attribute_type) ).values_list('expense_attribute_id', flat=True) - print('errored_attribute_ids', errored_attribute_ids) - if errored_attribute_ids: mapped_attribute_ids = get_mapped_attributes_ids(source_attribute_type, destination_attribute_type, errored_attribute_ids) diff --git a/tests/test_mappings/test_signals.py b/tests/test_mappings/test_signals.py index 1f33c019..a54a5e38 100644 --- a/tests/test_mappings/test_signals.py +++ b/tests/test_mappings/test_signals.py @@ -2,7 +2,37 @@ from django_q.models import Schedule from apps.workspaces.models import Configuration, Workspace from apps.mappings.models import GeneralMapping -from fyle_accounting_mappings.models import MappingSetting, ExpenseAttribute +from apps.tasks.models import Error +from fyle_accounting_mappings.models import MappingSetting, ExpenseAttribute, EmployeeMapping + + +@pytest.mark.django_db() +def test_resolve_post_employees_mapping_errors(access_token): + source_employee = ExpenseAttribute.objects.filter( + value='approver1@fyleforgotham.in', + workspace_id=1, + attribute_type='EMPLOYEE' + ).first() + + Error.objects.update_or_create( + workspace_id=1, + expense_attribute=source_employee, + defaults={ + 'type': 'EMPLOYEE_MAPPING', + 'error_title': source_employee.value, + 'error_detail': 'Employee mapping is missing', + 'is_resolved': False + } + ) + employee_mapping, _ = EmployeeMapping.objects.update_or_create( + source_employee_id=1, + destination_employee_id=719, + workspace_id=1 + ) + + error = Error.objects.filter(expense_attribute_id=employee_mapping.source_employee_id).first() + + assert error.is_resolved == True @pytest.mark.django_db() def test_run_post_mapping_settings_triggers(access_token): diff --git a/tests/test_mappings/test_tasks.py b/tests/test_mappings/test_tasks.py index 1e6a27c1..77a743b2 100644 --- a/tests/test_mappings/test_tasks.py +++ b/tests/test_mappings/test_tasks.py @@ -1,4 +1,5 @@ import logging +from apps.fyle.models import ExpenseGroup import pytest from unittest import mock from django_q.models import Schedule @@ -17,6 +18,46 @@ logger = logging.getLogger(__name__) logger.level = logging.INFO + +def test_resolve_expense_attribute_errors(db): + workspace_id = 1 + expense_group = ExpenseGroup.objects.get(id=1) + + employee_attribute = ExpenseAttribute.objects.filter( + value=expense_group.description.get('employee_email'), + workspace_id=expense_group.workspace_id, + attribute_type='EMPLOYEE' + ).first() + + error, _ = Error.objects.update_or_create( + workspace_id=expense_group.workspace_id, + expense_attribute=employee_attribute, + defaults={ + 'type': 'EMPLOYEE_MAPPING', + 'error_title': employee_attribute.value, + 'error_detail': 'Employee mapping is missing', + 'is_resolved': False + } + ) + + resolve_expense_attribute_errors('EMPLOYEE', workspace_id, 'EMPLOYEE') + assert Error.objects.get(id=error.id).is_resolved == True + + error, _ = Error.objects.update_or_create( + workspace_id=expense_group.workspace_id, + expense_attribute=employee_attribute, + defaults={ + 'type': 'EMPLOYEE_MAPPING', + 'error_title': employee_attribute.value, + 'error_detail': 'Employee mapping is missing', + 'is_resolved': False + } + ) + + resolve_expense_attribute_errors('EMPLOYEE', workspace_id, 'VENDOR') + assert Error.objects.get(id=error.id).is_resolved == True + + def test_disable_category_for_items_mapping(db ,mocker): workspace_id = 49 configuration = Configuration.objects.filter(workspace_id=workspace_id).first()