Skip to content

Commit

Permalink
feat: complete test for the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
johanseto committed Oct 26, 2023
1 parent d44a50b commit 49b6209
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 8 deletions.
38 changes: 33 additions & 5 deletions eox_nelp/cms/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,49 @@
from django.test import TestCase, override_settings
from rest_framework import status

from eox_nelp.edxapp_wrapper.test_backends.cms_api_views_m_v1 import COURSE_RUN_TEST_RESPONSE

@override_settings(ROOT_URLCONF='eox_nelp.cms_urls')

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

def test_view_api_router(self):
"""
For the studio urls.
Check the /api/v1/ endpoint works for cms.
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.
"""
routes_api_url = "/api/v1/"
api_url = "/api/v1/course_runs/"
expected_data = COURSE_RUN_TEST_RESPONSE

response = self.client.get(routes_api_url)
response = self.client.get(api_url)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(response.json(), expected_data)
1 change: 0 additions & 1 deletion eox_nelp/cms/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ class NelpCourseRunViewSet(CourseRunViewSet):
"""
Nelp version(flavour) of CourseRun Api View.
"""
pass
55 changes: 53 additions & 2 deletions eox_nelp/edxapp_wrapper/test_backends/cms_api_views_m_v1.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,61 @@
"""Backend test abstraction."""
from rest_framework.response import Response

from eox_nelp.edxapp_wrapper.test_backends import DummyViewset


def get_course_run_view():
"""Return test class.
Returns:
Mock class.
TestCourseRunViewSet class.
"""
return DummyViewset
return TestCourseRunViewSet


class TestCourseRunViewSet(DummyViewset):
"""Test version of course Run viewset"""

def list(self, request, *args, **kwargs): # lint-amnesty, pylint: disable=unused-argument
return Response(COURSE_RUN_TEST_RESPONSE)


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]"
},
},
],
}

0 comments on commit 49b6209

Please sign in to comment.