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
c84eda42
Commit
c84eda42
authored
Jan 23, 2017
by
Renzo Lucioni
Committed by
GitHub
Jan 23, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14357 from edx/renzo/catalog-switch
Transition program list and detail pages to the catalog
parents
d5a879d3
3fd23629
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
6 deletions
+75
-6
lms/djangoapps/learner_dashboard/tests/test_programs.py
+23
-3
lms/djangoapps/learner_dashboard/views.py
+3
-1
openedx/core/djangolib/testing/tests/test_utils.py
+26
-1
openedx/core/djangolib/testing/utils.py
+23
-1
No files found.
lms/djangoapps/learner_dashboard/tests/test_programs.py
View file @
c84eda42
...
...
@@ -23,6 +23,7 @@ from openedx.core.djangoapps.credentials.tests.mixins import CredentialsApiConfi
from
openedx.core.djangoapps.programs.models
import
ProgramsApiConfig
from
openedx.core.djangoapps.programs.tests
import
factories
as
programs_factories
from
openedx.core.djangoapps.programs.tests.mixins
import
ProgramsApiConfigMixin
from
openedx.core.djangolib.testing.utils
import
skip_unless_lms
,
toggle_switch
from
student.tests.factories
import
UserFactory
,
CourseEnrollmentFactory
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
...
...
@@ -32,9 +33,9 @@ UTILS_MODULE = 'openedx.core.djangoapps.programs.utils'
MARKETING_URL
=
'https://www.example.com/marketing/path'
@skip_unless_lms
@httpretty.activate
@override_settings
(
MKTG_URLS
=
{
'ROOT'
:
'https://www.example.com'
})
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
class
TestProgramListing
(
ProgramsApiConfigMixin
,
CredentialsApiConfigMixin
,
SharedModuleStoreTestCase
):
"""Unit tests for the program listing page."""
maxDiff
=
None
...
...
@@ -99,7 +100,7 @@ class TestProgramListing(ProgramsApiConfigMixin, CredentialsApiConfigMixin, Shar
"""Helper for mocking out Credentials API URLs."""
self
.
assertTrue
(
httpretty
.
is_enabled
(),
msg
=
'httpretty must be enabled to mock Credentials API calls.'
)
url
=
'{base}/
user_
credentials/?username={username}'
.
format
(
url
=
'{base}/credentials/?username={username}'
.
format
(
base
=
CredentialsApiConfig
.
current
()
.
internal_api_url
.
strip
(
'/'
),
username
=
self
.
user
.
username
)
...
...
@@ -261,10 +262,29 @@ class TestProgramListing(ProgramsApiConfigMixin, CredentialsApiConfigMixin, Shar
expected_credential
[
'certificate_url'
]
)
def
test_switch_to_catalog
(
self
):
"""
Verify that the 'get_programs_from_catalog' switch can be used to route
traffic between the programs and catalog services.
"""
self
.
create_programs_config
()
switch_name
=
'get_programs_from_catalog'
with
mock
.
patch
(
'openedx.core.djangoapps.programs.utils.get_programs'
)
as
mock_get_programs
:
mock_get_programs
.
return_value
=
self
.
data
toggle_switch
(
switch_name
)
self
.
client
.
get
(
self
.
url
)
mock_get_programs
.
assert_called_with
(
self
.
user
,
use_catalog
=
True
)
toggle_switch
(
switch_name
)
self
.
client
.
get
(
self
.
url
)
mock_get_programs
.
assert_called_with
(
self
.
user
,
use_catalog
=
False
)
@skip_unless_lms
@httpretty.activate
@override_settings
(
MKTG_URLS
=
{
'ROOT'
:
'https://www.example.com'
})
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
@mock.patch
(
UTILS_MODULE
+
'.get_run_marketing_url'
,
mock
.
Mock
(
return_value
=
MARKETING_URL
))
class
TestProgramDetails
(
ProgramsApiConfigMixin
,
SharedModuleStoreTestCase
):
"""Unit tests for the program details page."""
...
...
lms/djangoapps/learner_dashboard/views.py
View file @
c84eda42
...
...
@@ -13,6 +13,7 @@ from openedx.core.djangoapps.credentials.utils import get_programs_credentials
from
openedx.core.djangoapps.programs.models
import
ProgramsApiConfig
from
openedx.core.djangoapps.programs
import
utils
from
openedx.core.djangoapps.user_api.preferences.api
import
get_user_preferences
import
waffle
@login_required
...
...
@@ -23,7 +24,8 @@ def program_listing(request):
if
not
programs_config
.
show_program_listing
:
raise
Http404
meter
=
utils
.
ProgramProgressMeter
(
request
.
user
)
use_catalog
=
waffle
.
switch_is_active
(
'get_programs_from_catalog'
)
meter
=
utils
.
ProgramProgressMeter
(
request
.
user
,
use_catalog
=
use_catalog
)
context
=
{
'credentials'
:
get_programs_credentials
(
request
.
user
),
...
...
openedx/core/djangolib/testing/tests/test_utils.py
View file @
c84eda42
...
...
@@ -5,8 +5,9 @@ from django.contrib.auth import get_user_model
from
django.contrib.auth.models
import
AnonymousUser
from
django.http.request
import
HttpRequest
from
django.test
import
TestCase
from
waffle.models
import
Switch
from
..utils
import
get_mock_request
from
..utils
import
get_mock_request
,
toggle_switch
USER_MODEL
=
get_user_model
()
...
...
@@ -27,3 +28,27 @@ class TestGetMockRequest(TestCase):
def
test_mock_request_without_user
(
self
):
request
=
get_mock_request
()
self
.
assertIsInstance
(
request
.
user
,
AnonymousUser
)
class
TestToggleSwitch
(
TestCase
):
"""
Verify that the toggle_switch utility can be used to turn Waffle Switches
on and off.
"""
def
test_toggle_switch
(
self
):
"""Verify that a new switch can be turned on and off."""
name
=
'foo'
switch
=
toggle_switch
(
name
)
# Verify that the switch was saved.
self
.
assertEqual
(
switch
,
Switch
.
objects
.
get
())
# Verify that the switch has the right name and is active.
self
.
assertEqual
(
switch
.
name
,
name
)
self
.
assertTrue
(
switch
.
active
)
switch
=
toggle_switch
(
name
)
# Verify that the switch has been turned off.
self
.
assertFalse
(
switch
.
active
)
openedx/core/djangolib/testing/utils.py
View file @
c84eda42
...
...
@@ -18,8 +18,8 @@ from django.core.cache import caches
from
django.test
import
RequestFactory
,
TestCase
,
override_settings
from
django.conf
import
settings
from
django.contrib
import
sites
from
nose.plugins
import
Plugin
from
waffle.models
import
Switch
from
request_cache.middleware
import
RequestCache
...
...
@@ -190,3 +190,25 @@ def skip_unless_lms(func):
Only run the decorated test in the LMS test suite
"""
return
skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in LMS'
)(
func
)
def
toggle_switch
(
name
,
active
=
True
):
"""
Activate or deactivate a Waffle switch. The switch is created if it does not exist.
Arguments:
name (str): Name of the switch to be toggled.
Keyword Arguments:
active (bool): Whether a newly created switch should be on or off.
Returns:
Switch
"""
switch
,
created
=
Switch
.
objects
.
get_or_create
(
name
=
name
,
defaults
=
{
'active'
:
active
})
if
not
created
:
switch
.
active
=
not
switch
.
active
switch
.
save
()
return
switch
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