Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable sage fields #183

Merged
merged 20 commits into from
Jun 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 98 additions & 2 deletions tests/test_sage300/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from datetime import datetime, timedelta, timezone
from apps.sage300.helpers import (
check_interval_and_sync_dimension,
sync_dimensions
sync_dimensions,
disable_projects,
update_and_disable_cost_code
)
from apps.workspaces.models import Workspace, Sage300Credential
from fyle_accounting_mappings.models import ExpenseAttribute
from apps.fyle.models import DependentFieldSetting
from apps.sage300.models import CostCategory


def test_check_interval_and_sync_dimension(
Expand Down Expand Up @@ -83,4 +88,95 @@ def test():
)
except Exception as e:
assert str(e) == 'Error'
continue


def test_disable_projects(
db,
mocker,
create_temp_workspace,
add_fyle_credentials
):
workspace_id = 1

projects_to_disable = {
'destination_id': {
'value': 'old_project',
'updated_value': 'new_project'
}
}

ExpenseAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='PROJECT',
display_name='Project',
value='old_project',
source_id='source_id'
)

mock_platform = mocker.patch('apps.sage300.helpers.PlatformConnector')
mocker.patch.object(mock_platform.return_value.projects, 'post_bulk')
mocker.patch.object(mock_platform.return_value.projects, 'sync')

mocker.patch('apps.sage300.helpers.update_and_disable_cost_code')

disable_projects(workspace_id, projects_to_disable)

projects_to_disable = {
'destination_id': {
'value': 'old_project_2',
'updated_value': 'new_project'
}
}

disable_projects(workspace_id, projects_to_disable)
Hrishabh17 marked this conversation as resolved.
Show resolved Hide resolved


def test_update_and_disable_cost_code(
db,
mocker,
create_temp_workspace,
add_fyle_credentials,
add_dependent_field_setting,
add_cost_category
):
workspace_id = 1

projects_to_disable = {
'destination_id': {
'value': 'old_project',
'updated_value': 'new_project'
}
}

cost_category = CostCategory.objects.filter(workspace_id=workspace_id).first()
cost_category.job_name = 'old_project'
cost_category.job_id = 'destination_id'
cost_category.save()

ExpenseAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='PROJECT',
display_name='Project',
value='old_project',
source_id='source_id'
)

mock_platform = mocker.patch('apps.sage300.helpers.PlatformConnector')
mocker.patch.object(mock_platform.return_value.cost_centers, 'post_bulk')
mocker.patch.object(mock_platform.return_value.cost_centers, 'sync')
mocker.patch.object(mock_platform.return_value.dependent_fields, 'bulk_post_dependent_expense_field_values')

update_and_disable_cost_code(workspace_id, projects_to_disable, mock_platform)

updated_cost_category = CostCategory.objects.filter(workspace_id=workspace_id, job_id='destination_id').first()
assert updated_cost_category.job_name == 'new_project'

updated_cost_category.job_name = 'old_project'
updated_cost_category.save()

DependentFieldSetting.objects.get(workspace_id=workspace_id).delete()

update_and_disable_cost_code(workspace_id, projects_to_disable, mock_platform)

updated_cost_category = CostCategory.objects.filter(workspace_id=workspace_id, job_id='destination_id').first()
assert updated_cost_category.job_name == 'old_project'
Loading