Coverage for payments/views.py: 94%

36 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -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) 

16 

17 

18class BasePaymentViewSet(GenericViewSet, List, Detail): 

19 """ 

20 Base ViewSet for Payments 

21 """ 

22 

23 pagination_class = PaymentPagination 

24 filterset_class = PaymentFilter 

25 search_fields = ["membership__name"] 

26 serializer_class = PaymentPolymorphicSerializer 

27 

28 def get_paginated_response(self, data, filtered_queryset): 

29 return self.paginator.get_paginated_response(data, filtered_queryset) 

30 

31 def list(self, request, *args, **kwargs): 

32 queryset = self.filter_queryset(self.get_queryset()) 

33 

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) 

38 

39 serializer = self.get_serializer(queryset, many=True) 

40 return Response(serializer.data) 

41 

42 

43class PaymentViewSet(OrganizationAdminMixin, BasePaymentViewSet): 

44 """ 

45 ViewSet for Payments 

46 """ 

47 

48 model = Payment 

49 

50 

51class MemberPaymentViewSet(MemberMixin, BasePaymentViewSet): 

52 """ 

53 ViewSet for Member Payments 

54 """ 

55 

56 model = Payment 

57 

58 

59class PaymentIntentViewSet(OrganizationAdminMixin, GenericViewSet, Create): 

60 """ViewSet for PaymentIntent""" 

61 

62 serializer_class = PaymentIntentSerializer 

63 

64 

65class MemberPaymentIntentViewSet(MemberMixin, GenericViewSet, Create): 

66 """ViewSet for Member PaymentIntent""" 

67 

68 serializer_class = MemberPaymentIntentSerializer 

69 

70 

71class ManualPaymentViewSet(OrganizationAdminMixin, GenericViewSet, Create): 

72 """ViewSet for ManualPayment""" 

73 

74 serializer_class = ManualPaymentSerializer 

75 

76 

77class PaymentAllocationExportViewSet(OrganizationAdminMixin, GenericViewSet, Create): 

78 """ 

79 ViewSet for PaymentAllocationExport 

80 """ 

81 

82 serializer_class = PaymentAllocationExportSerializer