Skip to content

Commit

Permalink
feat: add course and program availability in APIs (#3094)
Browse files Browse the repository at this point in the history
* feat: add course and program availability

* fix tests

* fix typo program
  • Loading branch information
arslanashraf7 authored Aug 8, 2024
1 parent 23e7e54 commit 4488976
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 @@ -113,6 +113,16 @@ class CourseSerializer(serializers.ModelSerializer):
credits = serializers.SerializerMethodField()
platform = serializers.SerializerMethodField()
marketing_hubspot_form_id = serializers.SerializerMethodField()
availability = serializers.SerializerMethodField()

def get_availability(self, instance): # noqa: ARG002
"""Get course availability"""

# This is a hard coded value because the consumers of the API need this field.
# In an ideal situation the availability could be "dated" or "anytime".
# Since all the courses in xPRO are dated so we will not check for "self paced"
# courses to determine if the course could be "anytime"
return "dated"

def get_url(self, instance):
"""Get CMS Page URL for the course"""
Expand Down Expand Up @@ -217,6 +227,7 @@ class Meta:
"credits",
"is_external",
"platform",
"availability",
]


Expand Down Expand Up @@ -280,6 +291,16 @@ class ProgramSerializer(serializers.ModelSerializer):
video_url = serializers.SerializerMethodField()
credits = serializers.SerializerMethodField()
platform = serializers.SerializerMethodField()
availability = serializers.SerializerMethodField()

def get_availability(self, instance): # noqa: ARG002
"""Get program availability"""

# This is a hard coded value because the consumers of the API need this field.
# In an ideal situation the availability could be "dated" or "anytime".
# Since all the programs in xPRO are dated so we will not check for "self paced"
# courses to determine if the course could be "anytime"
return "dated"

def get_courses(self, instance):
"""Serializer for courses"""
Expand Down Expand Up @@ -411,6 +432,7 @@ class Meta:
"credits",
"is_external",
"platform",
"availability",
]


Expand Down
2 changes: 2 additions & 0 deletions courses/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def test_serialize_program( # noqa: PLR0913
"external_marketing_url": external_marketing_url,
"marketing_hubspot_form_id": marketing_hubspot_form_id,
"platform": program.platform.name,
"availability": "dated",
},
)
assert data["end_date"] != non_live_run.end_date.strftime(datetime_format)
Expand Down Expand Up @@ -296,6 +297,7 @@ def test_serialize_course( # noqa: PLR0913
marketing_hubspot_form_id if course_page else None
),
"platform": course.platform.name,
"availability": "dated",
},
)

Expand Down

0 comments on commit 4488976

Please sign in to comment.