Skip to content

Commit

Permalink
Added Validation for exempting orgs with wrong org ids (#474)
Browse files Browse the repository at this point in the history
* Added Validation for exempting orgs with wrong org ids

* Fixing Test Fixture for Exempt Case

* Removing unused import
  • Loading branch information
Shwetabhk authored Sep 1, 2023
1 parent f04ce06 commit 59e8fda
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ max-line-length = 99
max-complexity = 19
ban-relative-imports = true
select = B,C,E,F,N,W,I25
exclude=*env
4 changes: 2 additions & 2 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def post_merchants(platform_connection: PlatformConnector, workspace_id: int):

if fyle_payload:
platform_connection.merchants.post(fyle_payload)
platform_connection.merchants.sync(workspace_id)
platform_connection.merchants.sync()


@handle_import_exceptions(task_name='Auto Create Vendors as Merchants')
Expand All @@ -775,7 +775,7 @@ def auto_create_vendors_as_merchants(workspace_id):

fyle_connection = PlatformConnector(fyle_credentials)

fyle_connection.merchants.sync(workspace_id)
fyle_connection.merchants.sync()

sync_qbo_attribute('VENDOR', workspace_id)
post_merchants(fyle_connection, workspace_id)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum34==1.1.10
future==0.18.2
fyle==0.30.0
fyle-accounting-mappings==1.26.1
fyle-integrations-platform-connector==1.30.0
fyle-integrations-platform-connector==1.32.3
fyle-rest-auth==1.5.0
gevent==22.10.2
gunicorn==20.1.0
Expand Down
21 changes: 17 additions & 4 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9123,11 +9123,24 @@
{
'code': '16200',
'created_at': '2022-08-12T16:50:53.658771+00:00',
'display_name': 'Patents & Licenses',
'id': 207983,
'display_name': 'Patents & Licenses - Test',
'id': 22330021,
'is_enabled': True,
'name': 'Patents & Licenses',
'org_id': 'orNoatdUnm1w',
'name': 'Patents & Licenses - Included',
'org_id': 'orPJvXuoLqvJ',
'restricted_project_ids': None,
'sub_category': None,
'system_category': None,
'updated_at': '2022-08-30T16:50:44.671684+00:00',
},
{
'code': '16200',
'created_at': '2022-08-12T16:50:53.658771+00:00',
'display_name': 'Patents & Licenses - Test',
'id': 22330021,
'is_enabled': True,
'name': 'Patents & Licenses - Exempted',
'org_id': 'orPJvXuoasfnn1J',
'restricted_project_ids': None,
'sub_category': None,
'system_category': None,
Expand Down
18 changes: 15 additions & 3 deletions tests/test_mappings/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from apps.workspaces.models import FyleCredential, QBOCredential, WorkspaceGeneralSettings
from tests.helper import dict_compare_keys
from tests.test_mappings.fixtures import data
from tests.test_fyle.fixtures import data as fyle_data


def test_auto_create_tax_codes_mappings(db, mocker):
Expand Down Expand Up @@ -86,13 +87,14 @@ def test_disable_category_for_items_mapping(db, mocker):
workspace_general_setting.save()

# mocking all the sdk calls
mocker.patch('fyle_integrations_platform_connector.apis.Categories.sync', return_value=[])
mocker.patch('fyle.platform.apis.v1beta.admin.Categories.list_all', return_value=fyle_data['get_all_categories'])
mocker.patch('fyle_integrations_platform_connector.apis.Categories.post_bulk', return_value=[])
mocker.patch('qbosdk.apis.Items.get', return_value=[])

# adding test data to the database
destination_attribute = DestinationAttribute.objects.create(attribute_type='ACCOUNT', display_name='Item', value='Concrete', destination_id=3, workspace_id=workspace_id, active=False)
expense_attribute = ExpenseAttribute.objects.create(attribute_type='CATEGORY', display_name='Category', value='Concrete', source_id='253737253737', workspace_id=workspace_id, active=True)

Mapping.objects.create(source_type='CATEGORY', destination_type='ACCOUNT', destination_id=destination_attribute.id, source_id=expense_attribute.id, workspace_id=workspace_id)

disable_category_for_items_mapping(workspace_id)
Expand Down Expand Up @@ -228,14 +230,24 @@ def test_auto_create_category_mappings_with_items(db, mocker):
assert mappings == 46

mocker.patch('qbosdk.apis.Accounts.get', return_value=[])
mocker.patch('fyle_integrations_platform_connector.apis.Categories.sync', return_value=[])
mocker.patch('fyle.platform.apis.v1beta.admin.Categories.list_all', return_value=fyle_data['get_all_categories'])
mocker.patch('fyle_integrations_platform_connector.apis.Categories.post_bulk', return_value=[])
mocker.patch('qbosdk.apis.Items.get', return_value=[])

response = auto_create_category_mappings(workspace_id=workspace_id)
assert response == []

category = ExpenseAttribute.objects.filter(value='Patents & Licenses - Included', workspace_id=workspace_id).first()

assert category != None
assert category.value == 'Patents & Licenses - Included'

category = ExpenseAttribute.objects.filter(value='Patents & Licenses - Exempted', workspace_id=workspace_id).first()

assert category == None

item_count = Mapping.objects.filter(destination_type='ACCOUNT', source_type='CATEGORY', destination__display_name='Item', workspace_id=workspace_id).count()

assert item_count == 0


Expand Down Expand Up @@ -452,7 +464,7 @@ def test_schedule_fyle_attributes_creation(db, mocker):
def test_post_merchants(db, mocker):
mocker.patch('fyle_integrations_platform_connector.apis.Merchants.get', return_value=data['get_merchants'])
mocker.patch('fyle_integrations_platform_connector.apis.Merchants.post', return_value=[])
mocker.patch('fyle_integrations_platform_connector.apis.Merchants.sync', return_value=[])
mocker.patch('fyle.platform.apis.v1beta.admin.expense_fields', return_value=data['get_merchants'])
workspace_id = 5
fyle_credentials = FyleCredential.objects.all()
fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id)
Expand Down

0 comments on commit 59e8fda

Please sign in to comment.