Skip to content

Commit

Permalink
Imports base test cases (#47)
Browse files Browse the repository at this point in the history
* Fix: Import bugs

* Imports base test cases

* Imports test cases for schedules, categories, cost centers (#48)

* Imports test cases for schedules, categories, cost centers

* Imports test cases for merchants, projects, expense fields (#49)
  • Loading branch information
ruuushhh authored Dec 15, 2023
1 parent befe905 commit 14b6729
Show file tree
Hide file tree
Showing 14 changed files with 10,162 additions and 11 deletions.
66 changes: 55 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import pytest
from fyle.platform.platform import Platform
from fyle_accounting_mappings.models import DestinationAttribute
from fyle_accounting_mappings.models import DestinationAttribute, MappingSetting
from fyle_rest_auth.models import AuthToken, User
from rest_framework.test import APIClient

from apps.accounting_exports.models import AccountingExport, AccountingExportSummary, Error
from apps.fyle.helpers import get_access_token
from apps.fyle.models import ExpenseFilter
from apps.workspaces.models import BusinessCentralCredentials, ExportSetting, FyleCredential, Workspace
from apps.workspaces.models import BusinessCentralCredentials, ExportSetting, FyleCredential, ImportSetting, Workspace
from ms_business_central_api.tests import settings
from tests.test_fyle.fixtures import fixtures as fyle_fixtures

Expand Down Expand Up @@ -68,37 +68,43 @@ def test_connection(db):
@pytest.fixture(scope="session", autouse=True)
def default_session_fixture(request):
patched_1 = mock.patch(
'fyle_rest_auth.authentication.get_fyle_admin',
return_value=fyle_fixtures['get_my_profile']
'dynamics.core.client.Dynamics._Dynamics__refresh_access_token',
return_value="dummy_token"
)
patched_1.__enter__()

patched_2 = mock.patch(
'fyle.platform.internals.auth.Auth.update_access_token',
return_value='asnfalsnkflanskflansfklsan'
'fyle_rest_auth.authentication.get_fyle_admin',
return_value=fyle_fixtures['get_my_profile']
)
patched_2.__enter__()

patched_3 = mock.patch(
'fyle.platform.internals.auth.Auth.update_access_token',
return_value='asnfalsnkflanskflansfklsan'
)
patched_3.__enter__()

patched_4 = mock.patch(
'apps.fyle.helpers.post_request',
return_value={
'access_token': 'easnfkjo12233.asnfaosnfa.absfjoabsfjk',
'cluster_domain': 'https://staging.fyle.tech'
}
)
patched_3.__enter__()
patched_4.__enter__()

patched_4 = mock.patch(
patched_5 = mock.patch(
'fyle.platform.apis.v1beta.spender.MyProfile.get',
return_value=fyle_fixtures['get_my_profile']
)
patched_4.__enter__()
patched_5.__enter__()

patched_5 = mock.patch(
patched_6 = mock.patch(
'fyle_rest_auth.helpers.get_fyle_admin',
return_value=fyle_fixtures['get_my_profile']
)
patched_5.__enter__()
patched_6.__enter__()


@pytest.fixture
Expand Down Expand Up @@ -316,3 +322,41 @@ def add_export_settings():
credit_card_expense_grouped_by='EXPENSE' if workspace_id == 3 else 'REPORT',
credit_card_expense_date='spent_at'
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_import_settings():
"""
Pytest fixtue to add import_settings to a workspace
"""
workspace_ids = [
1, 2, 3
]

for workspace_id in workspace_ids:
ImportSetting.objects.create(
workspace_id=workspace_id,
import_vendors_as_merchants=True,
import_categories=True
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_mapping_settings():
"""
Pytest fixtue to add mapping_settings to a workspace
"""
workspace_ids = [
1, 2, 3
]

for workspace_id in workspace_ids:
MappingSetting.objects.create(
workspace_id=workspace_id,
source_field='CATEGORY',
destination_field='ACCOUNT',
import_to_fyle=True,
is_custom=False
)
Empty file added tests/test_mappings/__init__.py
Empty file.
Empty file.
Empty file.
170 changes: 170 additions & 0 deletions tests/test_mappings/test_imports/test_modules/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
"""
Fixture configuration for import tests
"""
import pytest
from fyle_accounting_mappings.models import DestinationAttribute, ExpenseAttribute


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_project_mappings():
"""
Pytest fixtue to add project mappings to a workspace
"""
workspace_ids = [
1, 2, 3
]
for workspace_id in workspace_ids:
DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='PROJECT',
display_name='Direct Mail Campaign',
value='Direct Mail Campaign',
destination_id='10064',
detail='Business Central Project - Direct Mail Campaign, Id - 10064',
active=True
)
DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='PROJECT',
display_name='Platform APIs',
value='Platform APIs',
destination_id='10081',
detail='Business Central Project - Platform APIs, Id - 10081',
active=True
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_cost_center_mappings():
"""
Pytest fixtue to add cost center mappings to a workspace
"""
workspace_ids = [
1, 2, 3
]
for workspace_id in workspace_ids:
DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='COST_CENTER',
display_name='Direct Mail Campaign',
value='Direct Mail Campaign',
destination_id='10064',
detail='Cost Center - Direct Mail Campaign, Id - 10064',
active=True
)
DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='COST_CENTER',
display_name='Platform APIs',
value='Platform APIs',
destination_id='10081',
detail='Cost Center - Platform APIs, Id - 10081',
active=True
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_merchant_mappings():
"""
Pytest fixture to add merchant mappings to a workspace
"""
workspace_ids = [
1, 2, 3
]
for workspace_id in workspace_ids:
DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='MERCHANT',
display_name='Direct Mail Campaign',
value='Direct Mail Campaign',
destination_id='10064',
detail='Merchant - Direct Mail Campaign, Id - 10064',
active=True
)
DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='MERCHANT',
display_name='Platform APIs',
value='Platform APIs',
destination_id='10081',
detail='Merchant - Platform APIs, Id - 10081',
active=True
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_project_expense_attributes():
"""
Pytest fixture to add project expense attributes to a workspace
"""
for i in range(1, 110):
ExpenseAttribute.objects.create(
workspace_id=1,
attribute_type='PROJECT',
display_name='Project',
value='Platform APIs {0}'.format(i),
source_id='1008{0}'.format(i),
detail='Merchant - Platform APIs, Id - 1008{0}'.format(i),
active=True
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_expense_destination_attributes():
"""
Pytest fixture to add expense & destination attributes to a workspace
"""
ExpenseAttribute.objects.create(
workspace_id=1,
attribute_type='CATEGORY',
display_name='Category',
value='Test Dynamics',
source_id='1008',
detail='Merchant - Platform APIs, Id - 1008',
active=True
)
DestinationAttribute.objects.create(
workspace_id=1,
attribute_type='ACCOUNT',
display_name='Account',
value='Test Dynamics',
destination_id='10081',
detail='Merchant - Platform APIs, Id - 10081',
active=True
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_expense_destination_attributes_1():
"""
Pytest fixture to add expense & destination attributes to a workspace
"""
values = ['Internet','Meals']
count = 0

for value in values:
count += 1
ExpenseAttribute.objects.create(
workspace_id=1,
attribute_type='CATEGORY',
display_name='Category',
value= value,
source_id='1009{0}'.format(count),
detail='Merchant - Platform APIs, Id - 1008',
active=True
)
DestinationAttribute.objects.create(
workspace_id=1,
attribute_type='ACCOUNT',
display_name='Account',
value= value,
destination_id=value,
detail='Merchant - Platform APIs, Id - 10081',
active=True
)
Loading

0 comments on commit 14b6729

Please sign in to comment.