Skip to content

Commit

Permalink
adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
labhvam5 committed Dec 5, 2023
1 parent ba897dc commit 13a04ea
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions tests/test_fyle_integrations_imports/test_modules/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from apps.workspaces.models import Workspace
from apps.workspaces.models import QBOCredential
from apps.quickbooks_online.utils import QBOConnector
from apps.tasks.models import Error
from fyle_integrations_imports.modules.projects import Project
from fyle_integrations_imports.modules.categories import Category
from fyle_integrations_imports.models import ImportLog
from tests.test_fyle_integrations_imports.helpers import (
get_base_class_instance,
Expand Down Expand Up @@ -58,20 +60,23 @@ def test_get_platform_class(db):


def test_construct_attributes_filter(db):
paginated_destination_attribute_values = ['Mobile App Redesign', 'Platform APIs', 'Fyle NetSuite Integration', 'Fyle Sage Intacct Integration', 'Support Taxes', 'T&M Project with Five Tasks', 'Fixed Fee Project with Five Tasks', 'General Overhead', 'General Overhead-Current', 'Youtube proj', 'Integrations', 'Yujiro', 'Pickle']
base = get_base_class_instance()

assert base.construct_attributes_filter('PROJECT') == {'attribute_type': 'PROJECT', 'workspace_id': 1}
assert base.construct_attributes_filter('PROJECT', False) == {'attribute_type': 'PROJECT', 'workspace_id': 1}

date_string = '2023-08-06 12:50:05.875029'
sync_after = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S.%f')

base = get_base_class_instance(workspace_id=1, source_field='CATEGORY', destination_field='ACCOUNT', platform_class_name='categories', sync_after=sync_after)
base = get_base_class_instance(workspace_id=1, source_field='COST_CENTER', destination_field='CUSTOMER', platform_class_name='cost_centers', sync_after=sync_after)

filters = base.construct_attributes_filter('COST_CENTER', False, paginated_destination_attribute_values)

assert base.construct_attributes_filter('CATEGORY', False) == {'attribute_type': 'CATEGORY', 'workspace_id': 1}
assert filters == {'attribute_type': 'COST_CENTER', 'workspace_id': 1, 'value__in': paginated_destination_attribute_values}

paginated_destination_attribute_values = ['Mobile App Redesign', 'Platform APIs', 'Fyle NetSuite Integration', 'Fyle Sage Intacct Integration', 'Support Taxes', 'T&M Project with Five Tasks', 'Fixed Fee Project with Five Tasks', 'General Overhead', 'General Overhead-Current', 'Youtube proj', 'Integrations', 'Yujiro', 'Pickle']
filters = base.construct_attributes_filter('CUSTOMER', True, paginated_destination_attribute_values)

assert base.construct_attributes_filter('COST_CENTER', paginated_destination_attribute_values) == {'attribute_type': 'COST_CENTER', 'workspace_id': 1, 'updated_at__gte': sync_after, 'value__in': paginated_destination_attribute_values}
assert filters == {'attribute_type': 'CUSTOMER', 'workspace_id': 1, 'updated_at__gte': sync_after, 'value__in': paginated_destination_attribute_values}


def test_expense_attributes_sync_after(db):
Expand Down Expand Up @@ -171,3 +176,53 @@ def test_auto_create_destination_attributes(mocker, db):
assert import_log.status == 'IN_PORGRESS'
assert import_log.total_batches_count != 0
assert import_log.processed_batches_count != 0


def test_resolve_expense_attribute_errors(db):
workspace_id = 3
qbo_credentials = QBOCredential.get_active_qbo_credentials(workspace_id)
qbo_connection = QBOConnector(credentials_object=qbo_credentials, workspace_id=workspace_id)
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['accounts'], True, False, ['Expense', 'Fixed Asset'])

# deleting all the Error objects
Error.objects.filter(workspace_id=workspace_id).delete()

# getting the expense_attribute
source_category = ExpenseAttribute.objects.filter(
id=5357,
workspace_id=workspace_id,
attribute_type='CATEGORY'
).first()

print(source_category)

category_mapping_count = Mapping.objects.filter(workspace_id=workspace_id, source_id=source_category.id).count()

# category mapping is not present
assert category_mapping_count == 0

error = Error.objects.create(
workspace_id=workspace_id,
expense_attribute=source_category,
type='CATEGORY_MAPPING',
error_title=source_category.value,
error_detail='Category mapping is missing',
is_resolved=False
)

assert Error.objects.get(id=error.id).is_resolved == False

destination_attribute = DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='ACCOUNT').first()

# creating the category mapping in bulk mode to avoid setting the is_resolved flag to true by signal
category_list = []
category_list.append(
Mapping(
workspace_id=workspace_id,
source_id=source_category.id,
destination_id=destination_attribute.id
))
Mapping.objects.bulk_create(category_list)

category.resolve_expense_attribute_errors()
assert Error.objects.get(id=error.id).is_resolved == True

0 comments on commit 13a04ea

Please sign in to comment.