Skip to content

Commit

Permalink
Fix: Delete Expense Filter (#632)
Browse files Browse the repository at this point in the history
* Fix: Delete Expense Filter

* fix pytest"

* add tests

* add tests

---------

Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
ruuushhh and GitHub Actions committed Aug 19, 2024
1 parent 22cbd81 commit 946da46
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
submodules: recursive
- name: Bring up Services and Run Tests
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 --cov-report=xml --cov-fail-under=86
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 --cov-report=xml --cov-fail-under=86
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
6 changes: 3 additions & 3 deletions .github/workflows/pytest_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
submodules: recursive
- name: Bring up Services and Run Tests
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 --cov-report=xml --cov-fail-under=86 --junit-xml=test-reports/report.xml | tee pytest-coverage.txt
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 --cov-report=xml --cov-fail-under=86 --junit-xml=test-reports/report.xml | 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
3 changes: 2 additions & 1 deletion apps/fyle/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .views import ExpenseGroupSyncView, ExpenseGroupView, ExpenseGroupByIdView, ExpenseGroupScheduleView, ExpenseGroupViewV2, ExpenseViewV2, ExportableExpenseGroupsView, FyleFieldsView, ExpenseView,\
ExpenseAttributesView, ExpenseGroupSettingsView, SyncFyleDimensionView, RefreshFyleDimensionView,\
ExpenseGroupCountView, ExpenseFilterView, ExpenseGroupExpenseView, CustomFieldView, ExportView
ExpenseGroupCountView, ExpenseFilterView, ExpenseGroupExpenseView, CustomFieldView, ExportView, ExpenseFilterDeleteView

expense_groups_paths = [
path('expense_groups/', ExpenseGroupView.as_view(), name='expense-groups'),
Expand All @@ -28,6 +28,7 @@
path('expense_attributes/', ExpenseAttributesView.as_view(), name='expense-attributes'),
path('fyle_fields/', FyleFieldsView.as_view(), name='fyle-fields'),
path('fields/', FyleFieldsView.as_view(), name='fyle-fields-v2'),
path('expense_filters/<int:pk>/', ExpenseFilterDeleteView.as_view(), name='expense-filters-delete'),
path('expense_filters/', ExpenseFilterView.as_view(), name='expense-filters'),
path('expenses/', ExpenseView.as_view(), name='expenses'),
path('expenses/v2/', ExpenseViewV2.as_view(), name='expenses-v2'),
Expand Down
35 changes: 10 additions & 25 deletions apps/fyle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,16 @@ def post(self, request, *args, **kwargs):
)


class ExpenseFilterView(generics.ListCreateAPIView, generics.DestroyAPIView):
class ExpenseFilterDeleteView(generics.DestroyAPIView):
"""
Expense Filter view
"""

queryset = ExpenseFilter.objects.all()
serializer_class = ExpenseFilterSerializer


class ExpenseFilterView(generics.ListCreateAPIView):
"""
Expense Filter view
"""
Expand All @@ -336,30 +345,6 @@ def get_queryset(self):
queryset = ExpenseFilter.objects.filter(workspace_id=self.kwargs['workspace_id']).order_by('rank')
return queryset

def delete(self, request, *args, **kwargs):
try:
workspace_id = self.kwargs['workspace_id']
rank = self.request.query_params.get('rank').split(',')
ExpenseFilter.objects.filter(workspace_id=workspace_id, rank__in=rank).delete()

return Response(data={
'workspace_id': workspace_id,
'rank': rank,
'message': 'Expense filter deleted'
})

except Exception as exception:
logger.error(
'Something went wrong - %s in Fyle %s %s',
workspace_id, exception.message, {'error': exception.response}
)
return Response(
data={
'message': 'Something went wrong'
},
status=status.HTTP_400_BAD_REQUEST
)


class ExpenseView(generics.ListAPIView):
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/test_fyle/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ def test_expense_filters(api_client, access_token):

assert dict_compare_keys(response, data['expense_filters_response']) == [], 'expense group api return diffs in keys'

url = reverse('expense-filters-delete',
kwargs={
'workspace_id': 1,
'pk': 2
})

response = api_client.delete(url)
assert response.status_code == 204


@pytest.mark.django_db(databases=['default'])
def test_custom_fields(mocker, api_client, access_token):

Expand Down

0 comments on commit 946da46

Please sign in to comment.