10
10
generate_broken_links_descriptor ,
11
11
_update_node_tree_and_dictionary ,
12
12
_get_node_path ,
13
- _create_dto_from_node_tree_recursive
13
+ _create_dto_recursive
14
14
)
15
15
16
- class TestLinkCheck (CourseTestCase ):
16
+ class TestLinkCheckProvider (CourseTestCase ):
17
17
"""
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.
19
20
"""
20
21
def setUp (self ):
21
- """Setup for tests"""
22
- global MOCK_TREE
23
- global MOCK_XBLOCK_DICTIONARY
22
+ """Setup course blocks for tests"""
24
23
global MOCK_COURSE
25
24
global MOCK_SECTION
26
25
global MOCK_SUBSECTION
27
26
global MOCK_UNIT
28
27
global MOCK_BLOCK
29
28
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
-
61
29
MOCK_COURSE = Mock ()
62
30
MOCK_SECTION = Mock (
63
31
location = Mock (block_id = 'chapter_1' ),
@@ -80,17 +48,39 @@ def setUp(self):
80
48
course_id = 'course-v1:test+course' ,
81
49
category = 'html'
82
50
)
83
- # MOCK_BLOCK.location.__str__.return_value = 'block_location_str'
84
51
MOCK_COURSE .get_parent .return_value = None
85
52
MOCK_SECTION .get_parent .return_value = MOCK_COURSE
86
53
MOCK_SUBSECTION .get_parent .return_value = MOCK_SECTION
87
54
MOCK_UNIT .get_parent .return_value = MOCK_SUBSECTION
88
55
MOCK_BLOCK .get_parent .return_value = MOCK_UNIT
89
56
90
57
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
+ """
94
84
expected_dictionary = {
95
85
'chapter_1' : {
96
86
'display_name' : 'Section Name' ,
@@ -111,30 +101,28 @@ def test_update_node_tree_and_dictionary(self):
111
101
'locked_links' : ['example_link' ]
112
102
}
113
103
}
114
-
115
104
result_tree , result_dictionary = _update_node_tree_and_dictionary (
116
105
MOCK_BLOCK , 'example_link' , True , {}, {}
117
106
)
118
107
119
- self .assertEqual (expected_tree , result_tree )
120
108
self .assertEqual (expected_dictionary , result_dictionary )
121
109
122
110
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 ({}, {})
133
117
self .assertEqual (None , expected )
134
118
135
119
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
+ """
138
126
expected_result = {
139
127
'blocks' : [
140
128
{
@@ -146,15 +134,40 @@ def test_create_dto_recursive_leaf_node(self):
146
134
}
147
135
]
148
136
}
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 )
153
162
self .assertEqual (expected_result , expected )
154
163
155
164
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
+ """
158
171
expected_result = {
159
172
'sections' : [
160
173
{
@@ -185,6 +198,36 @@ def test_create_dto_recursive_full_tree(self):
185
198
]
186
199
}
187
200
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
+
189
232
self .assertEqual (expected_result , expected )
190
233
0 commit comments