-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
course_optimizer_provider tests #36033
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e058555
feat: locked link
rayzhou-bit f317880
feat: wip
rayzhou-bit 81619f8
feat: tests wip
rayzhou-bit ebee1d9
Merge branch '2u/course-optimizer' into 2u/optimizer-tests
rayzhou-bit 4bf67c4
feat: course_optimizer_provider tests
rayzhou-bit c1f894e
Merge branch '2u/course-optimizer' into 2u/optimizer-tests
rayzhou-bit e9e071f
fix: names and descriptions
rayzhou-bit 6cf8127
feat: test impovements
rayzhou-bit 1f60c59
Merge branch '2u/course-optimizer' into 2u/optimizer-tests
rayzhou-bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
190 changes: 190 additions & 0 deletions
190
cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
""" | ||
Tests for course optimizer | ||
""" | ||
|
||
import unittest | ||
from unittest.mock import Mock, patch | ||
|
||
from cms.djangoapps.contentstore.tests.utils import CourseTestCase | ||
from cms.djangoapps.contentstore.core.course_optimizer_provider import ( | ||
generate_broken_links_descriptor, | ||
_update_node_tree_and_dictionary, | ||
_get_node_path, | ||
_create_dto_from_node_tree_recursive | ||
) | ||
|
||
class TestLinkCheck(CourseTestCase): | ||
""" | ||
Tests for the link check functionality | ||
""" | ||
def setUp(self): | ||
"""Setup for tests""" | ||
global MOCK_TREE | ||
global MOCK_XBLOCK_DICTIONARY | ||
global MOCK_COURSE | ||
global MOCK_SECTION | ||
global MOCK_SUBSECTION | ||
global MOCK_UNIT | ||
global MOCK_BLOCK | ||
|
||
MOCK_TREE = { | ||
'chapter_1': { | ||
'sequential_1': { | ||
'vertical_1': { | ||
'block_1': {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
MOCK_XBLOCK_DICTIONARY = { | ||
'chapter_1': { | ||
'display_name': 'Section Name', | ||
'category': 'chapter' | ||
}, | ||
'sequential_1': { | ||
'display_name': 'Subsection Name', | ||
'category': 'sequential' | ||
}, | ||
'vertical_1': { | ||
'display_name': 'Unit Name', | ||
'category': 'vertical' | ||
}, | ||
'block_1': { | ||
'display_name': 'Block Name', | ||
'url': '/block/1', | ||
'broken_links': ['broken_link_1', 'broken_link_2'], | ||
'locked_links': ['locked_link'] | ||
} | ||
} | ||
|
||
MOCK_COURSE = Mock() | ||
MOCK_SECTION = Mock( | ||
location=Mock(block_id='chapter_1'), | ||
display_name='Section Name', | ||
category='chapter' | ||
) | ||
MOCK_SUBSECTION = Mock( | ||
location=Mock(block_id='sequential_1'), | ||
display_name='Subsection Name', | ||
category='sequential' | ||
) | ||
MOCK_UNIT = Mock( | ||
location=Mock(block_id='vertical_1'), | ||
display_name='Unit Name', | ||
category='vertical' | ||
) | ||
MOCK_BLOCK = Mock( | ||
location=Mock(block_id='block_1'), | ||
display_name='Block Name', | ||
course_id='course-v1:test+course', | ||
category='html' | ||
) | ||
# MOCK_BLOCK.location.__str__.return_value = 'block_location_str' | ||
MOCK_COURSE.get_parent.return_value = None | ||
MOCK_SECTION.get_parent.return_value = MOCK_COURSE | ||
MOCK_SUBSECTION.get_parent.return_value = MOCK_SECTION | ||
MOCK_UNIT.get_parent.return_value = MOCK_SUBSECTION | ||
MOCK_BLOCK.get_parent.return_value = MOCK_UNIT | ||
|
||
|
||
def test_update_node_tree_and_dictionary(self): | ||
"""Test _update_node_tree_and_dictionary""" | ||
expected_tree = MOCK_TREE | ||
expected_dictionary = { | ||
'chapter_1': { | ||
'display_name': 'Section Name', | ||
'category': 'chapter' | ||
}, | ||
'sequential_1': { | ||
'display_name': 'Subsection Name', | ||
'category': 'sequential' | ||
}, | ||
'vertical_1': { | ||
'display_name': 'Unit Name', | ||
'category': 'vertical' | ||
}, | ||
'block_1': { | ||
'display_name': 'Block Name', | ||
'category': 'html', | ||
'url': f'/course/{MOCK_BLOCK.course_id}/editor/html/{MOCK_BLOCK.location}', | ||
'locked_links': ['example_link'] | ||
} | ||
} | ||
|
||
result_tree, result_dictionary = _update_node_tree_and_dictionary( | ||
MOCK_BLOCK, 'example_link', True, {}, {} | ||
) | ||
|
||
self.assertEqual(expected_tree, result_tree) | ||
self.assertEqual(expected_dictionary, result_dictionary) | ||
|
||
|
||
def test_get_node_path(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See naming comment above |
||
"""Tests _get_node_path""" | ||
expected_result = [MOCK_SECTION, MOCK_SUBSECTION, MOCK_UNIT, MOCK_BLOCK] | ||
result = _get_node_path(MOCK_BLOCK) | ||
self.assertEqual(expected_result, result) | ||
|
||
|
||
def test_create_dto_recursive_empty(self): | ||
"""Tests _create_dto_from_node_tree_recursive""" | ||
expected = _create_dto_from_node_tree_recursive({}, {}) | ||
self.assertEqual(None, expected) | ||
|
||
|
||
def test_create_dto_recursive_leaf_node(self): | ||
"""Tests _create_dto_from_node_tree_recursive""" | ||
expected_result = { | ||
'blocks': [ | ||
{ | ||
'id': 'block_1', | ||
'displayName': 'Block Name', | ||
'url': '/block/1', | ||
'brokenLinks': ['broken_link_1', 'broken_link_2'], | ||
'lockedLinks': ['locked_link'] | ||
} | ||
] | ||
} | ||
expected = _create_dto_from_node_tree_recursive( | ||
MOCK_TREE['chapter_1']['sequential_1']['vertical_1'], | ||
MOCK_XBLOCK_DICTIONARY | ||
) | ||
self.assertEqual(expected_result, expected) | ||
|
||
|
||
def test_create_dto_recursive_full_tree(self): | ||
"""Tests _create_dto_from_node_tree_recursive""" | ||
expected_result = { | ||
'sections': [ | ||
{ | ||
'id': 'chapter_1', | ||
'displayName': 'Section Name', | ||
'subsections': [ | ||
{ | ||
'id': 'sequential_1', | ||
'displayName': 'Subsection Name', | ||
'units': [ | ||
{ | ||
'id': 'vertical_1', | ||
'displayName': 'Unit Name', | ||
'blocks': [ | ||
{ | ||
'id': 'block_1', | ||
'displayName': 'Block Name', | ||
'url': '/block/1', | ||
'brokenLinks': ['broken_link_1', 'broken_link_2'], | ||
'lockedLinks': ['locked_link'] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
expected = _create_dto_from_node_tree_recursive(MOCK_TREE, MOCK_XBLOCK_DICTIONARY) | ||
self.assertEqual(expected_result, expected) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you have a look at https://github.com/openedx/frontend-lib-content-components/blob/main/docs/decisions/0006-test-names.rst and follow the naming conventions there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the convention we use for pytest is that the function docstring describes quite clearly what the unit under test is supposed to do and what we are testing.