Commit 7873d2d4 by Matthew Piatetsky

Expose course run seats on program endpoint

ECOM-7262
parent e7c67e1a
......@@ -383,6 +383,7 @@ class NestedProgramSerializer(serializers.ModelSerializer):
class MinimalCourseRunSerializer(TimestampModelSerializer):
image = ImageField(read_only=True, source='card_image_url')
marketing_url = serializers.SerializerMethodField()
seats = SeatSerializer(many=True)
@classmethod
def prefetch_queryset(cls):
......@@ -393,7 +394,7 @@ class MinimalCourseRunSerializer(TimestampModelSerializer):
class Meta:
model = CourseRun
fields = ('key', 'uuid', 'title', 'image', 'short_description', 'marketing_url',
fields = ('key', 'uuid', 'title', 'image', 'short_description', 'marketing_url', 'seats',
'start', 'end', 'enrollment_start', 'enrollment_end', 'pacing_type', 'type',)
def get_marketing_url(self, obj):
......
......@@ -318,6 +318,7 @@ class MinimalCourseRunSerializerTests(TestCase):
'enrollment_end': json_date_format(course_run.enrollment_end),
'pacing_type': course_run.pacing_type,
'type': course_run.type,
'seats': SeatSerializer(course_run.seats, many=True).data
}
def test_data(self):
......@@ -613,6 +614,37 @@ class MinimalProgramCourseSerializerTests(TestCase):
self.assertSequenceEqual(serializer.data, expected)
def test_use_full_course_serializer(self):
"""
Verify that we can use the `use_full_course_serializer` parameter to use the
CourseRun serializer.
"""
request = make_request()
course = CourseFactory()
program = ProgramFactory(courses=[course])
CourseRunFactory(course=course)
serializer_data = MinimalProgramCourseSerializer(
course,
context={
'request': request,
'program': program,
'use_full_course_serializer': 1,
'course_runs': list(program.course_runs),
}
).data
expected = CourseRunSerializer(
course.course_runs.all(),
many=True,
context={
'request': request,
'use_full_course_serializer': 1
}
).data
assert serializer_data['course_runs'] == expected
class MinimalProgramSerializerTests(TestCase):
serializer_class = MinimalProgramSerializer
......@@ -863,35 +895,6 @@ class ProgramSerializerTests(MinimalProgramSerializerTests):
expected = self.get_expected_data(program, request)
self.assertDictEqual(serializer.data, expected)
def test_use_full_course_serializer(self):
"""
Verify that we can use the `use_full_course_serializer` parameter to toggle the CourseRun
serializer used when returning program data.
"""
request = make_request()
program = self.create_program()
# Assert that the seats are not available when fetched without any flag
program_without_seats = self.serializer_class(program, context={'request': request}).data
course_run_without_seats = program_without_seats['courses'][0]['course_runs'][0]
assert 'seats' not in course_run_without_seats
# Assert that the seats are not available when fetched with the use_full_course_serializer param set to 0
program_without_seats = self.serializer_class(program, context={
'request': request,
'use_full_course_serializer': 0
}).data
course_run_without_seats = program_without_seats['courses'][0]['course_runs'][0]
assert 'seats' not in course_run_without_seats
# Assert that the seats are available when fetched with the use_full_course_serializer param set to 1
program_with_seats = self.serializer_class(
program,
context={'request': request, 'use_full_course_serializer': 1}
).data
course_run_with_seats = program_with_seats['courses'][0]['course_runs'][0]
assert 'seats' in course_run_with_seats
def test_marketable_enrollable_course_runs_with_archived(self):
""" Test that the marketable_enrollable_course_runs_with_archived flag hides course runs
that are not marketable or enrollable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment