Skip to content

Commit e9e071f

Browse files
committed
fix: names and descriptions
1 parent c1f894e commit e9e071f

File tree

2 files changed

+110
-66
lines changed

2 files changed

+110
-66
lines changed

cms/djangoapps/contentstore/core/course_optimizer_provider.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def generate_broken_links_descriptor(json_content, request_user):
7676
dictionary=xblock_dictionary
7777
)
7878

79-
return _create_dto_from_node_tree_recursive(xblock_node_tree, xblock_dictionary)
79+
return _create_dto_recursive(xblock_node_tree, xblock_dictionary)
8080

8181

8282
def _update_node_tree_and_dictionary(block, link, is_locked, node_tree, dictionary):
@@ -173,9 +173,10 @@ def _get_node_path(block):
173173
}
174174

175175

176-
def _create_dto_from_node_tree_recursive(xblock_node, xblock_dictionary):
176+
def _create_dto_recursive(xblock_node, xblock_dictionary):
177177
"""
178-
Recursively build the Data Transfer Object from the node tree and dictionary.
178+
Recursively build the Data Transfer Object by using
179+
the structure from the node tree and data from the dictionary.
179180
"""
180181
# Exit condition when there are no more child nodes (at block level)
181182
if not xblock_node:
@@ -185,7 +186,7 @@ def _create_dto_from_node_tree_recursive(xblock_node, xblock_dictionary):
185186
xblock_children = []
186187

187188
for xblock_id, node in xblock_node.items():
188-
child_blocks = _create_dto_from_node_tree_recursive(node, xblock_dictionary)
189+
child_blocks = _create_dto_recursive(node, xblock_dictionary)
189190
xblock_data = xblock_dictionary.get(xblock_id, {})
190191

191192
xblock_entry = {

cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py

Lines changed: 105 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,22 @@
1010
generate_broken_links_descriptor,
1111
_update_node_tree_and_dictionary,
1212
_get_node_path,
13-
_create_dto_from_node_tree_recursive
13+
_create_dto_recursive
1414
)
1515

16-
class TestLinkCheck(CourseTestCase):
16+
class TestLinkCheckProvider(CourseTestCase):
1717
"""
18-
Tests for the link check functionality
18+
Tests for functions that generate a json structure of locked and broken links
19+
to send to the frontend.
1920
"""
2021
def setUp(self):
21-
"""Setup for tests"""
22-
global MOCK_TREE
23-
global MOCK_XBLOCK_DICTIONARY
22+
"""Setup course blocks for tests"""
2423
global MOCK_COURSE
2524
global MOCK_SECTION
2625
global MOCK_SUBSECTION
2726
global MOCK_UNIT
2827
global MOCK_BLOCK
2928

30-
MOCK_TREE = {
31-
'chapter_1': {
32-
'sequential_1': {
33-
'vertical_1': {
34-
'block_1': {}
35-
}
36-
}
37-
}
38-
}
39-
40-
MOCK_XBLOCK_DICTIONARY = {
41-
'chapter_1': {
42-
'display_name': 'Section Name',
43-
'category': 'chapter'
44-
},
45-
'sequential_1': {
46-
'display_name': 'Subsection Name',
47-
'category': 'sequential'
48-
},
49-
'vertical_1': {
50-
'display_name': 'Unit Name',
51-
'category': 'vertical'
52-
},
53-
'block_1': {
54-
'display_name': 'Block Name',
55-
'url': '/block/1',
56-
'broken_links': ['broken_link_1', 'broken_link_2'],
57-
'locked_links': ['locked_link']
58-
}
59-
}
60-
6129
MOCK_COURSE = Mock()
6230
MOCK_SECTION = Mock(
6331
location=Mock(block_id='chapter_1'),
@@ -80,17 +48,39 @@ def setUp(self):
8048
course_id='course-v1:test+course',
8149
category='html'
8250
)
83-
# MOCK_BLOCK.location.__str__.return_value = 'block_location_str'
8451
MOCK_COURSE.get_parent.return_value = None
8552
MOCK_SECTION.get_parent.return_value = MOCK_COURSE
8653
MOCK_SUBSECTION.get_parent.return_value = MOCK_SECTION
8754
MOCK_UNIT.get_parent.return_value = MOCK_SUBSECTION
8855
MOCK_BLOCK.get_parent.return_value = MOCK_UNIT
8956

9057

91-
def test_update_node_tree_and_dictionary(self):
92-
"""Test _update_node_tree_and_dictionary"""
93-
expected_tree = MOCK_TREE
58+
def test_update_node_tree_and_dictionary_returns_node_tree(self):
59+
"""
60+
Verify _update_node_tree_and_dictionary creates a node tree structure
61+
when passed a block level xblock.
62+
"""
63+
expected_tree = {
64+
'chapter_1': {
65+
'sequential_1': {
66+
'vertical_1': {
67+
'block_1': {}
68+
}
69+
}
70+
}
71+
}
72+
result_tree, result_dictionary = _update_node_tree_and_dictionary(
73+
MOCK_BLOCK, 'example_link', True, {}, {}
74+
)
75+
76+
self.assertEqual(expected_tree, result_tree)
77+
78+
79+
def test_update_node_tree_and_dictionary_returns_dictionary(self):
80+
"""
81+
Verify _update_node_tree_and_dictionary creates a dictionary of parent xblock entries
82+
when passed a block level xblock.
83+
"""
9484
expected_dictionary = {
9585
'chapter_1': {
9686
'display_name': 'Section Name',
@@ -111,30 +101,28 @@ def test_update_node_tree_and_dictionary(self):
111101
'locked_links': ['example_link']
112102
}
113103
}
114-
115104
result_tree, result_dictionary = _update_node_tree_and_dictionary(
116105
MOCK_BLOCK, 'example_link', True, {}, {}
117106
)
118107

