From b1bb4ede3795181ea57663f5f479e80d5ba8efa6 Mon Sep 17 00:00:00 2001 From: Muhammad Arslan Date: Mon, 25 Nov 2024 18:23:38 +0500 Subject: [PATCH] feat(api): has_prerequisites field added in courses and programs API (#3306) New field has_prerequisites added in courses and programs API for MIT Learn --- courses/serializers.py | 22 ++++++++++++++++++++++ courses/serializers_test.py | 2 ++ 2 files changed, 24 insertions(+) diff --git a/courses/serializers.py b/courses/serializers.py index f2422ccd1..beff663a2 100644 --- a/courses/serializers.py +++ b/courses/serializers.py @@ -114,6 +114,16 @@ class CourseSerializer(serializers.ModelSerializer): platform = serializers.SerializerMethodField() marketing_hubspot_form_id = serializers.SerializerMethodField() availability = serializers.SerializerMethodField() + prerequisites = serializers.SerializerMethodField() + + def get_prerequisites(self, instance): # noqa: ARG002 + """Get course prerequisites""" + + # This is a hard coded value because the consumers of the API need this field. + # In an ideal situation the prerequisites could be list of courses. + # Since in xPRO we don't have support for prerequisites + # so we will not get/check for prerequisites + return [] def get_availability(self, instance): # noqa: ARG002 """Get course availability""" @@ -228,6 +238,7 @@ class Meta: "is_external", "platform", "availability", + "prerequisites", ] @@ -292,6 +303,16 @@ class ProgramSerializer(serializers.ModelSerializer): credits = serializers.SerializerMethodField() platform = serializers.SerializerMethodField() availability = serializers.SerializerMethodField() + prerequisites = serializers.SerializerMethodField() + + def get_prerequisites(self, instance): # noqa: ARG002 + """Get course prerequisites""" + + # This is a hard coded value because the consumers of the API need this field. + # In an ideal situation the prerequisites could be list of courses. + # Since in xPRO we don't have support for prerequisites + # so we will not get/check for prerequisites + return [] def get_availability(self, instance): # noqa: ARG002 """Get program availability""" @@ -433,6 +454,7 @@ class Meta: "is_external", "platform", "availability", + "prerequisites", ] diff --git a/courses/serializers_test.py b/courses/serializers_test.py index e88148053..8e711c914 100644 --- a/courses/serializers_test.py +++ b/courses/serializers_test.py @@ -162,6 +162,7 @@ def test_serialize_program( # noqa: PLR0913 "marketing_hubspot_form_id": marketing_hubspot_form_id, "platform": program.platform.name, "availability": "dated", + "prerequisites": [], }, ) assert data["end_date"] != non_live_run.end_date.strftime(datetime_millis_format) @@ -298,6 +299,7 @@ def test_serialize_course( # noqa: PLR0913 ), "platform": course.platform.name, "availability": "dated", + "prerequisites": [], }, )