Skip to content

Commit

Permalink
test: Internal APIs (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 authored Nov 26, 2024
1 parent be221fb commit 140a47c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
Empty file added tests/test_internal/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions tests/test_internal/test_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from apps.internal.actions import get_accounting_fields, get_exported_entry
from tests.test_quickbooks_online.fixtures import data


def test_get_accounting_fields(db, mocker):
query_params = {
'org_id': 'or79Cob97KSh',
'resource_type': 'employees',
}
mocker.patch(
'qbosdk.apis.Employees.get_all_generator',
return_value=[data['employee_response']]
)

fields = get_accounting_fields(query_params)
assert fields is not None


def test_get_exported_entry(db, mocker):
query_params = {
'org_id': 'or79Cob97KSh',
'resource_type': 'bills',
'internal_id': '1'
}
mocker.patch(
'qbosdk.apis.Bills.get_by_id',
return_value={'summa': 'hehe'}
)

entry = get_exported_entry(query_params)
assert entry is not None
50 changes: 50 additions & 0 deletions tests/test_internal/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
from unittest.mock import patch
from django.urls import reverse

from apps.workspaces.permissions import IsAuthenticatedForInternalAPI

from tests.test_quickbooks_online.fixtures import data


@pytest.mark.django_db(databases=['default'])
@patch.object(IsAuthenticatedForInternalAPI, 'has_permission', return_value=True)
def test_qbo_fields_view(db, api_client, mocker):
url = reverse('accounting-fields')

response = api_client.get(url)
assert response.status_code == 400

response = api_client.get(url, {'org_id': 'or79Cob97KSh'})
assert response.status_code == 400

mocker.patch(
'qbosdk.apis.Employees.get_all_generator',
return_value=[data['employee_response']]
)

response = api_client.get(url, {'org_id': 'or79Cob97KSh', 'resource_type': 'employees'})
assert response.status_code == 200


@pytest.mark.django_db(databases=['default'])
@patch.object(IsAuthenticatedForInternalAPI, 'has_permission', return_value=True)
def test_exported_entry_view(db, api_client, mocker):
url = reverse('exported-entry')

response = api_client.get(url)
assert response.status_code == 400

response = api_client.get(url, {'org_id': 'or79Cob97KSh'})
assert response.status_code == 400

response = api_client.get(url, {'org_id': 'or79Cob97KSh', 'resource_type': 'bills'})
assert response.status_code == 400

mocker.patch(
'qbosdk.apis.Bills.get_by_id',
return_value={'summa': 'hehe'}
)

response = api_client.get(url, {'org_id': 'or79Cob97KSh', 'resource_type': 'bills', 'internal_id': '1'})
assert response.status_code == 200
8 changes: 4 additions & 4 deletions tests/test_workspaces/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_connect_qbo_view_exceptions(api_client, test_connection):
def test_prepare_e2e_test_view(mock_db, mocker, api_client, test_connection):
url = reverse('setup-e2e-test', kwargs={'workspace_id': 3})

api_client.credentials(HTTP_X_E2E_Tests_Client_ID='dummy_id')
api_client.credentials(HTTP_X_Internal_API_Client_ID='dummy_id')
response = api_client.post(url)
assert response.status_code == 403

Expand All @@ -175,7 +175,7 @@ def test_prepare_e2e_test_view(mock_db, mocker, api_client, test_connection):
mocker.patch('fyle_integrations_platform_connector.fyle_integrations_platform_connector.PlatformConnector.import_fyle_dimensions', return_value=[])
mocker.patch('apps.workspaces.models.QBOCredential.objects.create', return_value=None)

api_client.credentials(HTTP_X_E2E_Tests_Client_ID='dummy_id')
api_client.credentials(HTTP_X_Internal_API_Client_ID='dummy_id')
response = api_client.post(url)
assert response.status_code == 400

Expand All @@ -184,12 +184,12 @@ def test_prepare_e2e_test_view(mock_db, mocker, api_client, test_connection):
healthy_token.is_expired = False
healthy_token.save()

api_client.credentials(HTTP_X_E2E_Tests_Client_ID='gAAAAABi8oXHBll3lEUPGpMDXnZDhVgSl_LMOkIF0ilfmSCL3wFxZnoTIbpdzwPoOFzS0vFO4qaX51JtAqCG2RBHZaf1e98hug==')
api_client.credentials(HTTP_X_Internal_API_Client_ID='gAAAAABi8oXHBll3lEUPGpMDXnZDhVgSl_LMOkIF0ilfmSCL3wFxZnoTIbpdzwPoOFzS0vFO4qaX51JtAqCG2RBHZaf1e98hug==')
response = api_client.post(url)
assert response.status_code == 200

url = reverse('setup-e2e-test', kwargs={'workspace_id': 6})
api_client.credentials(HTTP_X_E2E_Tests_Client_ID='gAAAAABi8oWVoonxF0K_g2TQnFdlpOJvGsBYa9rPtwfgM-puStki_qYbi0PdipWHqIBIMip94MDoaTP4MXOfERDeEGrbARCxPw==')
api_client.credentials(HTTP_X_Internal_API_Client_ID='gAAAAABi8oWVoonxF0K_g2TQnFdlpOJvGsBYa9rPtwfgM-puStki_qYbi0PdipWHqIBIMip94MDoaTP4MXOfERDeEGrbARCxPw==')
response = api_client.post(url)
assert response.status_code == 400

Expand Down

0 comments on commit 140a47c

Please sign in to comment.