119-
self.assertEqual(expected_tree, result_tree)
120108
self.assertEqual(expected_dictionary, result_dictionary)
121109

122110

123-
def test_get_node_path(self):
124-
"""Tests _get_node_path"""
125-
expected_result = [MOCK_SECTION, MOCK_SUBSECTION, MOCK_UNIT, MOCK_BLOCK]
126-
result = _get_node_path(MOCK_BLOCK)
127-
self.assertEqual(expected_result, result)
128-
129-
130-
def test_create_dto_recursive_empty(self):
131-
"""Tests _create_dto_from_node_tree_recursive"""
132-
expected = _create_dto_from_node_tree_recursive({}, {})
111+
def test_create_dto_recursive_returns_for_empty_node(self):
112+
"""
113+
Test _create_dto_recursive behavior at the end of recursion.
114+
Function should return None when given empty node tree and empty dictionary.
115+
"""
116+
expected = _create_dto_recursive({}, {})
133117
self.assertEqual(None, expected)
134118

135119

136-
def test_create_dto_recursive_leaf_node(self):
137-
"""Tests _create_dto_from_node_tree_recursive"""
120+
def test_create_dto_recursive_returns_for_leaf_node(self):
121+
"""
122+
Test _create_dto_recursive behavior at the step before the end of recursion.
123+
When evaluating a leaf node in the node tree, the function should return broken links
124+
and locked links data from the leaf node.
125+
"""
138126
expected_result = {
139127
'blocks': [
140128
{
@@ -146,15 +134,40 @@ def test_create_dto_recursive_leaf_node(self):
146134
}
147135
]
148136
}
149-
expected = _create_dto_from_node_tree_recursive(
150-
MOCK_TREE['chapter_1']['sequential_1']['vertical_1'],
151-
MOCK_XBLOCK_DICTIONARY
152-
)
137+
138+
mock_node_tree = {
139+
'block_1': {}
140+
}
141+
mock_dictionary = {
142+
'chapter_1': {
143+
'display_name': 'Section Name',
144+
'category': 'chapter'
145+
},
146+
'sequential_1': {
147+
'display_name': 'Subsection Name',
148+
'category': 'sequential'
149+
},
150+
'vertical_1': {
151+
'display_name': 'Unit Name',
152+
'category': 'vertical'
153+
},
154+
'block_1': {
155+
'display_name': 'Block Name',
156+
'url': '/block/1',
157+
'broken_links': ['broken_link_1', 'broken_link_2'],
158+
'locked_links': ['locked_link']
159+
}
160+
}
161+
expected = _create_dto_recursive(mock_node_tree, mock_dictionary)
153162
self.assertEqual(expected_result, expected)
154163

155164

156-
def test_create_dto_recursive_full_tree(self):
157-
"""Tests _create_dto_from_node_tree_recursive"""
165+
def test_create_dto_recursive_returns_for_full_tree(self):
166+
"""
167+
Test _create_dto_recursive behavior when recursing many times.
168+
When evaluating a fully mocked node tree and dictionary, the function should return
169+
a full json DTO prepared for frontend.
170+
"""
158171
expected_result = {
159172
'sections': [
160173
{
@@ -185,6 +198,36 @@ def test_create_dto_recursive_full_tree(self):
185198
]
186199
}
187200

188-
expected = _create_dto_from_node_tree_recursive(MOCK_TREE, MOCK_XBLOCK_DICTIONARY)
201+
mock_node_tree = {
202+
'chapter_1': {
203+
'sequential_1': {
204+
'vertical_1': {
205+
'block_1': {}
206+
}
207+
}
208+
}
209+
}
210+
mock_dictionary = {
211+
'chapter_1': {
212+
'display_name': 'Section Name',
213+
'category': 'chapter'
214+
},
215+
'sequential_1': {
216+
'display_name': 'Subsection Name',
217+
'category': 'sequential'
218+
},
219+
'vertical_1': {
220+
'display_name': 'Unit Name',
221+
'category': 'vertical'
222+
},
223+
'block_1': {
224+
'display_name': 'Block Name',
225+
'url': '/block/1',
226+
'broken_links': ['broken_link_1', 'broken_link_2'],
227+
'locked_links': ['locked_link']
228+
}
229+
}
230+
expected = _create_dto_recursive(mock_node_tree, mock_dictionary)
231+
189232
self.assertEqual(expected_result, expected)
190233

0 commit comments

Comments
 (0)