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
8f530d12
Commit
8f530d12
authored
Aug 16, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise ItemNotFoundError rather than return None if no map found
parent
bd8a7906
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
22 deletions
+26
-22
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
+8
-5
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
+18
-17
No files found.
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
View file @
8f530d12
...
...
@@ -107,10 +107,13 @@ class LocMapperStore(object):
if the code just trips into this w/o creating translations. The downfall is that ambiguous course
locations may generate conflicting block_ids.
Will raise ItemNotFoundError if there's no mapping and add_entry_if_missing is False.
:param old_style_course_id: the course_id used in old mongo not the new one (optional, will use location)
:param location: a Location pointing to a module
:param published: a boolean to indicate whether the caller wants the draft or published branch.
:param add_entry_if_missing: a boolean as to whether to return None or to create an entry if the course
:param add_entry_if_missing: a boolean as to whether to raise ItemNotFoundError or to create an entry if
the course
or block is not found in the map.
NOTE: unlike old mongo, draft branches contain the whole course; so, it applies to all category
...
...
@@ -126,7 +129,7 @@ class LocMapperStore(object):
self
.
create_map_entry
(
course_location
)
entry
=
self
.
location_map
.
find_one
(
location_id
)
else
:
r
eturn
None
r
aise
ItemNotFoundError
()
elif
maps
.
count
()
>
1
:
# if more than one, prefer the one w/o a name if that exists. Otherwise, choose the first (arbitrary)
# a bit odd b/c maps is a cursor and doesn't allow multitraversal w/o requerying db
...
...
@@ -150,7 +153,7 @@ class LocMapperStore(object):
if
add_entry_if_missing
:
usage_id
=
self
.
_add_to_block_map
(
location
,
location_id
,
entry
[
'block_map'
])
else
:
r
eturn
None
r
aise
ItemNotFoundError
()
elif
isinstance
(
usage_id
,
dict
):
# name is not unique, look through for the right category
if
location
.
category
in
usage_id
:
...
...
@@ -158,7 +161,7 @@ class LocMapperStore(object):
elif
add_entry_if_missing
:
usage_id
=
self
.
_add_to_block_map
(
location
,
location_id
,
entry
[
'block_map'
])
else
:
r
eturn
None
r
aise
ItemNotFoundError
()
else
:
raise
InvalidLocationError
()
...
...
@@ -179,7 +182,7 @@ class LocMapperStore(object):
:param locator: a BlockUsageLocator
"""
#
Does not use _lookup_course b/c it doesn't actually require that the course exist in the active_version
#
This does not require that the course exist in any modulestore
# only that it has a mapping entry.
maps
=
self
.
location_map
.
find
({
'course_id'
:
locator
.
course_id
})
# look for one which maps to this block usage_id
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
View file @
8f530d12
...
...
@@ -78,12 +78,12 @@ class TestLocationMapper(unittest.TestCase):
org
=
'foo_org'
course
=
'bar_course'
old_style_course_id
=
'{}/{}/{}'
.
format
(
org
,
course
,
'baz_run'
)
prob_locator
=
loc_mapper
()
.
translate_location
(
old_style_course_id
,
Location
(
'i4x'
,
org
,
course
,
'problem'
,
'abc123'
)
,
add_entry_if_missing
=
False
)
self
.
assertIsNone
(
prob_locator
,
'found entry in empty map table'
)
with
self
.
assertRaises
(
ItemNotFoundError
):
_
=
loc_mapper
()
.
translate_location
(
old_style_course_id
,
Location
(
'i4x'
,
org
,
course
,
'problem'
,
'abc123'
),
add_entry_if_missing
=
False
)
new_style_course_id
=
'{}.geek_dept.{}.baz_run'
.
format
(
org
,
course
)
block_map
=
{
'abc123'
:
{
'problem'
:
'problem2'
}}
...
...
@@ -109,12 +109,12 @@ class TestLocationMapper(unittest.TestCase):
)
self
.
assertEqual
(
prob_locator
.
course_id
,
new_style_course_id
)
# look for non-existent problem
prob_locator
=
loc_mapper
()
.
translate_location
(
None
,
Location
(
'i4x'
,
org
,
course
,
'problem'
,
'1def23'
)
,
add_entry_if_missing
=
False
)
self
.
assertIsNone
(
prob_locator
,
"Found non-existent problem"
)
with
self
.
assertRaises
(
ItemNotFoundError
):
prob_locator
=
loc_mapper
()
.
translate_location
(
None
,
Location
(
'i4x'
,
org
,
course
,
'problem'
,
'1def23'
),
add_entry_if_missing
=
False
)
# add a distractor course
block_map
=
{
'abc123'
:
{
'problem'
:
'problem3'
}}
...
...
@@ -477,11 +477,12 @@ class TestLocationMapper(unittest.TestCase):
# delete from one course
location
=
location
.
replace
(
name
=
'abc123'
)
loc_mapper
()
.
delete_block_location_translator
(
location
,
'{}/{}/{}'
.
format
(
org
,
course
,
'baz_run'
))
self
.
assertIsNone
(
loc_mapper
()
.
translate_location
(
'{}/{}/{}'
.
format
(
org
,
course
,
'baz_run'
),
location
,
add_entry_if_missing
=
False
))
with
self
.
assertRaises
(
ItemNotFoundError
):
loc_mapper
()
.
translate_location
(
'{}/{}/{}'
.
format
(
org
,
course
,
'baz_run'
),
location
,
add_entry_if_missing
=
False
)
locator
=
loc_mapper
()
.
translate_location
(
'{}/{}/{}'
.
format
(
org
,
course
,
'delta_run'
),
location
,
...
...
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