Skip to content

Commit

Permalink
test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Oct 26, 2023
1 parent 59da8e1 commit 9a2c55e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 17 deletions.
10 changes: 4 additions & 6 deletions apps/accounting_exports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
CustomJsonField,
CustomDateTimeField
)
from apps.workspaces.models import BaseModel
from apps.workspaces.models import BaseForeignWorkspaceModel
from apps.fyle.models import Expense
from apps.sage300.models import Invoice, DirectCost



class AccountingExport(BaseModel):
class AccountingExport(BaseForeignWorkspaceModel):
"""
Table to store accounting exports
"""
id = models.AutoField(primary_key=True)
type = StringNotNullField(max_length=50, help_text='Task type (FETCH_EXPENSES / INVOICES / DIRECT_COST)')
fund_source = StringNotNullField(help_text='Expense fund source')
mapping_errors = ArrayField()
mapping_errors = ArrayField(help_text='Mapping errors', base_field=models.CharField(max_length=255), blank=True, null=True)
expenses = models.ManyToManyField(Expense, help_text="Expenses under this Expense Group")
task_id = StringNullField(help_text='Fyle Jobs task reference')
description = CustomJsonField(help_text='Description')
Expand All @@ -29,4 +27,4 @@ class AccountingExport(BaseModel):
exported_at = CustomDateTimeField(help_text='time of export')

class Meta:
db_table = 'accounting_exports'
db_table = 'accounting_exports'
20 changes: 9 additions & 11 deletions apps/sage300/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from django.db import models
from apps.workspaces.models import BaseModel
from sage_desktop_api.models.fields import (
from sage_desktop_api.models.fields import (
StringNotNullField,
CustomDateTimeField,
FloatNullField,
IntegerNullField,
TextNotNullField
)

from apps.workspaces.models import Workspace
from apps.accounting_exports.models import AccountingExport


Expand All @@ -21,8 +19,8 @@ class Invoice(BaseModel):
date: '2021-04-26',
accounting_date: 'Accounts Payable',
description: 'Reimbursable Expenses by Shwetabh',
tax_amount: 1.32,
vendor_id: '12312123123'
tax_amount: 1.32,
vendor_id: '12312123123'
"""

id = models.AutoField(primary_key=True)
Expand All @@ -48,9 +46,9 @@ class InvoiceLineitems(BaseModel):
accounts_payable_account_id: '123123',
expense_account_id: '1231231',
description: 'Reimbursable Expenses by Shwetabh',
job_id: '123123',
cost_code_id: '12312123123'
category_id: '123'
job_id: '123123',
cost_code_id: '12312123123'
category_id: '123'
"""

id = models.AutoField(primary_key=True)
Expand All @@ -76,9 +74,9 @@ class DirectCost(BaseModel):
accounts_payable_account_id: '123123',
expense_account_id: '1231231',
description: 'Reimbursable Expenses by Shwetabh',
job_id: '123123',
cost_code_id: '12312123123'
category_id: '123'
job_id: '123123',
cost_code_id: '12312123123'
category_id: '123'
"""

id = models.AutoField(primary_key=True)
Expand Down
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Sage300Credentials
)
from apps.fyle.models import ExpenseFilter
from apps.accounting_exports.models import AccountingExport
from sage_desktop_api.tests import settings

from .test_fyle.fixtures import fixtures as fyle_fixtures
Expand Down Expand Up @@ -202,3 +203,30 @@ def add_expense_filters():
custom_field_type='SELECT',
workspace_id=workspace_id
)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_accounting_export_expenses():
"""
Pytest fixture to add accounting export to a workspace
"""
workspace_ids = [
1, 2, 3
]
for workspace_id in workspace_ids:
AccountingExport.objects.update_or_create(
workspace_id=workspace_id,
type='FETCHING_REIMBURSABLE_EXPENSES',
defaults={
'status': 'IN_PROGRESS'
}
)

AccountingExport.objects.update_or_create(
workspace_id=workspace_id,
type='FETCHING_CREDIT_CARD_EXPENSES',
defaults={
'status': 'IN_PROGRESS'
}
)
Empty file.
19 changes: 19 additions & 0 deletions tests/test_accounting_exports/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
from django.urls import reverse
from tests.helper import dict_compare_keys
from tests.test_fyle.fixtures import fixtures as data


def test_get_accounting_exports(api_client, test_connection, create_temp_workspace, add_fyle_credentials, add_accounting_export_expenses):
"""
Test get accounting exports
"""
url = reverse('accounting-exports', kwargs={'workspace_id': 1})

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

response = api_client.get(url)
assert response.status_code == 200
response = json.loads(response.content)

assert dict_compare_keys(response, data['accounting_export_response']) == [], 'expense group api return diffs in keys'
39 changes: 39 additions & 0 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,44 @@
"workspace": 1,
},
],
},
'accounting_export_response': {
"count":2,
"next":"None",
"previous":"None",
"results":[
{
"id":2,
"created_at":"2023-10-26T03:24:43.513291Z",
"updated_at":"2023-10-26T03:24:43.513296Z",
"type":"FETCHING_CREDIT_CARD_EXPENSES",
"fund_source":"",
"mapping_errors":"None",
"task_id":"None",
"description":[],
"status":"IN_PROGRESS",
"detail":[],
"sage_intacct_errors":[],
"exported_at":"None",
"workspace":1,
"expenses":[]
},
{
"id":1,
"created_at":"2023-10-26T03:24:43.511973Z",
"updated_at":"2023-10-26T03:24:43.511978Z",
"type":"FETCHING_REIMBURSABLE_EXPENSES",
"fund_source":"",
"mapping_errors":"None",
"task_id":"None",
"description":[],
"status":"IN_PROGRESS",
"detail":[],
"sage_intacct_errors":[],
"exported_at":"None",
"workspace":1,
"expenses":[]
}
]
}
}

0 comments on commit 9a2c55e

Please sign in to comment.