Skip to content

Commit

Permalink
feat: add course_home_url to course_api (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanseto authored Oct 31, 2024
1 parent 74b58da commit 6092e30
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
9 changes: 9 additions & 0 deletions eox_nelp/course_api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rest_framework import serializers

from eox_nelp.edxapp_wrapper.course_api import CourseDetailSerializer
from eox_nelp.edxapp_wrapper.course_experience import course_home_url as retrieve_course_home_url


class NelpCourseDetailSerializer(CourseDetailSerializer): # pylint: disable=abstract-method
Expand Down Expand Up @@ -37,6 +38,14 @@ def get_course_about_url(self, course_overview):

return self.context["request"].build_absolute_uri(about_course_path)

course_home_url = serializers.SerializerMethodField()

def get_course_home_url(self, course_overview):
"""
Get the representation for SerializerMethodField `course_home_url`
"""
return retrieve_course_home_url(course_overview.id)

overview = serializers.SerializerMethodField()

def get_overview(self, course_overview):
Expand Down
5 changes: 4 additions & 1 deletion eox_nelp/course_api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rest_framework import status
from rest_framework.test import APIClient, APITestCase

from eox_nelp.edxapp_wrapper.course_experience import course_home_url
from eox_nelp.edxapp_wrapper.course_overviews import CourseOverview
from eox_nelp.edxapp_wrapper.test_backends.course_api_m_v1 import TEST_RAW_OVERVIEW

Expand Down Expand Up @@ -92,11 +93,13 @@ def test_get_nelp_courses_list(self):
"results": [
{
"course_about_url": f"http://testserver/courses/{self.BASE_COURSE_ID}1/about",
"course_home_url": course_home_url(f"{self.BASE_COURSE_ID}1"),
"overview": TEST_RAW_OVERVIEW,
"overview_object": self.expected_overview_object,
},
{
"course_about_url": f"http://testserver/courses/{self.BASE_COURSE_ID}2/about",
"course_home_url": course_home_url(f"{self.BASE_COURSE_ID}2"),
"overview": TEST_RAW_OVERVIEW,
"overview_object": self.expected_overview_object,
},
Expand All @@ -122,12 +125,12 @@ def test_get_nelp_course_detail(self):
url_endpoint = reverse(self.reverse_viewname_detail, kwargs=course_kwarg)
expected_value = {
"course_about_url": f"http://testserver/courses/{self.BASE_COURSE_ID}1/about",
"course_home_url": course_home_url(f"{self.BASE_COURSE_ID}1"),
"overview": TEST_RAW_OVERVIEW,
"overview_object": self.expected_overview_object,
}

response = self.client.get(url_endpoint)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn(response.headers["Content-Type"], self.RESPONSE_CONTENT_TYPES)
self.assertDictEqual(response.json(), expected_value)
14 changes: 14 additions & 0 deletions eox_nelp/edxapp_wrapper/backends/course_experience_p_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Backend for course_experience module.
This file contains all the necessary course_experience dependencies from
https://github.com/openedx/edx-platform/blob/open-release/palm.master/openedx/features/course_experience/
"""
from openedx.features.course_experience import course_home_url # pylint: disable=import-error


def get_course_home_url():
"""Allow to get the course_home_url function from
https://github.com/openedx/edx-platform/blob/open-release/palm.master/openedx/features/course_experience/__init__.py
Returns:
course_home_url function.
"""
return course_home_url
15 changes: 15 additions & 0 deletions eox_nelp/edxapp_wrapper/course_experience.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Wrapper course_experience.
This contains all the required dependencies from course_experience.
Attributes:
backend: Imported module by using the plugin settings.
course_experience: Module for openedx course_experience
"""

from importlib import import_module

from django.conf import settings

backend = import_module(settings.EOX_NELP_COURSE_EXPERIENCE_BACKEND)

course_home_url = backend.get_course_home_url()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Test backend for course_experience module."""


def get_course_home_url():
"""Return test function.
Returns:
string for testing basic home url
"""
return lambda course_key: f"http://testserver/learning/course/{course_key}/home"
1 change: 1 addition & 0 deletions eox_nelp/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def plugin_settings(settings):
settings.EOX_NELP_COURSE_BLOCKS_BACKEND = 'eox_nelp.edxapp_wrapper.backends.course_blocks_m_v1'
settings.EOX_NELP_COURSEWARE_BACKEND = 'eox_nelp.edxapp_wrapper.backends.courseware_m_v1'
settings.EOX_NELP_INSTRUCTOR_BACKEND = 'eox_nelp.edxapp_wrapper.backends.instructor_m_v1'
settings.EOX_NELP_COURSE_EXPERIENCE_BACKEND = 'eox_nelp.edxapp_wrapper.backends.course_experience_p_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 @@ -38,6 +38,7 @@ def plugin_settings(settings): # pylint: disable=function-redefined
settings.EOX_NELP_COURSE_BLOCKS_BACKEND = 'eox_nelp.edxapp_wrapper.test_backends.course_blocks_m_v1'
settings.EOX_NELP_COURSEWARE_BACKEND = "eox_nelp.edxapp_wrapper.test_backends.courseware_m_v1"
settings.EOX_NELP_INSTRUCTOR_BACKEND = "eox_nelp.edxapp_wrapper.test_backends.instructor_m_v1"
settings.EOX_NELP_COURSE_EXPERIENCE_BACKEND = "eox_nelp.edxapp_wrapper.test_backends.course_experience_p_v1"

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

0 comments on commit 6092e30

Please sign in to comment.