Skip to content

Commit

Permalink
added support for department api (#70)
Browse files Browse the repository at this point in the history
* added support for deartment api

* added tests for admin departments api

* new line

* fixed broken tests

* added new line

* version update
  • Loading branch information
harshithaputtaswamy authored Nov 21, 2022
1 parent 206665a commit ed27d3f
Show file tree
Hide file tree
Showing 11 changed files with 380 additions and 408 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ ENV/
env.bak/
venv.bak/

*.DS_Store
.DS_Store

# Spyder project settings
.spyderproject
.spyproject
Expand Down
2 changes: 2 additions & 0 deletions fyle/platform/apis/v1beta/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .accounting_exports import AccountingExports
from .corporate_cards import CorporateCards
from .corporate_card_transactions import CorporateCardTransactions
from .departments import Departments
from ..version import version

role = 'admin'
Expand All @@ -33,3 +34,4 @@
accounting_exports = AccountingExports(version, role)
corporate_cards = CorporateCards(version, role)
corporate_card_transactions = CorporateCardTransactions(version, role)
departments = Departments(version, role)
16 changes: 16 additions & 0 deletions fyle/platform/apis/v1beta/admin/departments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
V1 Beta Admin Departments
"""

from ....internals.list_resources import ListResources
from ....internals.list_all_resources import ListAllResources
from ....internals.post_resources import PostResources
from ....internals.get_resources import GetResources

class Departments(ListResources, ListAllResources, PostResources, GetResources):
"""Class for Departments APIs."""

DEPARTMENTS = '/departments'

def __init__(self, version, role):
super().__init__(version, role, Departments.DEPARTMENTS)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='fyle',
version='v0.29.1',
version='v0.30.0',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing Fyle Platform APIs',
Expand Down
21 changes: 19 additions & 2 deletions test/integration/admin/fixtures/mock_admin_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,22 @@
"is_enabled": true,
"code": "C1234"
}
]
}
],
"departments": [
{
"code": null,
"created_at": "2022-11-15T16:49:58.330898+00:00",
"department_head_user_ids": [],
"department_head_users": [],
"description": null,
"display_name": "sample",
"doc_url": null,
"id": "deptitPFOc606d",
"is_enabled": false,
"name": "sample",
"org_id": "or79Cob97KSh",
"sub_department": null,
"updated_at": "2022-11-16T12:51:21.455228+00:00"
}
]
}
35 changes: 35 additions & 0 deletions test/integration/admin/test_admin_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,38 @@ def test_get_by_id_tax_groups_missing_id(fyle, mock_data):
get_by_id = fyle.v1beta.admin.tax_groups.get_by_id()
except:
logger.error("id is a requied parameter")


def test_post_departments(fyle, mock_data):
department = {
'data': {
'name': 'sample1',
'id': 'deptCWZRyDcq3Z',
'is_enabled': True
}}

departments_generator = fyle.v1beta.admin.departments.post(department)
mock_departments = mock_data.departments.get()

if departments_generator:
assert dict_compare_keys(departments_generator['data'], mock_departments[0]) == [], 'fyle.v1beta.admin.departments.list_all() has stuff that mock_data doesnt'
assert dict_compare_keys(mock_departments[0], departments_generator['data']) == [], 'mock_data.departments.get() has stuff that fyle doesnt'


def test_list_departments(fyle, mock_data):
departments = []
query_params = {
'order': 'created_at.desc',
'name': 'eq.sample1'
}

departments_generator = fyle.v1beta.admin.departments.list_all(query_params=query_params)
mock_departments = mock_data.departments.get()

for response in departments_generator:
if response.get('data'):
departments.extend(response['data'])

if departments:
assert dict_compare_keys(departments[0], mock_departments[0]) == [], 'fyle.v1beta.admin.departments.list_all() has stuff that mock_data doesnt'
assert dict_compare_keys(mock_departments[0], departments[0]) == [], 'mock_data.departments.get() has stuff that fyle doesnt'
1 change: 1 addition & 0 deletions test/integration/admin/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_mock_data_from_file(filename):
mock_data.files_create.get.return_value = mock_data_dict['file_create']
mock_data.file_generate_url.get.return_value = mock_data_dict['file_generate_url']
mock_data.tax_groups.get.return_value = mock_data_dict['tax_groups']
mock_data.departments.get.return_value = mock_data_dict['departments']

return mock_data

Expand Down
96 changes: 58 additions & 38 deletions test/integration/approver/fixtures/mock_approver_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,65 @@
],
"reports": [
{
"id": "sdfd2391",
"org_id": "orwruogwnngg",
"created_at": "2020-06-01T13:14:54.804+00:00",
"updated_at": "2020-06-11T13:14:55.201598+00:00",
"user_id": "sdfd2391",
"user": {
"id": "uswjwgnwwgo",
"email": "[email protected]",
"full_name": "John Doe"
},
"purpose": "Business trip to London",
"currency": "USD",
"amount": 47.99,
"tax": 18.23,
"state": "DRAFT",
"num_expenses": 3,
"is_verified": true,
"settlement_id": "set5nlgnwgwl",
"is_physical_bill_submitted": true,
"physical_bill_submitted_at": "2020-06-11T13:14:55.201598+00:00",
"is_manually_flagged": true,
"is_policy_flagged": true,
"is_exported": true,
"last_paid_at": "2020-06-11T13:14:55.201598+00:00",
"last_approved_at": "2020-06-11T13:14:55.201598+00:00",
"last_submitted_at": "2020-06-11T13:14:55.201598+00:00",
"seq_num": "C/2021/02/R/907",
"source": "string",
"approvals": [
"amount":50,
"approvals":[
{
"approver_user_id": "usge49ielgel",
"approver_user": {
"id": "uswjwgnwwgo",
"email": "[email protected]",
"full_name": "John Doe"
},
"state": "APPROVAL_PENDING"
"approver_user":{
"email":"[email protected]",
"full_name":"Joanna",
"id":"usqywo0f3nBY"
},
"approver_user_id":"usqywo0f3nBY",
"state":"APPROVAL_DONE"
}
]
],
"created_at":"2021-10-22T07:43:08.159902+00:00",
"currency":"USD",
"employee":{
"ach_account":{
"added":"None",
"verified":"None"
},
"code":"None",
"department":"None",
"department_id":"None",
"id":"ou77JxTLLifN",
"org_id":"orf7jLXAJ6SY",
"user":{
"email":"[email protected]",
"full_name":"Ashwin",
"id":"usqywo0f3nBY"
},
"user_id":"usqywo0f3nBY"
},
"employee_id":"ou77JxTLLifN",
"id":"rpnWQIpTxPzl",
"is_exported":false,
"is_manually_flagged":false,
"is_physical_bill_submitted":false,
"is_policy_flagged":false,
"is_verified":false,
"last_approved_at":"2021-10-22T07:43:12.802000+00:00",
"last_paid_at":"2022-05-23T01:39:10.004000+00:00",
"last_resubmitted_at":"None",
"last_submitted_at":"2021-10-22T07:43:08.615000+00:00",
"next_approver_user_ids":"None",
"num_expenses":1,
"org_id":"orf7jLXAJ6SY",
"physical_bill_submitted_at":"None",
"purpose":"#2: Oct 2021",
"seq_num":"C/2021/10/R/2",
"settlement_id":"setKvFHOzcAjt",
"source":"WEBAPP",
"state":"PAID",
"tax":0.5,
"updated_at":"2022-10-27T05:09:08.976413+00:00",
"user":{
"email":"[email protected]",
"full_name":"Joanna",
"id":"usqywo0f3nBY"
},
"user_id":"usqywo0f3nBY"
}
]
}
}
16 changes: 7 additions & 9 deletions test/integration/approver/test_approver_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ def test_list_all_categories(fyle, mock_data):
# Get a list of all Categories in a paginated manner and add to a list
categories = []
query_params = {
'order': 'created_at.desc'
'order': 'created_at.desc',
'limit': 100,
'offset': 10
}

categories_generator = fyle.v1beta.approver.categories.list_all(query_params=query_params)
categories_generator = fyle.v1beta.approver.categories.list(query_params=query_params)
mock_categories = mock_data.categories.get()

for response in categories_generator:
if response.get('data'):
categories.extend(response['data'])

if categories:
assert dict_compare_keys(categories[0], mock_categories[0]) == [], 'fyle.v1beta.approver.categories.list_all() has stuff that mock_data doesnt'
assert dict_compare_keys(mock_categories[0], categories[0]) == [], 'mock_data.categories.get() has stuff that fyle doesnt'
if categories_generator['data']:
assert dict_compare_keys(categories_generator['data'][0], mock_categories[0]) == [], 'fyle.v1beta.approver.categories.list_all() has stuff that mock_data doesnt'
assert dict_compare_keys(mock_categories[0], categories_generator['data'][0]) == [], 'mock_data.categories.get() has stuff that fyle doesnt'


def test_list_reports(fyle, mock_data):
Expand Down
Loading

0 comments on commit ed27d3f

Please sign in to comment.