Skip to content

Commit

Permalink
Merge pull request #103 from eduNEXT/jlc/add-courseRunViewSetWrapper
Browse files Browse the repository at this point in the history
Jlc/add course run view set wrapper
  • Loading branch information
johanseto authored Oct 30, 2023
2 parents 6f833fd + dc10d4a commit f195d6e
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 1 deletion.
Empty file added eox_nelp/cms/__init__.py
Empty file.
Empty file added eox_nelp/cms/api/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions eox_nelp/cms/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""eox_nelp cms api urls
"""
from django.urls import include, path

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

urlpatterns = [ # pylint: disable=invalid-name
path("v1/", include("eox_nelp.cms.api.v1.urls", namespace="v1"))
]
Empty file added eox_nelp/cms/api/v1/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions eox_nelp/cms/api/v1/routers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Routes configuration for cms api views."""
from rest_framework import routers

from .views import NelpCourseRunViewSet

router = routers.DefaultRouter()
router.register(r'course_runs', NelpCourseRunViewSet, basename='course_run')
Empty file.
53 changes: 53 additions & 0 deletions eox_nelp/cms/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Test views file.
"""

from django.test import TestCase, override_settings
from rest_framework import status

from eox_nelp.edxapp_wrapper.test_backends.cms_api_m_v1 import COURSE_RUN_TEST_RESPONSE


@override_settings(ROOT_URLCONF="eox_nelp.cms_urls")
class CMSApiRouterView(TestCase):
"""
Test for cms api Router view.
"""

def test_view_api_router(self):
"""
For the studio urls.
Check the `/api/v1/` endpoint works for cms.
Expected behavior:
- Status code 200.
- Return expected data.
"""
api_url = "/api/v1/"
expected_data = {"course_runs": "http://testserver/api/v1/course_runs/"}

response = self.client.get(api_url)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(response.json(), expected_data)


@override_settings(ROOT_URLCONF="eox_nelp.cms_urls")
class CMSCourseRunView(TestCase):
"""
Test for cms Course Run view.
"""

def test_course_run_view(self):
"""
Check the `/api/v1/course_runs` endpoint works for cms.
Expected behavior:
- Status code 200.
- Return expected data.
"""
api_url = "/api/v1/course_runs/"
expected_data = COURSE_RUN_TEST_RESPONSE

response = self.client.get(api_url)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(response.json(), expected_data)
6 changes: 6 additions & 0 deletions eox_nelp/cms/api/v1/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""eox_nelp cms_api v1 urls
"""
from eox_nelp.cms.api.v1.routers import router

app_name = "eox_nelp" # pylint: disable=invalid-name
urlpatterns = router.urls
12 changes: 12 additions & 0 deletions eox_nelp/cms/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
CMS API v1 Views
"""
from eox_nelp.edxapp_wrapper.cms_api import CourseRunViewSet


class NelpCourseRunViewSet(CourseRunViewSet):
"""
Nelp version(flavour) of CourseRun Api View.
To got it you could use the following path.
{studio_url}/eox-nelp/api/v1/course_runs/
"""
4 changes: 3 additions & 1 deletion eox_nelp/cms_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
1. Import the include() function: from django.conf.urls import path, include
2. Add a URL to urlpatterns: path(r'^blog/', include('blog.urls'))
"""
from django.urls import path
from django.urls import include, path

from eox_nelp import views

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

urlpatterns = [ # pylint: disable=invalid-name
path('eox-info/', views.info_view, name='eox-info'),
path('api/', include('eox_nelp.cms.api.urls', namespace='cms-api')),

]
16 changes: 16 additions & 0 deletions eox_nelp/edxapp_wrapper/backends/cms_api_m_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Backend for cms api v1 views.
This file contains all the necessary dependencies from
https://github.com/openedx/edx-platform/blob/open-release/maple.master/cms/djangoapps/api/v1/views/course_runs.py
"""
from cms.djangoapps.api.v1.views.course_runs import CourseRunViewSet


def get_course_runs_view():
"""Allow to get the course runs cms view class from
https://github.com/openedx/edx-platform/blob/open-release/maple.master/cms/djangoapps/api/v1/views/course_runs.py
Returns:
CourseRunViewSet view.
"""
return CourseRunViewSet
15 changes: 15 additions & 0 deletions eox_nelp/edxapp_wrapper/cms_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Wrapper of cms api.
This contains imports of modules from djangoapp cms/api/
Attributes:
cms_api: Imported CMS api module by using the plugin settings.
CourseRunViewSet: Wrapper cms course_run api view class.
"""
from importlib import import_module

