-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from eduNEXT/jlc/add-courseRunViewSetWrapper
Jlc/add course run view set wrapper
- Loading branch information
Showing
15 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters