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
954f291a
Commit
954f291a
authored
Sep 16, 2016
by
Renzo Lucioni
Committed by
GitHub
Sep 16, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow intra-program course sorting to deal with runs missing start dates (#335)
ECOM-5668.
parent
67b1c404
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
course_discovery/apps/api/serializers.py
+6
-2
course_discovery/apps/api/tests/test_serializers.py
+40
-0
No files found.
course_discovery/apps/api/serializers.py
View file @
954f291a
...
...
@@ -459,10 +459,14 @@ class ProgramSerializer(serializers.ModelSerializer):
return
run
.
enrollment_start
or
min_datetime
def
min_run_start
(
course
):
# Course starts may be empty. Since this means the course can't be started, missing course
# start date is equivalent to (offset-aware) datetime.datetime.max.
max_datetime
=
datetime
.
datetime
.
max
.
replace
(
tzinfo
=
pytz
.
UTC
)
_course_runs
=
[
course_run
for
course_run
in
course_runs
if
course_run
.
course
==
course
]
run
=
min
(
_course_runs
,
key
=
lambda
run
:
run
.
start
)
run
=
min
(
_course_runs
,
key
=
lambda
run
:
run
.
start
or
max_datetime
)
return
run
.
start
return
run
.
start
or
max_datetime
courses
=
list
(
program
.
courses
.
all
())
courses
.
sort
(
key
=
min_run_enrollment_start
)
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
954f291a
...
...
@@ -502,6 +502,46 @@ class ProgramSerializerTests(TestCase):
self
.
assertEqual
(
serializer
.
data
[
'courses'
],
expected
)
def
test_course_ordering_with_no_start
(
self
):
"""
Verify that a courses run with missing start date appears last when ordering courses.
"""
request
=
make_request
()
course_list
=
CourseFactory
.
create_batch
(
3
)
# Create a course run with arbitrary start and empty enrollment_start.
CourseRunFactory
(
course
=
course_list
[
2
],
enrollment_start
=
None
,
start
=
datetime
(
2014
,
2
,
1
),
)
# Create a second run with matching start, but later enrollment_start.
CourseRunFactory
(
course
=
course_list
[
1
],
enrollment_start
=
datetime
(
2014
,
1
,
2
),
start
=
datetime
(
2014
,
2
,
1
),
)
# Create a third run with empty start and enrollment_start.
CourseRunFactory
(
course
=
course_list
[
0
],
enrollment_start
=
None
,
start
=
None
,
)
program
=
ProgramFactory
(
courses
=
course_list
)
serializer
=
ProgramSerializer
(
program
,
context
=
{
'request'
:
request
})
expected
=
ProgramCourseSerializer
(
# The expected ordering is the reverse of course_list.
course_list
[::
-
1
],
many
=
True
,
context
=
{
'request'
:
request
,
'program'
:
program
,
'course_runs'
:
program
.
course_runs
}
)
.
data
self
.
assertEqual
(
serializer
.
data
[
'courses'
],
expected
)
class
ContainedCourseRunsSerializerTests
(
TestCase
):
def
test_data
(
self
):
...
...
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