-
Notifications
You must be signed in to change notification settings - Fork 0
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
api for fyle expense custom field #41
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
76018ab
add fyle expense fields
NileshPant1999 4d25399
Merge branch 'master' of https://github.com/fylein/fyle-sage-desktop-…
NileshPant1999 983c41f
add support for expense fields with tests
NileshPant1999 80c8a2d
add support for github workflow for pytest
NileshPant1999 17fdaed
fix tsts
NileshPant1999 3c39af4
fix tsts
NileshPant1999 0d664dc
pull pytest github pr
NileshPant1999 dc785cc
add support
NileshPant1999 434f8de
er
NileshPant1999 0509baf
minor change
NileshPant1999 31d42d7
minor fix
NileshPant1999 4cfd159
fix
NileshPant1999 7d614d0
ad
NileshPant1999 da70cab
minor dix
NileshPant1999 bbf69ae
asd
NileshPant1999 65286c5
asd
NileshPant1999 c9431dc
Merge branch 'github-action-pytest' of https://github.com/fylein/fyle…
NileshPant1999 f1e287a
minor fx;
NileshPant1999 20fe791
merge master
NileshPant1999 7c281c8
lint fix
NileshPant1999 5e9eef2
fix test
NileshPant1999 4456741
resolve comments
NileshPant1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DEFAULT_FYLE_CONDITIONS = [ | ||
{ | ||
'field_name': 'employee_email', | ||
'type': 'SELECT', | ||
'is_custom': False | ||
}, | ||
{ | ||
'field_name': 'claim_number', | ||
'type': 'TEXT', | ||
'is_custom': False | ||
}, | ||
{ | ||
'field_name': 'report_title', | ||
'type': 'TEXT', | ||
'is_custom': False | ||
}, | ||
{ | ||
'field_name': 'spent_at', | ||
'type': 'DATE', | ||
'is_custom': False | ||
} | ||
] |
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,8 @@ | ||
|
||
|
||
class Reimbursement: | ||
""" | ||
Creating a dummy class to be able to user | ||
fyle_integrations_platform_connector correctly | ||
""" | ||
pass |
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,7 @@ | ||
from django.urls import path | ||
|
||
from apps.fyle.views import CustomFieldView | ||
|
||
urlpatterns = [ | ||
path('expense_fields/', CustomFieldView.as_view(), name='fyle-expense-fields'), | ||
] |
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,40 @@ | ||
from rest_framework.views import status | ||
from rest_framework import generics | ||
from rest_framework.response import Response | ||
|
||
from fyle_integrations_platform_connector import PlatformConnector | ||
|
||
from apps.workspaces.models import FyleCredential | ||
from apps.fyle.constants import DEFAULT_FYLE_CONDITIONS | ||
|
||
|
||
class CustomFieldView(generics.RetrieveAPIView): | ||
""" | ||
Custom Field view | ||
""" | ||
def get(self, request, *args, **kwargs): | ||
""" | ||
Get Custom Fields | ||
""" | ||
workspace_id = self.kwargs['workspace_id'] | ||
|
||
fyle_credentails = FyleCredential.objects.get(workspace_id=workspace_id) | ||
|
||
platform = PlatformConnector(fyle_credentails) | ||
|
||
custom_fields = platform.expense_custom_fields.list_all() | ||
|
||
response = [] | ||
response.extend(DEFAULT_FYLE_CONDITIONS) | ||
for custom_field in custom_fields: | ||
if custom_field['type'] in ('SELECT', 'NUMBER', 'TEXT', 'BOOLEAN'): | ||
response.append({ | ||
'field_name': custom_field['field_name'], | ||
'type': custom_field['type'], | ||
'is_custom': custom_field['is_custom'] | ||
}) | ||
|
||
return Response( | ||
data=response, | ||
status=status.HTTP_200_OK | ||
) |
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
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 |
---|---|---|
|
@@ -176,8 +176,6 @@ | |
} | ||
} | ||
|
||
|
||
|
||
CACHES = { | ||
'default': { | ||
'BACKEND': 'django.core.cache.backends.db.DatabaseCache', | ||
|
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
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,38 @@ | ||
import json | ||
from os import path | ||
|
||
|
||
def dict_compare_keys(d1, d2, key_path=''): | ||
""" | ||
Compare two dicts recursively and see if dict1 has any keys that dict2 does not | ||
Returns: list of key paths | ||
""" | ||
res = [] | ||
if not d1: | ||
return res | ||
if not isinstance(d1, dict): | ||
return res | ||
for k in d1: | ||
if k not in d2: | ||
missing_key_path = f'{key_path}->{k}' | ||
res.append(missing_key_path) | ||
else: | ||
if isinstance(d1[k], dict): | ||
key_path1 = f'{key_path}->{k}' | ||
res1 = dict_compare_keys(d1[k], d2[k], key_path1) | ||
res = res + res1 | ||
elif isinstance(d1[k], list): | ||
key_path1 = f'{key_path}->{k}[0]' | ||
dv1 = d1[k][0] if len(d1[k]) > 0 else None | ||
dv2 = d2[k][0] if len(d2[k]) > 0 else None | ||
res1 = dict_compare_keys(dv1, dv2, key_path1) | ||
res = res + res1 | ||
return res | ||
|
||
|
||
def get_response_dict(filename): | ||
basepath = path.dirname(__file__) | ||
filepath = path.join(basepath, filename) | ||
mock_json = open(filepath, 'r').read() | ||
mock_dict = json.loads(mock_json) | ||
return mock_dict |
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 |
---|---|---|
@@ -1,27 +1,63 @@ | ||
fixtures = { | ||
'get_my_profile': { | ||
'data': { | ||
'org': { | ||
'currency': 'USD', | ||
'domain': 'fyleforqvd.com', | ||
'id': 'orNoatdUnm1w', | ||
'name': 'Fyle For MS Dynamics Demo', | ||
"get_my_profile": { | ||
"data": { | ||
"org": { | ||
"currency": "USD", | ||
"domain": "fyleforqvd.com", | ||
"id": "orNoatdUnm1w", | ||
"name": "Fyle For MS Dynamics Demo", | ||
}, | ||
'org_id': 'orNoatdUnm1w', | ||
'roles': [ | ||
'FYLER', | ||
'VERIFIER', | ||
'PAYMENT_PROCESSOR', | ||
'FINANCE', | ||
'ADMIN', | ||
'AUDITOR', | ||
"org_id": "orNoatdUnm1w", | ||
"roles": [ | ||
"FYLER", | ||
"VERIFIER", | ||
"PAYMENT_PROCESSOR", | ||
"FINANCE", | ||
"ADMIN", | ||
"AUDITOR", | ||
], | ||
'user': { | ||
'email': '[email protected]', | ||
'full_name': 'Joanna', | ||
'id': 'usqywo0f3nBY' | ||
"user": { | ||
"email": "[email protected]", | ||
"full_name": "Joanna", | ||
"id": "usqywo0f3nBY", | ||
}, | ||
'user_id': 'usqywo0f3nBY', | ||
"user_id": "usqywo0f3nBY", | ||
} | ||
} | ||
}, | ||
"fyle_expense_custom_fields": [ | ||
{"field_name": "employee_email", "type": "SELECT", "is_custom": False}, | ||
{"field_name": "claim_number", "type": "TEXT", "is_custom": False}, | ||
{"field_name": "report_title", "type": "TEXT", "is_custom": False}, | ||
{"field_name": "spent_at", "type": "DATE", "is_custom": False}, | ||
{"field_name": "Class", "type": "SELECT", "is_custom": True}, | ||
{"field_name": "Fyle Categories", "type": "SELECT", "is_custom": True}, | ||
{"field_name": "Operating System", "type": "SELECT", "is_custom": True}, | ||
{"field_name": "User Dimension", "type": "SELECT", "is_custom": True}, | ||
{"field_name": "Asdasdas", "type": "SELECT", "is_custom": True}, | ||
{"field_name": "Nilesh Custom Field", "type": "SELECT", "is_custom": True}, | ||
], | ||
"get_all_custom_fields": [ | ||
{ | ||
"data": [ | ||
{ | ||
"category_ids": [142151], | ||
"code": None, | ||
"column_name": "text_column6", | ||
"created_at": "2021-10-22T07:50:04.613487+00:00", | ||
"default_value": None, | ||
"field_name": "Class", | ||
"id": 197380, | ||
"is_custom": True, | ||
"is_enabled": True, | ||
"is_mandatory": False, | ||
"options": ["Servers", "Home", "Office"], | ||
"org_id": "orGcBCVPijjO", | ||
"placeholder": "Select Class", | ||
"seq": 1, | ||
"type": "SELECT", | ||
"updated_at": "2023-01-01T05:35:26.345303+00:00", | ||
}, | ||
] | ||
} | ||
], | ||
} |
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,36 @@ | ||
import pytest | ||
import json | ||
from django.urls import reverse | ||
|
||
from tests.helper import dict_compare_keys | ||
from tests.test_fyle.fixtures import fixtures as fyle_fixtures | ||
|
||
|
||
@pytest.mark.django_db(databases=['default']) | ||
def test_fyle_expense_fields( | ||
api_client, | ||
test_connection, | ||
create_temp_workspace, | ||
add_fyle_credentials, | ||
add_sage300_creds, | ||
mocker, | ||
): | ||
workspace_id = 1 | ||
|
||
access_token = test_connection.access_token | ||
url = reverse('fyle-expense-fields', kwargs={'workspace_id': workspace_id}) | ||
|
||
mocker.patch( | ||
'fyle.platform.apis.v1beta.admin.ExpenseFields.list_all', | ||
return_value=fyle_fixtures['get_all_custom_fields'], | ||
) | ||
|
||
api_client.credentials(HTTP_AUTHORIZATION="Bearer {}".format(access_token)) | ||
|
||
response = api_client.get(url) | ||
assert response.status_code == 200 | ||
response = json.loads(response.content) | ||
|
||
assert ( | ||
dict_compare_keys(response, fyle_fixtures['fyle_expense_custom_fields']) == [] | ||
), 'expense group api return diffs in keys' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please put this in serializer?
Rushikesh user MethodSerializer somewhere to do something similar, please check it out