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
03ce0529
Commit
03ce0529
authored
Oct 18, 2016
by
Simon Chen
Committed by
Mike Dikan
Oct 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deleted program types from the course_run search endpoint
ECOM-5729
parent
60cf03a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
4 deletions
+45
-4
course_discovery/apps/api/v1/tests/test_views/test_search.py
+31
-0
course_discovery/apps/course_metadata/models.py
+6
-2
course_discovery/apps/course_metadata/tests/test_models.py
+8
-2
No files found.
course_discovery/apps/api/v1/tests/test_views/test_search.py
View file @
03ce0529
...
...
@@ -171,6 +171,37 @@ class CourseRunSearchViewSetTests(DefaultPartnerMixin, SerializationMixin, Login
}
self
.
assertDictContainsSubset
(
expected
,
response_data
[
'queries'
])
def
test_exclude_deleted_program_types
(
self
):
""" Verify the deleted programs do not show in the program_types representation. """
self
.
_test_exclude_program_types
(
ProgramStatus
.
Deleted
)
def
test_exclude_unpublished_program_types
(
self
):
""" Verify the unpublished programs do not show in the program_types representation. """
self
.
_test_exclude_program_types
(
ProgramStatus
.
Unpublished
)
def
_test_exclude_program_types
(
self
,
program_status
):
""" Verify that programs with the provided type do not show in the program_types representation. """
course_run
=
CourseRunFactory
(
course__partner
=
self
.
partner
,
course__title
=
'Software Testing'
,
status
=
CourseRunStatus
.
Published
)
active_program
=
ProgramFactory
(
courses
=
[
course_run
.
course
],
status
=
ProgramStatus
.
Active
)
ProgramFactory
(
courses
=
[
course_run
.
course
],
status
=
program_status
)
with
self
.
assertNumQueries
(
11
):
response
=
self
.
get_search_response
(
'software'
,
faceted
=
False
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
# Validate the search results
expected
=
{
'count'
:
1
,
'results'
:
[
self
.
serialize_course_run
(
course_run
)
]
}
self
.
assertDictContainsSubset
(
expected
,
response_data
)
self
.
assertEqual
(
response_data
[
'results'
][
0
]
.
get
(
'program_types'
),
[
active_program
.
type
.
name
])
class
AggregateSearchViewSet
(
DefaultPartnerMixin
,
SerializationMixin
,
LoginMixin
,
ElasticsearchTestMixin
,
APITestCase
):
path
=
reverse
(
'api:v1:search-all-facets'
)
...
...
course_discovery/apps/course_metadata/models.py
View file @
03ce0529
...
...
@@ -366,8 +366,12 @@ class CourseRun(TimeStampedModel):
@property
def
program_types
(
self
):
# Exclude unpublished programs from list so we don't identify that program type if not available
all_programs
=
[
program
for
program
in
self
.
programs
.
all
()
if
program
.
status
!=
ProgramStatus
.
Unpublished
]
"""
Exclude unpublished and deleted programs from list
so we don't identify that program type if not available
"""
program_statuses_to_exclude
=
(
ProgramStatus
.
Unpublished
,
ProgramStatus
.
Deleted
)
all_programs
=
[
program
for
program
in
self
.
programs
.
exclude
(
status__in
=
program_statuses_to_exclude
)]
return
[
program
.
type
.
name
for
program
in
all_programs
]
@property
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
03ce0529
...
...
@@ -167,8 +167,14 @@ class CourseRunTests(TestCase):
""" Verify the property exludes program types that are unpublished. """
courses
=
[
self
.
course_run
.
course
]
program
=
factories
.
ProgramFactory
(
courses
=
courses
)
other_program
=
factories
.
ProgramFactory
(
courses
=
courses
,
status
=
ProgramStatus
.
Unpublished
)
self
.
assertCountEqual
(
self
.
course_run
.
program_types
,
[
program
.
type
.
name
])
factories
.
ProgramFactory
(
courses
=
courses
,
status
=
ProgramStatus
.
Unpublished
)
self
.
assertEqual
(
self
.
course_run
.
program_types
,
[
program
.
type
.
name
])
def
test_exclude_deleted_program_types
(
self
):
""" Verify the program types property exclude programs that are deleted """
active_program
=
factories
.
ProgramFactory
(
courses
=
[
self
.
course_run
.
course
])
factories
.
ProgramFactory
(
courses
=
[
self
.
course_run
.
course
],
status
=
ProgramStatus
.
Deleted
)
self
.
assertEqual
(
self
.
course_run
.
program_types
,
[
active_program
.
type
.
name
])
class
OrganizationTests
(
TestCase
):
...
...
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