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
70469c16
Commit
70469c16
authored
Feb 22, 2016
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Block Structure API: Replace has_block with __contains__
parent
d969f486
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
12 additions
and
11 deletions
+12
-11
lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py
+2
-2
lms/djangoapps/course_blocks/transformers/tests/helpers.py
+1
-1
openedx/core/lib/block_structure/block_structure.py
+4
-3
openedx/core/lib/block_structure/manager.py
+1
-1
openedx/core/lib/block_structure/tests/helpers.py
+1
-1
openedx/core/lib/block_structure/tests/test_block_structure.py
+3
-3
No files found.
lms/djangoapps/course_api/blocks/transformers/tests/test_navigation.py
View file @
70469c16
...
...
@@ -88,14 +88,14 @@ class BlockNavigationTransformerCourseTestCase(ModuleStoreTestCase):
BlockNavigationTransformer
.
collect
(
block_structure
)
block_structure
.
_collect_requested_xblock_fields
()
self
.
assert
True
(
block_structure
.
has_block
(
chapter_x_key
)
)
self
.
assert
In
(
chapter_x_key
,
block_structure
)
# transform phase
BlockDepthTransformer
()
.
transform
(
usage_info
=
None
,
block_structure
=
block_structure
)
BlockNavigationTransformer
(
0
)
.
transform
(
usage_info
=
None
,
block_structure
=
block_structure
)
block_structure
.
_prune_unreachable
()
self
.
assert
True
(
block_structure
.
has_block
(
chapter_x_key
)
)
self
.
assert
In
(
chapter_x_key
,
block_structure
)
course_descendants
=
block_structure
.
get_transformer_block_field
(
course_usage_key
,
...
...
lms/djangoapps/course_blocks/transformers/tests/helpers.py
View file @
70469c16
...
...
@@ -311,7 +311,7 @@ class BlockParentsMapTestCase(TransformerRegistryTestMixin, ModuleStoreTestCase)
for
i
,
xblock_key
in
enumerate
(
self
.
xblock_keys
):
# compute access results of the block
block_structure_result
=
block_structure
.
has_block
(
xblock_key
)
block_structure_result
=
xblock_key
in
block_structure
has_access_result
=
bool
(
has_access
(
user
,
'load'
,
self
.
get_block
(
i
),
course_key
=
self
.
course
.
id
))
# compare with expected value
...
...
openedx/core/lib/block_structure/block_structure.py
View file @
70469c16
...
...
@@ -79,6 +79,7 @@ class BlockStructure(object):
Returns the parents of the block identified by the given
usage_key.
Arguments:
usage_key - The usage key of the block whose parents
are to be returned.
...
...
@@ -86,7 +87,7 @@ class BlockStructure(object):
Returns:
[UsageKey] - A list of usage keys of the block's parents.
"""
return
self
.
_block_relations
[
usage_key
]
.
parents
if
self
.
has_block
(
usage_key
)
else
[]
return
self
.
_block_relations
[
usage_key
]
.
parents
if
usage_key
in
self
else
[]
def
get_children
(
self
,
usage_key
):
"""
...
...
@@ -100,7 +101,7 @@ class BlockStructure(object):
Returns:
[UsageKey] - A list of usage keys of the block's children.
"""
return
self
.
_block_relations
[
usage_key
]
.
children
if
self
.
has_block
(
usage_key
)
else
[]
return
self
.
_block_relations
[
usage_key
]
.
children
if
usage_key
in
self
else
[]
def
set_root_block
(
self
,
usage_key
):
"""
...
...
@@ -117,7 +118,7 @@ class BlockStructure(object):
self
.
root_block_usage_key
=
usage_key
self
.
_block_relations
[
usage_key
]
.
parents
=
[]
def
has_block
(
self
,
usage_key
):
def
__contains__
(
self
,
usage_key
):
"""
Returns whether a block with the given usage_key is in this
block structure.
...
...
openedx/core/lib/block_structure/manager.py
View file @
70469c16
...
...
@@ -57,7 +57,7 @@ class BlockStructureManager(object):
# Override the root_block_usage_key so traversals start at the
# requested location. The rest of the structure will be pruned
# as part of the transformation.
if
not
block_structure
.
has_block
(
starting_block_usage_key
)
:
if
starting_block_usage_key
not
in
block_structure
:
raise
UsageKeyNotInBlockStructure
(
"The requested usage_key '{0}' is not found in the block_structure with root '{1}'"
,
unicode
(
starting_block_usage_key
),
...
...
openedx/core/lib/block_structure/tests/helpers.py
View file @
70469c16
...
...
@@ -219,7 +219,7 @@ class ChildrenMapTestMixin(object):
for
block_key
,
children
in
enumerate
(
children_map
):
# Verify presence
self
.
assertEquals
(
block_
structure
.
has_block
(
block_key
)
,
block_
key
in
block_structure
,
block_key
not
in
missing_blocks
,
'Expected presence in block_structure for block_key {} to match absence in missing_blocks.'
.
format
(
unicode
(
block_key
)
...
...
openedx/core/lib/block_structure/tests/test_block_structure.py
View file @
70469c16
...
...
@@ -37,10 +37,10 @@ class TestBlockStructure(TestCase, ChildrenMapTestMixin):
for
child
,
parents
in
enumerate
(
self
.
get_parents_map
(
children_map
)):
self
.
assertSetEqual
(
set
(
block_structure
.
get_parents
(
child
)),
set
(
parents
))
#
has_block
#
__contains__
for
node
in
range
(
len
(
children_map
)):
self
.
assert
True
(
block_structure
.
has_block
(
node
)
)
self
.
assert
False
(
block_structure
.
has_block
(
len
(
children_map
)
+
1
)
)
self
.
assert
In
(
node
,
block_structure
)
self
.
assert
NotIn
(
len
(
children_map
)
+
1
,
block_structure
)
@ddt.ddt
...
...
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