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
935be271
Commit
935be271
authored
Jul 19, 2016
by
Renzo Lucioni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow program detail pages to function when catalog config is missing
parent
fa56b575
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
19 deletions
+32
-19
openedx/core/djangoapps/catalog/tests/test_utils.py
+14
-4
openedx/core/djangoapps/catalog/utils.py
+18
-15
No files found.
openedx/core/djangoapps/catalog/tests/test_utils.py
View file @
935be271
...
...
@@ -5,6 +5,7 @@ import mock
from
opaque_keys.edx.keys
import
CourseKey
from
openedx.core.djangoapps.catalog
import
utils
from
openedx.core.djangoapps.catalog.models
import
CatalogIntegration
from
openedx.core.djangoapps.catalog.tests
import
factories
,
mixins
from
student.tests.factories
import
UserFactory
...
...
@@ -13,6 +14,8 @@ UTILS_MODULE = 'openedx.core.djangoapps.catalog.utils'
@mock.patch
(
UTILS_MODULE
+
'.get_edx_api_data'
)
# ConfigurationModels use the cache. Make every cache get a miss.
@mock.patch
(
'config_models.models.cache.get'
,
return_value
=
None
)
class
TestGetCourseRun
(
mixins
.
CatalogIntegrationMixin
,
TestCase
):
"""Tests covering retrieval of course runs from the catalog service."""
def
setUp
(
self
):
...
...
@@ -34,7 +37,7 @@ class TestGetCourseRun(mixins.CatalogIntegrationMixin, TestCase):
return
args
,
kwargs
def
test_get_course_run
(
self
,
mock_get_catalog_data
):
def
test_get_course_run
(
self
,
_mock_cache
,
mock_get_catalog_data
):
course_run
=
factories
.
CourseRun
()
mock_get_catalog_data
.
return_value
=
course_run
...
...
@@ -43,7 +46,7 @@ class TestGetCourseRun(mixins.CatalogIntegrationMixin, TestCase):
self
.
assert_contract
(
mock_get_catalog_data
.
call_args
)
self
.
assertEqual
(
data
,
course_run
)
def
test_course_run_unavailable
(
self
,
mock_get_catalog_data
):
def
test_course_run_unavailable
(
self
,
_mock_cache
,
mock_get_catalog_data
):
mock_get_catalog_data
.
return_value
=
[]
data
=
utils
.
get_course_run
(
self
.
course_key
,
self
.
user
)
...
...
@@ -51,14 +54,14 @@ class TestGetCourseRun(mixins.CatalogIntegrationMixin, TestCase):
self
.
assert_contract
(
mock_get_catalog_data
.
call_args
)
self
.
assertEqual
(
data
,
{})
def
test_cache_disabled
(
self
,
mock_get_catalog_data
):
def
test_cache_disabled
(
self
,
_mock_cache
,
mock_get_catalog_data
):
utils
.
get_course_run
(
self
.
course_key
,
self
.
user
)
_
,
kwargs
=
self
.
assert_contract
(
mock_get_catalog_data
.
call_args
)
self
.
assertIsNone
(
kwargs
[
'cache_key'
])
def
test_cache_enabled
(
self
,
mock_get_catalog_data
):
def
test_cache_enabled
(
self
,
_mock_cache
,
mock_get_catalog_data
):
catalog_integration
=
self
.
create_catalog_integration
(
cache_ttl
=
1
)
utils
.
get_course_run
(
self
.
course_key
,
self
.
user
)
...
...
@@ -67,6 +70,13 @@ class TestGetCourseRun(mixins.CatalogIntegrationMixin, TestCase):
self
.
assertEqual
(
kwargs
[
'cache_key'
],
catalog_integration
.
CACHE_KEY
)
def
test_config_missing
(
self
,
_mock_cache
,
_mock_get_catalog_data
):
"""Verify that no errors occur if this method is called when catalog config is missing."""
CatalogIntegration
.
objects
.
all
()
.
delete
()
data
=
utils
.
get_course_run
(
self
.
course_key
,
self
.
user
)
self
.
assertEqual
(
data
,
{})
@mock.patch
(
UTILS_MODULE
+
'.get_course_run'
)
@mock.patch
(
UTILS_MODULE
+
'.strip_querystring'
)
...
...
openedx/core/djangoapps/catalog/utils.py
View file @
935be271
...
...
@@ -21,21 +21,24 @@ def get_course_run(course_key, user):
"""
catalog_integration
=
CatalogIntegration
.
current
()
scopes
=
[
'email'
,
'profile'
]
expires_in
=
settings
.
OAUTH_ID_TOKEN_EXPIRATION
jwt
=
JwtBuilder
(
user
)
.
build_token
(
scopes
,
expires_in
)
api
=
EdxRestApiClient
(
catalog_integration
.
internal_api_url
,
jwt
=
jwt
)
data
=
get_edx_api_data
(
catalog_integration
,
user
,
'course_runs'
,
resource_id
=
unicode
(
course_key
),
cache_key
=
catalog_integration
.
CACHE_KEY
if
catalog_integration
.
is_cache_enabled
else
None
,
api
=
api
,
)
return
data
if
data
else
{}
if
catalog_integration
.
enabled
:
scopes
=
[
'email'
,
'profile'
]
expires_in
=
settings
.
OAUTH_ID_TOKEN_EXPIRATION
jwt
=
JwtBuilder
(
user
)
.
build_token
(
scopes
,
expires_in
)
api
=
EdxRestApiClient
(
catalog_integration
.
internal_api_url
,
jwt
=
jwt
)
data
=
get_edx_api_data
(
catalog_integration
,
user
,
'course_runs'
,
resource_id
=
unicode
(
course_key
),
cache_key
=
catalog_integration
.
CACHE_KEY
if
catalog_integration
.
is_cache_enabled
else
None
,
api
=
api
,
)
return
data
if
data
else
{}
else
:
return
{}
def
get_run_marketing_url
(
course_key
,
user
):
...
...
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