Skip to content

Commit

Permalink
Added tests for previous bug reports (#352)
Browse files Browse the repository at this point in the history
* modified mappings and workspace tests

* modified tests for fyle, mappings, workspace modules, 96.5% coverage

* modified quickbooks module tests (#350)

* modified quickbooks module tests

* fixed comments

* Add tests for prev bug reports

* fixed comments
  • Loading branch information
harshithaputtaswamy authored Nov 7, 2022
1 parent 45351d2 commit 696ea05
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: |
docker-compose -f docker-compose-pipeline.yml build
docker-compose -f docker-compose-pipeline.yml up -d
docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov=. --junit-xml=test-reports/report.xml --cov-report=term-missing --cov-fail-under=90 | tee pytest-coverage.txt
docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov=. --junit-xml=test-reports/report.xml --cov-report=term-missing --cov-fail-under=97 | tee pytest-coverage.txt
echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV
echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV
env:
Expand Down
22 changes: 20 additions & 2 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,24 @@
},
"user_id":"usqywo0f3nBY"
}
}

},
'get_all_orgs': [
{
'id': 'orHVw3ikkCxJ',
'created_at': '2018-12-18T10:50:36.506Z',
'updated_at': '2018-12-18T10:51:53.352Z',
'name': 'Anagha Org',
'domain': 'afyle.in',
'currency': 'EUR',
'branch_ifsc': None,
'branch_account': None,
'tally_bank_ledger': None,
'tally_default_category': None,
'tally_default_user': None,
'corporate_credit_card_details': {'bank_name': None,
'number_of_cards': None},
'verified': True,
'lite': False,
'dwolla_customers_metadata_id': None,
},],
}
13 changes: 6 additions & 7 deletions tests/test_fyle/test_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import random
import pytest
from apps.fyle.models import _format_date, _group_expenses
from apps.fyle.models import *
from .fixtures import data
import datetime

def test_default_fields():
expense_group_field = get_default_expense_group_fields()
Expand Down Expand Up @@ -64,12 +61,14 @@ def test_create_expense_groups_by_report_id_fund_source(db):
expense_group_settings.ccc_export_date_type = 'last_spent_at'
expense_group_settings.save()

field = ExpenseAttribute.objects.filter(workspace_id=workspace_id).first()
field.attribute_type = 'COOL'
field = ExpenseAttribute.objects.filter(workspace_id=workspace_id, attribute_type='PROJECT').last()
field.attribute_type = 'KILLUA'
field.save()

expense_groups = _group_expenses([], ['claim_number', 'fund_source', 'projects', 'employee_email', 'report_id', 'cool'], 4)
assert expense_groups == []
expenses = Expense.objects.filter(id=33).all()

expense_groups = _group_expenses(expenses, ['claim_number', 'fund_source', 'project', 'employee_email', 'report_id', 'Killua'], 4)
assert expense_groups == [{'claim_number': 'C/2022/05/R/6', 'fund_source': 'PERSONAL', 'project': 'Bebe Rexha', 'employee_email': '[email protected]', 'report_id': 'rpawE81idoYo', 'killua': '', 'total': 1, 'expense_ids': [33]}]

expense_groups = ExpenseGroup.create_expense_groups_by_report_id_fund_source([expense_objects], workspace_id)
assert len(expense_groups) == 1
Expand Down
16 changes: 10 additions & 6 deletions tests/test_users/test_views.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
from django.urls import reverse
import pytest

from tests.test_fyle.fixtures import data as fyle_data

# Will use paramaterize decorator of python later
@pytest.mark.django_db(databases=['default'])
def test_get_profile_view(api_client, test_connection):

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

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

def test_get_fyle_orgs_view(mocker, api_client, test_connection):

@pytest.mark.django_db(databases=['default'])
def test_get_fyle_orgs_view(api_client, test_connection, mocker):
mocker.patch(
'apps.users.views.get_fyle_orgs',
return_value=['fyleforgotham.in']
return_value=fyle_data['get_all_orgs']
)
access_token = test_connection.access_token
url = reverse('orgs')
api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))
api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(test_connection.access_token))

response = api_client.get(url)
assert response.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ def test_export_settings(api_client, test_connection):
response = json.loads(response.content)
assert dict_compare_keys(response, data['response']) == [], 'workspaces api returns a diff in the keys'

invalid_workspace_general_settings = data['export_settings']
invalid_workspace_general_settings['workspace_general_settings'] = {}
response = api_client.put(
url,
data=data['export_settings_missing_values'],
data=invalid_workspace_general_settings,
format='json'
)

assert response.status_code == 400

invalid_expense_group_settings = data['export_settings']
invalid_expense_group_settings['expense_group_settings'] = {}
invalid_expense_group_settings['workspace_general_settings'] = {'reimbursable_expenses_object': 'EXPENSE',
'corporate_credit_card_expenses_object': 'BILL'
}

response = api_client.put(
url,
data=invalid_expense_group_settings,
format='json'
)

Expand Down
43 changes: 38 additions & 5 deletions tests/test_workspaces/test_apis/test_import_settings/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,43 @@
'response': {'workspace_general_settings':{'import_categories':True,'charts_of_accounts':['Expense'],'import_tax_codes':True,'import_vendors_as_merchants':True},'general_mappings':{'default_tax_code':{'name':'12.5% TR @12.5%','id':'22'}},'mapping_settings':[{'source_field':'COST_CENTER','destination_field':'CLASS','import_to_fyle':True,'is_custom':False,'source_placeholder':''},{'source_field':'PROJECT','destination_field':'DEPARTMENT','import_to_fyle':True,'is_custom':False,'source_placeholder':''},{'source_field':'CLASS','destination_field':'CUSTOMER','import_to_fyle':True,'is_custom':True,'source_placeholder':''}],
'workspace_id':9
},
'import_settings_missing_values': {
'mapping_settings': None,
'workspace_general_settings': {},
'general_mappings': {}
'invalid_general_mappings': {
'workspace_general_settings': {
'import_categories': True,
'charts_of_accounts': [
'Expense'
],
'import_tax_codes': True,
'import_vendors_as_merchants': True
},
'general_mappings': {
},
'mapping_settings': [
{
'source_field': 'COST_CENTER',
'destination_field': 'DEPARTMENT',
'import_to_fyle': True,
'is_custom': False,
'source_placeholder': 'cost center'
}
]
},
'invalid_mapping_settings': {
'workspace_general_settings': {
'import_categories': True,
'charts_of_accounts': [
'Expense'
],
'import_tax_codes': True,
'import_vendors_as_merchants': True
},
'general_mappings': {
'default_tax_code': {
'name': '12.5% TR @12.5%',
'id': '22'
}
},
'mapping_settings': None
},

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,28 @@ def test_import_settings(mocker, api_client, test_connection):
)
assert response.status_code == 200

invalid_workspace_general_settings = data['import_settings']
invalid_workspace_general_settings['workspace_general_settings'] = {}
response = api_client.put(
url,
data=data['import_settings_missing_values'],
data=invalid_workspace_general_settings,
format='json'
)
assert response.status_code == 400

response = json.loads(response.content)
assert response['non_field_errors'] == ['Workspace general settings are required']

response = api_client.put(
url,
data=data['invalid_general_mappings'],
format='json'
)
assert response.status_code == 400

response = api_client.put(
url,
data=data['invalid_mapping_settings'],
format='json'
)
assert response.status_code == 400

0 comments on commit 696ea05

Please sign in to comment.