Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace generic list create api view with generic viewset a… #199

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions eox_nelp/pearson_vue/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- revokeResult: Endpoint for revoking a result.
- unrevokeResult: Endpoint for unrevoking a result.
"""
from django.urls import path
from rest_framework.routers import DefaultRouter

from eox_nelp.pearson_vue.api.v1.views import (
CancelAppointmentView,
Expand All @@ -38,13 +38,14 @@

app_name = "eox_nelp" # pylint: disable=invalid-name

urlpatterns = [
path('resultNotification/', ResultNotificationView.as_view(), name=RESULT_NOTIFICATION),
path('placeHold/', PlaceHoldView.as_view(), name=PLACE_HOLD),
path('releaseHold/', ReleaseHoldView.as_view(), name=RELEASE_HOLD),
path('modifyResultStatus/', ModifyResultStatusView.as_view(), name=MODIFY_RESULT_STATUS),
path('revokeResult/', RevokeResultView.as_view(), name=REVOKE_RESULT),
path('unrevokeResult/', UnrevokeResultView.as_view(), name=UNREVOKE_RESULT),
path('modifyAppointment/', ModifyAppointmentView.as_view(), name=MODIFY_APPOINTMENT),
path('cancelAppointment/', CancelAppointmentView.as_view(), name=CANCEL_APPOINTMENT),
]
router = DefaultRouter()
router.register('resultNotification', ResultNotificationView, basename=RESULT_NOTIFICATION)
router.register('placeHold', PlaceHoldView, basename=PLACE_HOLD)
router.register('releaseHold', ReleaseHoldView, basename=RELEASE_HOLD)
router.register('modifyResultStatus', ModifyResultStatusView, basename=MODIFY_RESULT_STATUS)
router.register('revokeResult', RevokeResultView, basename=REVOKE_RESULT)
router.register('unrevokeResult', UnrevokeResultView, basename=UNREVOKE_RESULT)
router.register('modifyAppointment', ModifyAppointmentView, basename=MODIFY_APPOINTMENT)
router.register('cancelAppointment', CancelAppointmentView, basename=CANCEL_APPOINTMENT)

urlpatterns = router.urls
17 changes: 10 additions & 7 deletions eox_nelp/pearson_vue/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
from django.http import Http404
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from eox_core.edxapp_wrapper.bearer_authentication import BearerAuthentication
from rest_framework import generics, status
from rest_framework import status
from rest_framework.mixins import CreateModelMixin, ListModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from eox_nelp.edxapp_wrapper.student import AnonymousUserId
from eox_nelp.pearson_vue.api.v1.serializers import PearsonRTENSerializer
Expand All @@ -39,7 +41,7 @@
from eox_nelp.pearson_vue.rti_backend import ResultNotificationBackend


class PearsonRTENBaseView(generics.ListCreateAPIView):
class PearsonRTENBaseView(CreateModelMixin, ListModelMixin, GenericViewSet):
"""
Base view for Pearson RTEN (Real Time Event Notification) API endpoints.

Expand Down Expand Up @@ -124,11 +126,12 @@ def create(self, request, *args, **kwargs):
Returns:
Response: Response object with status code 201 and an empty dictionary.
"""
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response({}, status=status.HTTP_200_OK, headers=headers)
response = super().create(request, *args, **kwargs)

if response.status_code == status.HTTP_201_CREATED:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so crazy, chaging normal status codes. But we depends on client logic 201 ->200

return Response({}, status=status.HTTP_200_OK, headers=response.headers)

return response

def get_candidate(self):
"""
Expand Down
14 changes: 7 additions & 7 deletions eox_nelp/pearson_vue/tests/api/v1/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_create_result_notification_event(self, enrollment_from_id_mock):
AnonymousUserId.objects.get.return_value.user = self.user

response = self.client.post(
reverse(f"pearson-vue-api:v1:{self.event_type}"),
reverse(f"pearson-vue-api:v1:{self.event_type}-list"),
{
"clientCandidateID": "NELC123456",
"authorization": {
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_create_result_notification_event_without_user(self):
AnonymousUserId.DoesNotExist = ObjectDoesNotExist
AnonymousUserId.objects.get.side_effect = AnonymousUserId.DoesNotExist

response = self.client.post(reverse(f"pearson-vue-api:v1:{self.event_type}"), {}, format="json")
response = self.client.post(reverse(f"pearson-vue-api:v1:{self.event_type}-list"), {}, format="json")

final_count = PearsonRTENEvent.objects.filter(event_type=self.event_type, candidate=None).count()

Expand Down Expand Up @@ -151,7 +151,7 @@ def test_create_result_notification_event_with_invalid_authorization_id(self, en
enrollment_from_id_mock.return_value = {}

response = self.client.post(
reverse(f"pearson-vue-api:v1:{self.event_type}"),
reverse(f"pearson-vue-api:v1:{self.event_type}-list"),
{"authorization": {"clientAuthorizationID": "1584-4785"}},
format="json",
)
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_get_event(self):
'created_at': event.created_at.isoformat(),
})

response = self.client.get(reverse(f"pearson-vue-api:v1:{self.event_type}"), format="json")
response = self.client.get(reverse(f"pearson-vue-api:v1:{self.event_type}-list"), format="json")

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], len(events))
Expand All @@ -201,7 +201,7 @@ def test_create_result_notification_event_disabled(self):
"""
initial_count = PearsonRTENEvent.objects.filter(event_type=self.event_type).count() # pylint: disable=no-member

response = self.client.post(reverse(f"pearson-vue-api:v1:{self.event_type}"), {}, format="json")
response = self.client.post(reverse(f"pearson-vue-api:v1:{self.event_type}-list"), {}, format="json")

final_count = PearsonRTENEvent.objects.filter(event_type=self.event_type).count() # pylint: disable=no-member

Expand All @@ -216,7 +216,7 @@ def test_get_event_disabled(self):
Expected behavior:
- Response returns a 404 status code.
"""
response = self.client.get(reverse(f"pearson-vue-api:v1:{self.event_type}"), format="json")
response = self.client.get(reverse(f"pearson-vue-api:v1:{self.event_type}-list"), format="json")

self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

Expand Down Expand Up @@ -253,7 +253,7 @@ def test_pipeline_execution(self, result_notification_mock):
}
}

response = self.client.post(reverse(f"pearson-vue-api:v1:{self.event_type}"), payload, format="json")
response = self.client.post(reverse(f"pearson-vue-api:v1:{self.event_type}-list"), payload, format="json")

final_count = PearsonRTENEvent.objects.filter(event_type=self.event_type).count()

Expand Down
Loading