Skip to content

Commit

Permalink
unit tests views
Browse files Browse the repository at this point in the history
  • Loading branch information
anishfyle committed Jul 18, 2024
1 parent e10294f commit 9d6be94
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 1 deletion.
58 changes: 58 additions & 0 deletions tests/test_fyle/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,61 @@ def test_sync_fyle_dimension_view(api_client, test_connection, mocker):
assert response.status_code == 200
assert len(qbd_mapping) == fixture['get_qbd_ccc_mapping']['count']
assert qbd_mapping[0].source_value == fixture['get_qbd_ccc_mapping']['results'][0]['source_value']


def test_sync_fyle_dimension_projects(api_client, test_connection, mocker):
mocker.patch(
'fyle.platform.apis.v1beta.admin.projects.list_all',
return_value=fixture['project_list']
)
url = reverse(
'workspaces'
)

api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(test_connection.access_token))
response = api_client.post(url)

workspace_id = response.data['id']

url = reverse(
'sync-fyle-dimensions', kwargs={
'workspace_id': workspace_id
}
)

response = api_client.post(url)

qbd_mapping = QBDMapping.objects.filter(workspace_id=workspace_id)

assert response.status_code == 200
assert len(qbd_mapping) == fixture['get_qbd_ccc_mapping_project']['count']
assert qbd_mapping[0].source_value == fixture['get_qbd_ccc_mapping_project']['results'][0]['source_value']


def test_sync_fyle_dimension_cost_center(api_client, test_connection, mocker):
mocker.patch(
'fyle.platform.apis.v1beta.admin.cost_center.list_all',
return_value=fixture['cost_center_list']
)
url = reverse(
'workspaces'
)

api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(test_connection.access_token))
response = api_client.post(url)

workspace_id = response.data['id']

url = reverse(
'sync-fyle-dimensions', kwargs={
'workspace_id': workspace_id
}
)

response = api_client.post(url)

qbd_mapping = QBDMapping.objects.filter(workspace_id=workspace_id)

assert response.status_code == 200
assert len(qbd_mapping) == fixture['get_qbd_ccc_mapping_cost_center']['count']
assert qbd_mapping[0].source_value == fixture['get_qbd_ccc_mapping_cost_center']['results'][0]['source_value']
114 changes: 113 additions & 1 deletion tests/test_mapping/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,117 @@
"workspace": 1
},
]
}
},
'project_list':
[
{
'count': 2,
'data':
[
{
"attribute_type": "PROJECT",
"source_value": "Aaron",
"source_id": "1234"
},
{
"attribute_type": "PROJECT",
"source_value": "Abbott",
"source_id": "5678"
},
]
}
],
'cost_center_list':
[
{
'count': 2,
'data':
[
{
"attribute_type": "COST_CENTER",
"source_value": "Administration",
"source_id": "1234"
},
{
"attribute_type": "COST_CENTER",
"source_value": "Analytics",
"source_id": "5678"
},
]
}
],
'get_qbd_ccc_mapping_cost_center': {
"count": 2,
"next": "http://localhost:8008/api/workspaces/1/qbd_mappings/?attribute_type=ITEMS",
"previous": '',
"results": [
{
"id": 3,
"attribute_type": "COST_CENTER",
"source_value": "Administration",
"source_id": "1234",
"destination_value": "",
"created_at": "2023-08-25T11:19:09.625706Z",
"updated_at": "2023-08-28T05:46:59.326614Z",
"workspace": 1
},
{
"id": 4,
"attribute_type": "COST_CENTER",
"source_value": "Analytics",
"source_id": "5678",
"destination_value": "",
"created_at": "2023-08-25T11:19:09.627857Z",
"updated_at": "2023-08-28T05:46:59.330073Z",
"workspace": 1
},
]
},
'get_qbd_ccc_mapping_project': {
"count": 2,
"next": "http://localhost:8008/api/workspaces/1/qbd_mappings/?attribute_type=ITEMS",
"previous": '',
"results": [
{
"id": 3,
"attribute_type": "PROJECT",
"source_value": "Aaron",
"source_id": "1234",
"destination_value": "",
"created_at": "2023-08-25T11:19:09.625706Z",
"updated_at": "2023-08-28T05:46:59.326614Z",
"workspace": 1
},
{
"id": 4,
"attribute_type": "PROJECT",
"source_value": "Abbott",
"source_id": "5678",
"destination_value": "",
"created_at": "2023-08-25T11:19:09.627857Z",
"updated_at": "2023-08-28T05:46:59.330073Z",
"workspace": 1
},
]
},
'post_qbd_ccc_mapping_project': {
"id": 1,
"attribute_type": "PROJECT",
"source_value": "Aaron",
"source_id": "1234",
"destination_value": "Mastercard",
"created_at": "2023-08-25T11:19:09.608035Z",
"updated_at": "2023-08-28T10:07:30.524503Z",
"workspace": 1
},
'post_qbd_ccc_mapping_cost_center': {
"id": 1,
"attribute_type": "COST_CENTER",
"source_value": "Analystics",
"source_id": "5678",
"destination_value": "Mastercard",
"created_at": "2023-08-25T11:19:09.608035Z",
"updated_at": "2023-08-28T10:07:30.524503Z",
"workspace": 1
},
}

0 comments on commit 9d6be94

Please sign in to comment.