Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
7873d2d4
Commit
7873d2d4
authored
Mar 09, 2017
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose course run seats on program endpoint
ECOM-7262
parent
e7c67e1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
30 deletions
+34
-30
course_discovery/apps/api/serializers.py
+2
-1
course_discovery/apps/api/tests/test_serializers.py
+32
-29
No files found.
course_discovery/apps/api/serializers.py
View file @
7873d2d4
...
@@ -383,6 +383,7 @@ class NestedProgramSerializer(serializers.ModelSerializer):
...
@@ -383,6 +383,7 @@ class NestedProgramSerializer(serializers.ModelSerializer):
class
MinimalCourseRunSerializer
(
TimestampModelSerializer
):
class
MinimalCourseRunSerializer
(
TimestampModelSerializer
):
image
=
ImageField
(
read_only
=
True
,
source
=
'card_image_url'
)
image
=
ImageField
(
read_only
=
True
,
source
=
'card_image_url'
)
marketing_url
=
serializers
.
SerializerMethodField
()
marketing_url
=
serializers
.
SerializerMethodField
()
seats
=
SeatSerializer
(
many
=
True
)
@classmethod
@classmethod
def
prefetch_queryset
(
cls
):
def
prefetch_queryset
(
cls
):
...
@@ -393,7 +394,7 @@ class MinimalCourseRunSerializer(TimestampModelSerializer):
...
@@ -393,7 +394,7 @@ class MinimalCourseRunSerializer(TimestampModelSerializer):
class
Meta
:
class
Meta
:
model
=
CourseRun
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'
,)
'start'
,
'end'
,
'enrollment_start'
,
'enrollment_end'
,
'pacing_type'
,
'type'
,)
def
get_marketing_url
(
self
,
obj
):
def
get_marketing_url
(
self
,
obj
):
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
7873d2d4
...
@@ -318,6 +318,7 @@ class MinimalCourseRunSerializerTests(TestCase):
...
@@ -318,6 +318,7 @@ class MinimalCourseRunSerializerTests(TestCase):
'enrollment_end'
:
json_date_format
(
course_run
.
enrollment_end
),
'enrollment_end'
:
json_date_format
(
course_run
.
enrollment_end
),
'pacing_type'
:
course_run
.
pacing_type
,
'pacing_type'
:
course_run
.
pacing_type
,
'type'
:
course_run
.
type
,
'type'
:
course_run
.
type
,
'seats'
:
SeatSerializer
(
course_run
.
seats
,
many
=
True
)
.
data
}
}
def
test_data
(
self
):
def
test_data
(
self
):
...
@@ -613,6 +614,37 @@ class MinimalProgramCourseSerializerTests(TestCase):
...
@@ -613,6 +614,37 @@ class MinimalProgramCourseSerializerTests(TestCase):
self
.
assertSequenceEqual
(
serializer
.
data
,
expected
)
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
):
class
MinimalProgramSerializerTests
(
TestCase
):
serializer_class
=
MinimalProgramSerializer
serializer_class
=
MinimalProgramSerializer
...
@@ -863,35 +895,6 @@ class ProgramSerializerTests(MinimalProgramSerializerTests):
...
@@ -863,35 +895,6 @@ class ProgramSerializerTests(MinimalProgramSerializerTests):
expected
=
self
.
get_expected_data
(
program
,
request
)
expected
=
self
.
get_expected_data
(
program
,
request
)
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
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
):
def
test_marketable_enrollable_course_runs_with_archived
(
self
):
""" Test that the marketable_enrollable_course_runs_with_archived flag hides course runs
""" Test that the marketable_enrollable_course_runs_with_archived flag hides course runs
that are not marketable or enrollable
that are not marketable or enrollable
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment