Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
99957168
Commit
99957168
authored
Jun 06, 2017
by
Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exclude hidden programs from white label course and homepage
LEARNER-1126, LEARNER-1127
parent
c03cd599
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
8 deletions
+66
-8
common/djangoapps/student/views.py
+1
-1
lms/djangoapps/courseware/views/views.py
+1
-1
openedx/core/djangoapps/catalog/tests/factories.py
+1
-0
openedx/core/djangoapps/catalog/tests/test_utils.py
+56
-4
openedx/core/djangoapps/catalog/utils.py
+7
-2
No files found.
common/djangoapps/student/views.py
View file @
99957168
...
...
@@ -216,7 +216,7 @@ def index(request, extra_context=None, user=AnonymousUser()):
# Do not add programs to the context if there are no program types enabled for the site.
if
program_types
:
programs_list
=
get_programs_with_type
(
program_types
)
programs_list
=
get_programs_with_type
(
program_types
,
include_hidden
=
False
)
context
[
"programs_list"
]
=
programs_list
...
...
lms/djangoapps/courseware/views/views.py
View file @
99957168
...
...
@@ -167,7 +167,7 @@ def courses(request):
# Do not add programs to the context if there are no program types enabled for the site.
if
program_types
:
programs_list
=
get_programs_with_type
(
program_types
)
programs_list
=
get_programs_with_type
(
program_types
,
include_hidden
=
False
)
return
render_to_response
(
"courseware/courses.html"
,
...
...
openedx/core/djangoapps/catalog/tests/factories.py
View file @
99957168
...
...
@@ -125,6 +125,7 @@ class ProgramFactory(DictFactoryBase):
title
=
factory
.
Faker
(
'catch_phrase'
)
type
=
factory
.
Faker
(
'word'
)
uuid
=
factory
.
Faker
(
'uuid4'
)
hidden
=
False
class
ProgramTypeFactory
(
DictFactoryBase
):
...
...
openedx/core/djangoapps/catalog/tests/test_utils.py
View file @
99957168
...
...
@@ -3,6 +3,7 @@
import
copy
import
uuid
import
ddt
import
mock
from
django.contrib.auth
import
get_user_model
from
django.core.cache
import
cache
...
...
@@ -13,15 +14,14 @@ from openedx.core.djangoapps.catalog.models import CatalogIntegration
from
openedx.core.djangoapps.catalog.tests.factories
import
CourseRunFactory
,
ProgramFactory
,
ProgramTypeFactory
from
openedx.core.djangoapps.catalog.tests.mixins
import
CatalogIntegrationMixin
from
openedx.core.djangoapps.catalog.utils
import
(
get_programs
,
get_program_types
,
get_programs_with_type
,
get_course_runs
,
get_program_types
,
get_programs
,
get_programs_with_type
)
from
openedx.core.djangolib.testing.utils
import
CacheIsolationTestCase
,
skip_unless_lms
from
student.tests.factories
import
UserFactory
UTILS_MODULE
=
'openedx.core.djangoapps.catalog.utils'
User
=
get_user_model
()
# pylint: disable=invalid-name
...
...
@@ -154,6 +154,58 @@ class TestGetPrograms(CacheIsolationTestCase):
@skip_unless_lms
@ddt.ddt
class
TestGetProgramsWithType
(
TestCase
):
@mock.patch
(
UTILS_MODULE
+
'.get_programs'
)
@mock.patch
(
UTILS_MODULE
+
'.get_program_types'
)
def
test_get_programs_with_type
(
self
,
mock_get_program_types
,
mock_get_programs
):
"""Verify get_programs_with_type returns the expected list of programs."""
programs_with_program_type
=
[]
programs
=
ProgramFactory
.
create_batch
(
2
)
program_types
=
[]
for
program
in
programs
:
program_type
=
ProgramTypeFactory
(
name
=
program
[
'type'
])
program_types
.
append
(
program_type
)
program_with_type
=
copy
.
deepcopy
(
program
)
program_with_type
[
'type'
]
=
program_type
programs_with_program_type
.
append
(
program_with_type
)
mock_get_programs
.
return_value
=
programs
mock_get_program_types
.
return_value
=
program_types
actual
=
get_programs_with_type
()
self
.
assertEqual
(
actual
,
programs_with_program_type
)
@ddt.data
(
False
,
True
)
@mock.patch
(
UTILS_MODULE
+
'.get_programs'
)
@mock.patch
(
UTILS_MODULE
+
'.get_program_types'
)
def
test_get_programs_with_type_include_hidden
(
self
,
include_hidden
,
mock_get_program_types
,
mock_get_programs
):
"""Verify get_programs_with_type returns the expected list of programs with include_hidden parameter."""
programs_with_program_type
=
[]
programs
=
[
ProgramFactory
(
hidden
=
False
),
ProgramFactory
(
hidden
=
True
)]
program_types
=
[]
for
program
in
programs
:
if
program
[
'hidden'
]
and
not
include_hidden
:
continue
program_type
=
ProgramTypeFactory
(
name
=
program
[
'type'
])
program_types
.
append
(
program_type
)
program_with_type
=
copy
.
deepcopy
(
program
)
program_with_type
[
'type'
]
=
program_type
programs_with_program_type
.
append
(
program_with_type
)
mock_get_programs
.
return_value
=
programs
mock_get_program_types
.
return_value
=
program_types
actual
=
get_programs_with_type
(
include_hidden
=
include_hidden
)
self
.
assertEqual
(
actual
,
programs_with_program_type
)
@mock.patch
(
UTILS_MODULE
+
'.get_edx_api_data'
)
class
TestGetProgramTypes
(
CatalogIntegrationMixin
,
TestCase
):
"""Tests covering retrieval of program types from the catalog service."""
...
...
openedx/core/djangoapps/catalog/utils.py
View file @
99957168
...
...
@@ -109,15 +109,17 @@ def get_program_types(name=None):
return
[]
def
get_programs_with_type
(
types
=
None
):
def
get_programs_with_type
(
types
=
None
,
include_hidden
=
True
):
"""
Return the list of programs. You can filter the types of programs returned using the optional
types parameter. If no filter is provided, all programs of all types will be returned.
types parameter. If no filter is provided, all programs of all types will be returned. In addition,
you can specify whether to include hidden programs using the optional include_hidden parameter.
The program dict is updated with the fully serialized program type.
Keyword Arguments:
types (list): List of program type slugs to filter by.
include_hidden (bool): whether to include hidden programs
Return:
list of dict, representing the active programs.
...
...
@@ -136,6 +138,9 @@ def get_programs_with_type(types=None):
if
types
and
program
[
'type'
]
not
in
types
:
continue
if
program
[
'hidden'
]
and
not
include_hidden
:
continue
# deepcopy the program dict here so we are not adding
# the type to the cached object
program_with_type
=
copy
.
deepcopy
(
program
)
...
...
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