Skip to content

Commit

Permalink
removing the construct test
Browse files Browse the repository at this point in the history
  • Loading branch information
labhvam5 committed Dec 6, 2023
1 parent 0df30c4 commit 1cc938b
Showing 1 changed file with 0 additions and 154 deletions.
154 changes: 0 additions & 154 deletions tests/test_fyle_integrations_imports/test_modules/test_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,157 +458,3 @@ def test_construct_fyle_payload(db):
)

assert fyle_payload == categories_data['create_fyle_category_payload_create_disable_case']

def compare_q_objects(q1, q2):
# Convert Q objects to dictionaries and sort the key-value pairs
q1_dict = sorted(q1.children, key=lambda x: x[0])
q2_dict = sorted(q2.children, key=lambda x: x[0])

# Compare the sorted dictionaries
assert q1_dict == q2_dict

def test_construct_attributes_filter(db):
workspace_id = 2
qbo_credentials = QBOCredential.get_active_qbo_credentials(workspace_id)
qbo_connection = QBOConnector(credentials_object=qbo_credentials, workspace_id=workspace_id)

Workspace.objects.filter(id=workspace_id).update(fyle_org_id='or5qYLrvnoF9')

# destination-field without sync-after with only import-categories enabled
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['accounts'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = None
constructed_expense_filter = category.construct_attributes_filter('ACCOUNT', True)

filter_1 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'detail__account_type__in': ['Expense', 'Fixed Asset'],
'display_name':'Account',
}
response = Q(**filter_1)

compare_q_objects(constructed_expense_filter, response)

# destination-field without sync-after with only import-items enabled
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['items'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = None
constructed_expense_filter = category.construct_attributes_filter('ACCOUNT', True)

filter_1 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'display_name':'Item',
}
response = Q(**filter_1)

compare_q_objects(constructed_expense_filter, response)

# destination-field without sync-after with both import-items and import-categories enabled
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['items', 'accounts'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = None
constructed_expense_filter = category.construct_attributes_filter('ACCOUNT', True)

filter_1 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'display_name':'Item',
}
filter_2 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'detail__account_type__in': ['Expense', 'Fixed Asset'],
'display_name':'Account',
}
response = Q(**filter_2) | Q(**filter_1)

# assert constructed_expense_filter == response

# adding the sync_after value
date_string = '2023-08-06 12:50:05.875029'
sync_after = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S.%f')

# destination-field with sync-after with only import-categories enabled
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['accounts'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = sync_after
constructed_expense_filter = category.construct_attributes_filter('ACCOUNT', True)

filter_1 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'updated_at__gte': sync_after,
'detail__account_type__in': ['Expense', 'Fixed Asset'],
'display_name':'Account',
}
response = Q(**filter_1)

compare_q_objects(constructed_expense_filter, response)

# destination-field with sync-after with only import-items enabled
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['items'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = sync_after
constructed_expense_filter = category.construct_attributes_filter('ACCOUNT', True)

filter_1 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'updated_at__gte': sync_after,
'display_name':'Item',
}
response = Q(**filter_1)

compare_q_objects(constructed_expense_filter, response)

# destination-field with sync-after with both import-items and import-categories enabled
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['items', 'accounts'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = sync_after
constructed_expense_filter = category.construct_attributes_filter('ACCOUNT', True)

filter_1 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'updated_at__gte': sync_after,
'display_name':'Item',
}
filter_2 = {
'attribute_type': 'ACCOUNT',
'workspace_id': workspace_id,
'detail__account_type__in': ['Expense', 'Fixed Asset'],
'updated_at__gte': sync_after,
'display_name':'Account',
}
response = Q(**filter_2) | Q(**filter_1)

print("constructed_expense_filter")
print(constructed_expense_filter)
print("response")
print(response)

assert constructed_expense_filter == response

# source-field with sync-after and paginated_values
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['items'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = sync_after
constructed_expense_filter = category.construct_attributes_filter('CATEGORY', False, ['Fuel', 'Advertising'])

filter_1 = {
'attribute_type': 'CATEGORY',
'workspace_id': workspace_id,
'value__in': ['Fuel', 'Advertising'],
}
response = Q(**filter_1)

compare_q_objects(constructed_expense_filter, response)

# source-field without sync-after and paginated_values
category = Category(workspace_id, 'ACCOUNT', None, qbo_connection, ['items'], True, False, ['Expense', 'Fixed Asset'])
category.sync_after = None
constructed_expense_filter = category.construct_attributes_filter('CATEGORY', False, ['Fuel', 'Advertising'])

filter_1 = {
'attribute_type': 'CATEGORY',
'workspace_id': workspace_id,
'value__in': ['Fuel', 'Advertising'],
}
response = Q(**filter_1)

compare_q_objects(constructed_expense_filter, response)

0 comments on commit 1cc938b

Please sign in to comment.