Skip to content

Commit

Permalink
employee mapping error test added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Nov 8, 2023
1 parent 0a4aee3 commit 469efda
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
2 changes: 0 additions & 2 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 31 additions & 1 deletion tests/test_mappings/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
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):
Expand Down
41 changes: 41 additions & 0 deletions tests/test_mappings/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from apps.fyle.models import ExpenseGroup
import pytest
from unittest import mock
from django_q.models import Schedule
Expand All @@ -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()
Expand Down

0 comments on commit 469efda

Please sign in to comment.