Skip to content

Commit f317880

Browse files
committed
feat: wip
1 parent e058555 commit f317880

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

cms/djangoapps/contentstore/core/__init__.py

Whitespace-only changes.

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

Whitespace-only changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
Tests for course optimizer
3+
"""
4+
5+
import unittest
6+
from unittest.mock import Mock, patch
7+
8+
from cms.djangoapps.contentstore.core.course_optimizer_provider import generate_broken_links_descriptor
9+
# from ..course_optimizer_provider import generate_broken_links_descriptor
10+
11+
class TestLinkCheck(ModuleStoreTestCase):
12+
"""
13+
Tests for the link check functionality
14+
"""
15+
@patch('cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers.get_xblock')
16+
@patch('cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers.usage_key_with_run')
17+
def test_success(self):
18+
# Mock data
19+
mock_block = Mock()
20+
mock_block.location.block_id = "block_id"
21+
mock_block.display_name = "Block Name"
22+
mock_block.course_id = "course-v1:test+course+2024"
23+
mock_block.category = "html"
24+
mock_block.get_parent.side_effect = [
25+
Mock(location=Mock(block_id="unit_id"), display_name="Unit Name"),
26+
Mock(location=Mock(block_id="subsection_id"), display_name="Subsection Name"),
27+
Mock(location=Mock(block_id="section_id"), display_name="Section Name"),
28+
None,
29+
]
30+
31+
# Mocking
32+
mock_usage_key_with_run.return_value = "mock_usage_key"
33+
mock_get_xblock.return_value = mock_block
34+
35+
# Test input
36+
mock_json_content = [
37+
["block_id", "http://example.com/broken-link1", False],
38+
["block_id", "http://example.com/locked-link1", True],
39+
["block_id", "http://example.com/broken-link2", False],
40+
]
41+
request_user = Mock()
42+
43+
# Call the function
44+
result = generate_broken_links_descriptor(mock_json_content, request_user)
45+
46+
# Expected structure
47+
expected_result = {
48+
'sections': [
49+
{
50+
'id': 'section_id',
51+
'displayName': 'Section Name',
52+
'subsections': [
53+
{
54+
'id': 'subsection_id',
55+
'displayName': 'Subsection Name',
56+
'units': [
57+
{
58+
'id': 'unit_id',
59+
'displayName': 'Unit Name',
60+
'blocks': [
61+
{
62+
'id': 'block_id',
63+
'displayName': 'Block Name',
64+
'url': '/course/course-v1:test+course+2024/editor/html/mock_usage_key',
65+
'brokenLinks': [
66+
"http://example.com/broken-link1",
67+
"http://example.com/broken-link2",
68+
],
69+
'lockedLinks': ["http://example.com/broken-link1"],
70+
},
71+
]
72+
}
73+
]
74+
}
75+
]
76+
}
77+
]
78+
}
79+
80+
self.assertEqual(result, expected_result)
81+
82+
83+
# def test_exception(self):
84+
85+
# if __name__ == '__main__':
86+
# unittest.main()

0 commit comments

Comments
 (0)