Skip to content

Commit

Permalink
feat(api): has_prerequisites field added in courses and programs API (#…
Browse files Browse the repository at this point in the history
…3306)

New field has_prerequisites added in courses and programs API for MIT Learn
  • Loading branch information
marslanabdulrauf authored Nov 25, 2024
1 parent eb32d8d commit b1bb4ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions courses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -228,6 +238,7 @@ class Meta:
"is_external",
"platform",
"availability",
"prerequisites",
]


Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -433,6 +454,7 @@ class Meta:
"is_external",
"platform",
"availability",
"prerequisites",
]


Expand Down
2 changes: 2 additions & 0 deletions courses/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -298,6 +299,7 @@ def test_serialize_course( # noqa: PLR0913
),
"platform": course.platform.name,
"availability": "dated",
"prerequisites": [],
},
)

Expand Down

0 comments on commit b1bb4ed

Please sign in to comment.