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
9df23dc2
Commit
9df23dc2
authored
May 09, 2017
by
Nimisha Asthagiri
Committed by
GitHub
May 09, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15066 from edx/neem/fix-block-structure-key-error
Fix KeyError issue with empty course structures
parents
cd56cc56
8c01ffb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
lms/djangoapps/grades/new/course_data.py
+4
-3
lms/djangoapps/grades/tests/test_course_data.py
+21
-2
No files found.
lms/djangoapps/grades/new/course_data.py
View file @
9df23dc2
...
...
@@ -49,7 +49,7 @@ class CourseData(object):
@property
def
structure
(
self
):
if
not
self
.
_structur
e
:
if
self
.
_structure
is
Non
e
:
self
.
_structure
=
get_course_blocks
(
self
.
user
,
self
.
location
,
...
...
@@ -59,7 +59,7 @@ class CourseData(object):
@property
def
collected_structure
(
self
):
if
not
self
.
_collected_block_structur
e
:
if
self
.
_collected_block_structure
is
Non
e
:
self
.
_collected_block_structure
=
get_block_structure_manager
(
self
.
course_key
)
.
get_collected
()
return
self
.
_collected_block_structure
...
...
@@ -90,7 +90,8 @@ class CourseData(object):
@property
def
edited_on
(
self
):
# get course block from structure only; subtree_edited_on field on modulestore's course block isn't optimized.
course_block
=
self
.
structure
[
self
.
location
]
structure
=
self
.
_effective_structure
course_block
=
structure
[
self
.
location
]
return
getattr
(
course_block
,
'subtree_edited_on'
,
None
)
def
__unicode__
(
self
):
...
...
lms/djangoapps/grades/tests/test_course_data.py
View file @
9df23dc2
...
...
@@ -4,6 +4,7 @@ Tests for CourseData utility class.
from
mock
import
patch
from
lms.djangoapps.course_blocks.api
import
get_course_blocks
from
openedx.core.djangoapps.content.block_structure.api
import
get_course_in_cache
from
student.tests.factories
import
UserFactory
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
@@ -23,10 +24,13 @@ class CourseDataTest(ModuleStoreTestCase):
# need to re-retrieve the course since the version on the original course isn't accurate.
self
.
course
=
self
.
store
.
get_course
(
self
.
course
.
id
)
self
.
user
=
UserFactory
.
create
()
self
.
one_true_structure
=
get_course_blocks
(
self
.
user
,
self
.
course
.
location
)
self
.
collected_structure
=
get_course_in_cache
(
self
.
course
.
id
)
self
.
one_true_structure
=
get_course_blocks
(
self
.
user
,
self
.
course
.
location
,
collected_block_structure
=
self
.
collected_structure
,
)
self
.
expected_results
=
{
'course'
:
self
.
course
,
'collected_block_structure'
:
self
.
one_true
_structure
,
'collected_block_structure'
:
self
.
collected
_structure
,
'structure'
:
self
.
one_true_structure
,
'course_key'
:
self
.
course
.
id
,
'location'
:
self
.
course
.
location
,
...
...
@@ -75,3 +79,18 @@ class CourseDataTest(ModuleStoreTestCase):
def
test_no_data
(
self
):
with
self
.
assertRaises
(
ValueError
):
_
=
CourseData
(
self
.
user
)
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'DISABLE_START_DATES'
:
False
})
def
test_full_string
(
self
):
empty_structure
=
get_course_blocks
(
self
.
user
,
self
.
course
.
location
)
self
.
assertFalse
(
empty_structure
)
# full_string retrieves value from collected_structure when structure is empty.
course_data
=
CourseData
(
self
.
user
,
structure
=
empty_structure
,
collected_block_structure
=
self
.
collected_structure
,
)
self
.
assertIn
(
u'Course: course_key: {}, version:'
.
format
(
self
.
course
.
id
),
course_data
.
full_string
())
# full_string returns minimal value when structures aren't readily available.
course_data
=
CourseData
(
self
.
user
,
course_key
=
self
.
course
.
id
)
self
.
assertIn
(
u'empty course structure'
,
course_data
.
full_string
())
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