Skip to content

Commit

Permalink
adding test to increase cov
Browse files Browse the repository at this point in the history
  • Loading branch information
labhvam5 committed Dec 5, 2023
1 parent 92cc37d commit 3abb41e
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions tests/test_fyle_integrations_imports/test_modules/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
get_base_class_instance,
get_platform_connection
)
from tests.test_fyle_integrations_imports.test_modules.fixtures import projects_data
from tests.test_fyle_integrations_imports.test_modules.fixtures import projects_data, categories_data


def test_remove_duplicates(db):
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_auto_create_destination_attributes(mocker, db):
workspace_id = 3
qbo_credentials = QBOCredential.get_active_qbo_credentials(workspace_id)
qbo_connection = QBOConnector(credentials_object=qbo_credentials, workspace_id=workspace_id)
project = Project(3, 'CUSTOMER', None, qbo_connection, 'customers', True)
project = Project(3, 'CUSTOMER', None, qbo_connection, ['customers'], True)
project.sync_after = None

Workspace.objects.filter(id=workspace_id).update(fyle_org_id='or5qYLrvnoF9')
Expand Down Expand Up @@ -177,6 +177,68 @@ def test_auto_create_destination_attributes(mocker, db):
assert import_log.total_batches_count != 0
assert import_log.processed_batches_count != 0

# not creating due to no destination_attributes(projects)
Mapping.objects.filter(workspace_id=workspace_id, source_type='PROJECT').delete()
Mapping.objects.filter(workspace_id=workspace_id, destination_type='CUSTOMER').delete()
DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='CUSTOMER').delete()
ExpenseAttribute.objects.filter(workspace_id=workspace_id, attribute_type='PROJECT').delete()

with mock.patch('fyle.platform.apis.v1beta.admin.Projects.list_all') as mock_call:
mocker.patch(
'fyle_integrations_platform_connector.apis.Projects.post_bulk',
return_value=[]
)
mocker.patch(
'qbosdk.apis.Customers.count',
return_value=0
)
mocker.patch(
'qbosdk.apis.Customers.get',
return_value=[]
)
mock_call.side_effect = [
projects_data['create_new_auto_create_projects_expense_attributes_0'],
projects_data['create_new_auto_create_projects_expense_attributes_1']
]
project.trigger_import()

import_log = ImportLog.objects.filter(workspace_id=workspace_id).first()

assert import_log.status == 'COMPLETE'
assert import_log.error_log == []
assert import_log.total_batches_count == 0
assert import_log.processed_batches_count == 0

# not creating due to no destination_attributes(categories)
workspace_id = 2
Mapping.objects.filter(workspace_id=workspace_id, source_type='CATEGORY').delete()
DestinationAttribute.objects.filter(workspace_id=workspace_id, attribute_type='ACCOUNT').delete()
ExpenseAttribute.objects.filter(workspace_id=workspace_id, attribute_type='CATEGORY').delete()

category = Category(2, 'ACCOUNT', None, qbo_connection, ['items'], True, False, ['Expense', 'Fixed Asset'])
with mock.patch('fyle.platform.apis.v1beta.admin.Categories.list_all') as mock_call:
mocker.patch(
'fyle_integrations_platform_connector.apis.Categories.post_bulk',
return_value=[]
)
mocker.patch('qbosdk.apis.Items.get',return_value=[])
mocker.patch(
'qbosdk.apis.Accounts.get',
return_value=[]
)
mock_call.side_effect = [
categories_data['create_new_auto_create_categories_expense_attributes_0'],
categories_data['create_new_auto_create_categories_expense_attributes_1']
]
category.trigger_import()

import_log = ImportLog.objects.filter(workspace_id=workspace_id).first()

assert import_log.status == 'COMPLETE'
assert import_log.error_log == []
assert import_log.total_batches_count == 0
assert import_log.processed_batches_count == 0


def test_resolve_expense_attribute_errors(db):
workspace_id = 3
Expand Down

0 comments on commit 3abb41e

Please sign in to comment.