Fakultas Ilmu Komputer UI

Commit 0289117c authored by Azhar Difa Arnanda's avatar Azhar Difa Arnanda 💬
Browse files

Merge branch 'PBI-3-menghapus_donation' into 'dev'

#2 : PBI 3 Menghapus Donation

Closes #2

See merge request !3
parents 8a8b9ca8 17708af1
Pipeline #69192 passed with stages
in 5 minutes and 40 seconds
import decimal
from os import name
import tempfile
from unittest import mock
import datetime
......@@ -1634,6 +1635,21 @@ class ProgramDonationTest(rest_framework_test.APITestCase):
url_args=[program_donation.id]
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_delete_by_program(self):
program = models.Program.objects.create(**seeds.PROGRAM_DATA )
donation = models.ProgramDonation.objects.create(**dict(
seeds.PROGRAM_DONATION_CASH_DATA,
user=self.user,
program=program))
response = request(
'DELETE',
'donation-by-program',
http_authorization=self.superuser_http_authorization,
url_args=[program.id]
)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(models.ProgramDonation.objects.count(), 0)
class ChoicesViewsTest(rest_framework_test.APITestCase):
......
......@@ -30,6 +30,7 @@ urlpatterns = [
name='cart-cancel-transaction'
),
urls.path('donation/create/', api_views.DonationCreate.as_view(), name='donation-create'),
urls.path('donation/delete-by-p/<str:pid>', api_views.delete_donation_by_program, name='donation-by-program'),
urls.path(
'donation/reupload-proof-of-bank-transfer/',
api_views.DonationReuploadProofOfBankTransfer.as_view(),
......
from django import http, shortcuts
from django.contrib import auth
from django.db import transaction as db_transaction, utils as db_utils
......@@ -12,7 +11,8 @@ from rest_framework import (
permissions as rest_framework_permissions, response, status, views as rest_framework_views
)
from rest_framework.authtoken import serializers as authtoken_serializers
from rest_framework.decorators import api_view
from django.views.decorators.csrf import csrf_exempt
from api import (
constants, exceptions as api_exceptions, filters as api_filters, models, paginations,
permissions as api_permissions, reports_writer, schemas, serializers as api_serializers,
......@@ -844,6 +844,14 @@ class ProgramDonationList(generics.ListAPIView):
return queryset.filter(user=self.request.user)
return queryset
@api_view(['DELETE'])
@csrf_exempt
def delete_donation_by_program(request, pid):
if ((request.user) and (request.user.is_staff)):
program = models.Program.objects.get(id=pid)
donation = models.ProgramDonation.objects.filter(program=program)
donation.delete()
return response.Response(status=status.HTTP_204_NO_CONTENT)
class ProgramDonationListCSH(generics.ListAPIView):
filter_backends = [
......
File mode changed from 100644 to 100755
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment