Coverage for payments/views.py: 94%
36 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-05-16 12:38 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-05-16 12:38 -0600
1from rest_framework.mixins import CreateModelMixin as Create, ListModelMixin as List, RetrieveModelMixin as Detail
2from rest_framework.response import Response
3from rest_framework.viewsets import GenericViewSet
4from memberships.mixins import MemberMixin
5from organizations.mixins import OrganizationAdminMixin
6from .filters import PaymentFilter
7from .models import Payment
8from .pagination import PaymentPagination
9from .serializers import (
10 PaymentPolymorphicSerializer,
11 PaymentIntentSerializer,
12 MemberPaymentIntentSerializer,
13 ManualPaymentSerializer,
14 PaymentAllocationExportSerializer,
15)
18class BasePaymentViewSet(GenericViewSet, List, Detail):
19 """
20 Base ViewSet for Payments
21 """
23 pagination_class = PaymentPagination
24 filterset_class = PaymentFilter
25 search_fields = ["membership__name"]
26 serializer_class = PaymentPolymorphicSerializer
28 def get_paginated_response(self, data, filtered_queryset):
29 return self.paginator.get_paginated_response(data, filtered_queryset)
31 def list(self, request, *args, **kwargs):
32 queryset = self.filter_queryset(self.get_queryset())
34 page = self.paginate_queryset(queryset)
35 if page is not None: 35 ↛ 39line 35 didn't jump to line 39, because the condition on line 35 was never false
36 serializer = self.get_serializer(page, many=True)
37 return self.get_paginated_response(serializer.data, queryset)
39 serializer = self.get_serializer(queryset, many=True)
40 return Response(serializer.data)
43class PaymentViewSet(OrganizationAdminMixin, BasePaymentViewSet):
44 """
45 ViewSet for Payments
46 """
48 model = Payment
51class MemberPaymentViewSet(MemberMixin, BasePaymentViewSet):
52 """
53 ViewSet for Member Payments
54 """
56 model = Payment
59class PaymentIntentViewSet(OrganizationAdminMixin, GenericViewSet, Create):
60 """ViewSet for PaymentIntent"""
62 serializer_class = PaymentIntentSerializer
65class MemberPaymentIntentViewSet(MemberMixin, GenericViewSet, Create):
66 """ViewSet for Member PaymentIntent"""
68 serializer_class = MemberPaymentIntentSerializer
71class ManualPaymentViewSet(OrganizationAdminMixin, GenericViewSet, Create):
72 """ViewSet for ManualPayment"""
74 serializer_class = ManualPaymentSerializer
77class PaymentAllocationExportViewSet(OrganizationAdminMixin, GenericViewSet, Create):
78 """
79 ViewSet for PaymentAllocationExport
80 """
82 serializer_class = PaymentAllocationExportSerializer