from django.conf import settings

cms_api = import_module(settings.EOX_NELP_CMS_API_BACKEND)

CourseRunViewSet = cms_api.get_course_runs_view()
59 changes: 59 additions & 0 deletions eox_nelp/edxapp_wrapper/test_backends/cms_api_m_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Backend test abstraction."""
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

COURSE_RUN_TEST_RESPONSE = {
"next": "http://testserver/eox-nelp/api/v1/course_runs/?page=2",
"previous": None,
"count": 2,
"num_pages": 2,
"current_page": 1,
"start": 0,
"results": [
{
"schedule": {
"start": "2033-02-02T00:00:00Z",
"end": None,
"enrollment_start": "2023-01-30T00:00:00Z",
"enrollment_end": None,
},
"pacing_type": "instructor_paced",
"team": [{"user": "vader", "role": "instructor"}, {"user": "vader", "role": "staff"}],
"id": "course-v1:edX+cd101+2023-t2",
"title": "PROCEDURAL SEDATION AND ANALGESIA COURSE",
"images": {
"card_image": "http://testserver/asset-v1:edX+cd101+2023-t2+type@asset+block@images_course_image.jpg",
},
},
{
"schedule": {
"start": "2022-10-19T00:00:00Z",
"end": "2022-10-31T00:00:00Z",
"enrollment_start": "2022-10-01T00:00:00Z",
"enrollment_end": "2022-10-17T00:00:00Z",
},
"pacing_type": "instructor_paced",
"team": [{"user": "vader", "role": "instructor"}, {"user": "vader", "role": "staff"}],
"id": "course-v1:edX+completion+2023",
"title": "Course test h",
"images": {
"card_image": "http://testserver/asset-v1:edX+completion+2023+type@[email protected]",
},
},
],
}


def get_course_runs_view():
"""Return test class.
Returns:
TestCourseRunViewSet class.
"""
return TestCourseRunsViewSet


class TestCourseRunsViewSet(GenericViewSet):
"""Test version of CourseRunViewSet."""

def list(self, request, *args, **kwargs): # pylint: disable=unused-argument
return Response(COURSE_RUN_TEST_RESPONSE)
1 change: 1 addition & 0 deletions eox_nelp/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def plugin_settings(settings):
settings.EOX_NELP_EDXMAKO_BACKEND = 'eox_nelp.edxapp_wrapper.backends.edxmako_m_v1'
settings.EOX_NELP_BRANDING_BACKEND = 'eox_nelp.edxapp_wrapper.backends.branding_m_v1'
settings.EOX_NELP_CERTIFICATES_BACKEND = 'eox_nelp.edxapp_wrapper.backends.certificates_m_v1'
settings.EOX_NELP_CMS_API_BACKEND = 'eox_nelp.edxapp_wrapper.backends.cms_api_m_v1'

settings.FUTUREX_API_URL = 'https://testing-site.com'
settings.FUTUREX_API_CLIENT_ID = 'my-test-client-id'
Expand Down
1 change: 1 addition & 0 deletions eox_nelp/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def plugin_settings(settings): # pylint: disable=function-redefined
settings.EOX_NELP_EDXMAKO_BACKEND = 'eox_nelp.edxapp_wrapper.test_backends.edxmako_m_v1'
settings.EOX_NELP_BRANDING_BACKEND = 'eox_nelp.edxapp_wrapper.test_backends.branding_m_v1'
settings.EOX_NELP_CERTIFICATES_BACKEND = 'eox_nelp.edxapp_wrapper.test_backends.certificates_m_v1'
settings.EOX_NELP_CMS_API_BACKEND = 'eox_nelp.edxapp_wrapper.test_backends.cms_api_m_v1'

settings.FUTUREX_API_URL = 'https://testing.com'
settings.FUTUREX_API_CLIENT_ID = 'my-test-client-id'
Expand Down

0 comments on commit f195d6e

Please sign in to comment.