-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ashutosh619-sudo
committed
Oct 25, 2023
1 parent
cfb791b
commit e9a0b17
Showing
5 changed files
with
281 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
196 changes: 196 additions & 0 deletions
196
tests/test_workspaces/test_apis/test_export_settings/fixtures.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
data = { | ||
'export_settings': { | ||
'configuration': { | ||
'reimbursable_expenses_object': 'EXPENSE REPORT', | ||
'corporate_credit_card_expenses_object': 'EXPENSE REPORT', | ||
'auto_map_employees': 'NAME', | ||
'is_simplify_report_closure_enabled': False, | ||
'employee_field_mapping': 'EMPLOYEE' | ||
}, | ||
'expense_group_settings': { | ||
'reimbursable_expense_group_fields': [ | ||
'fund_source', | ||
'employee_email', | ||
'claim_number', | ||
'report_id' | ||
], | ||
'reimbursable_export_date_type': 'current_date', | ||
'expense_state': 'PAYMENT_PROCESSING', | ||
'corporate_credit_card_expense_group_fields': [ | ||
'fund_source', | ||
'claim_number', | ||
'employee_email', | ||
'report_id', | ||
'spent_at', | ||
'expense_id' | ||
], | ||
'ccc_export_date_type': 'spent_at', | ||
'ccc_expense_state': 'PAID' | ||
}, | ||
'general_mappings': { | ||
'reimbursable_account': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'accounts_payable': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'default_ccc_account': { | ||
'id': '1', | ||
'name': 'Elon musk' | ||
}, | ||
'default_ccc_vendor': { | ||
'id': '', | ||
'name': '' | ||
} | ||
} | ||
}, | ||
'response': { | ||
'configuration': { | ||
'reimbursable_expenses_object': 'EXPENSE_REPORT', | ||
'corporate_credit_card_expenses_object': 'CHARGE_CARD_TRANSACTION', | ||
'auto_map_employees': 'NAME', | ||
'is_simplify_report_closure_enabled': False, | ||
'employee_field_mapping': 'EMPLOYEE' | ||
}, | ||
'expense_group_settings': { | ||
'reimbursable_expense_group_fields': [ | ||
'fund_source', | ||
'employee_email', | ||
'claim_number', | ||
'report_id' | ||
], | ||
'reimbursable_export_date_type': 'current_date', | ||
'expense_state': 'PAYMENT_PROCESSING', | ||
'corporate_credit_card_expense_group_fields': [ | ||
'fund_source', | ||
'claim_number', | ||
'employee_email', | ||
'report_id', | ||
'spent_at', | ||
'expense_id' | ||
], | ||
'ccc_export_date_type': 'spent_at', | ||
'ccc_expense_state': 'PAID' | ||
}, | ||
'general_mappings': { | ||
'reimbursable_account': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'accounts_payable': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'default_ccc_account': { | ||
'id': '1', | ||
'name': 'Elon musk' | ||
}, | ||
'default_ccc_vendor': { | ||
'id': '', | ||
'name': '' | ||
} | ||
}, | ||
'workspace_id': 1 | ||
}, | ||
'export_settings_missing_values_configurations': { | ||
'configurations': {}, | ||
'expense_group_settings': { | ||
'reimbursable_expense_group_fields': [ | ||
'fund_source', | ||
'employee_email', | ||
'claim_number', | ||
'report_id' | ||
], | ||
'reimbursable_export_date_type': 'current_date', | ||
'expense_state': 'PAYMENT_PROCESSING', | ||
'corporate_credit_card_expense_group_fields': [ | ||
'fund_source', | ||
'claim_number', | ||
'employee_email', | ||
'report_id', | ||
'spent_at', | ||
'expense_id' | ||
], | ||
'ccc_export_date_type': 'spent_at', | ||
'ccc_expense_state': 'PAID' | ||
}, | ||
'general_mappings': { | ||
'reimbursable_account': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'accounts_payable': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'default_ccc_account': { | ||
'id': '1', | ||
'name': 'Elon musk' | ||
}, | ||
'default_ccc_vendor': { | ||
'id': '', | ||
'name': '' | ||
} | ||
} | ||
}, | ||
'export_settings_missing_values_expense_group_settings': { | ||
'configurations': { | ||
'reimbursable_expenses_object': 'EXPENSE_REPORT', | ||
'corporate_credit_card_expenses_object': 'CHARGE_CARD_TRANSACTION', | ||
'auto_map_employees': 'NAME', | ||
'is_simplify_report_closure_enabled': False, | ||
'employee_field_mapping': 'EMPLOYEE' | ||
}, | ||
'expense_group_settings': {}, | ||
'general_mappings': { | ||
'reimbursable_account': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'accounts_payable': { | ||
'id': '', | ||
'name': '' | ||
}, | ||
'default_ccc_account': { | ||
'id': '1', | ||
'name': 'Elon musk' | ||
}, | ||
'default_ccc_vendor': { | ||
'id': '', | ||
'name': '' | ||
} | ||
} | ||
}, | ||
'export_settings_missing_values_general_mappings': { | ||
'configurations': { | ||
'reimbursable_expenses_object': 'EXPENSE_REPORT', | ||
'corporate_credit_card_expenses_object': 'CHARGE_CARD_TRANSACTION', | ||
'auto_map_employees': 'NAME', | ||
'is_simplify_report_closure_enabled': False, | ||
'employee_field_mapping': 'EMPLOYEE' | ||
}, | ||
'expense_group_settings': { | ||
'reimbursable_expense_group_fields': [ | ||
'fund_source', | ||
'employee_email', | ||
'claim_number', | ||
'report_id' | ||
], | ||
'reimbursable_export_date_type': 'current_date', | ||
'expense_state': 'PAYMENT_PROCESSING', | ||
'corporate_credit_card_expense_group_fields': [ | ||
'fund_source', | ||
'claim_number', | ||
'employee_email', | ||
'report_id', | ||
'spent_at', | ||
'expense_id' | ||
], | ||
'ccc_export_date_type': 'spent_at', | ||
'ccc_expense_state': 'PAID' | ||
}, | ||
'general_mappings': {} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
tests/test_workspaces/test_apis/test_export_settings/test_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import json | ||
from tests.helper import dict_compare_keys | ||
from apps.workspaces.models import Workspace, Configuration | ||
from .fixtures import data | ||
import pytest | ||
from django.urls import reverse | ||
|
||
@pytest.mark.django_db(databases=['default']) | ||
def test_export_settings(api_client, access_token): | ||
|
||
workspace = Workspace.objects.get(id=1) | ||
workspace.onboarding_state = 'EXPORT_SETTINGS' | ||
workspace.save() | ||
|
||
url = reverse( | ||
'export-settings', kwargs={ | ||
'workspace_id': 1 | ||
} | ||
) | ||
|
||
api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token)) | ||
response = api_client.put( | ||
url, | ||
data=data['export_settings'], | ||
format='json' | ||
) | ||
|
||
assert response.status_code == 200 | ||
|
||
response = json.loads(response.content) | ||
workspace = Workspace.objects.get(id=1) | ||
|
||
assert dict_compare_keys(response, data['response']) == [], 'workspaces api returns a diff in the keys' | ||
assert workspace.onboarding_state == 'IMPORT_SETTINGS' | ||
|
||
url = '/api/v2/workspaces/1/export_settings/' | ||
api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token)) | ||
|
||
payload = data['export_settings'] | ||
payload['expense_group_settings']['reimbursable_expense_group_fields'] = [] | ||
payload['expense_group_settings']['corporate_credit_card_expense_group_fields'] = [] | ||
payload['expense_group_settings']['reimbursable_export_date_type'] = '' | ||
payload['expense_group_settings']['ccc_export_date_type'] = '' | ||
|
||
response = api_client.put( | ||
url, | ||
data=payload, | ||
format='json' | ||
) | ||
|
||
assert response.status_code == 200 | ||
|
||
response = json.loads(response.content) | ||
workspace = Workspace.objects.get(id=1) | ||
|
||
assert dict_compare_keys(response, data['response']) == [], 'workspaces api returns a diff in the keys' | ||
|
||
invalid_configurations = data['export_settings_missing_values_configurations'] | ||
response = api_client.put( | ||
url, | ||
data=invalid_configurations, | ||
format='json' | ||
) | ||
|
||
assert response.status_code == 400 | ||
|
||
invalid_expense_group_settings = data['export_settings_missing_values_expense_group_settings'] | ||
response = api_client.put( | ||
url, | ||
data=invalid_expense_group_settings, | ||
format='json' | ||
) | ||
|
||
assert response.status_code == 400 | ||
|
||
invalid_general_mappings = data['export_settings_missing_values_general_mappings'] | ||
response = api_client.put( | ||
url, | ||
data=invalid_general_mappings, | ||
format='json' | ||
) | ||
|
||
assert response.status_code == 400 |