From 946da4628b051d23f9beef699b5a5f3cf56deec5 Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Mon, 19 Aug 2024 10:19:17 +0530 Subject: [PATCH] Fix: Delete Expense Filter (#632) * Fix: Delete Expense Filter * fix pytest" * add tests * add tests --------- Co-authored-by: GitHub Actions --- .github/workflows/codecov.yml | 6 ++--- .github/workflows/pytest_action.yml | 6 ++--- apps/fyle/urls.py | 3 ++- apps/fyle/views.py | 35 +++++++++-------------------- tests/test_fyle/test_views.py | 10 +++++++++ 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 5d6c6cd9..14071ffa 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -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: diff --git a/.github/workflows/pytest_action.yml b/.github/workflows/pytest_action.yml index 68dde4ef..4efb4898 100644 --- a/.github/workflows/pytest_action.yml +++ b/.github/workflows/pytest_action.yml @@ -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: diff --git a/apps/fyle/urls.py b/apps/fyle/urls.py index b6db6fd7..874d39d9 100644 --- a/apps/fyle/urls.py +++ b/apps/fyle/urls.py @@ -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'), @@ -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//', 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'), diff --git a/apps/fyle/views.py b/apps/fyle/views.py index c09e0872..1243a8cf 100644 --- a/apps/fyle/views.py +++ b/apps/fyle/views.py @@ -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 """ @@ -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): """ diff --git a/tests/test_fyle/test_views.py b/tests/test_fyle/test_views.py index 81889754..77da9ec8 100644 --- a/tests/test_fyle/test_views.py +++ b/tests/test_fyle/test_views.py @@ -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):