feat: dump_settings management command (#36162)
This command dumps the current Django settings to JSON for debugging/diagnostics. The output of this command is for *humans*... it is NOT suitable for consumption by production systems. In particular, we are introducing this command as part of a series of refactorings to the Django settings files lms/envs/* and cms/envs/*. We want to ensure that these refactorings do not introduce any unexpected breaking changes, so the dump_settings command will both help us manually verify our refactorings and help operators verify that our refactorings behave expectedly when using their custom python/yaml settings files. Related to: https://github.com/openedx/edx-platform/pull/36131
This commit is contained in:
64
openedx/core/djangoapps/util/tests/test_dump_settings.py
Normal file
64
openedx/core/djangoapps/util/tests/test_dump_settings.py
Normal file
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
Basic tests for dump_settings management command.
|
||||
|
||||
These are moreso testing that dump_settings works, less-so testing anything about the Django
|
||||
settings files themselves. Remember that tests only run with (lms,cms)/envs/test.py,
|
||||
which are based on (lms,cms)/envs/common.py, so these tests will not execute any of the
|
||||
YAML-loading or post-processing defined in (lms,cms)/envs/production.py.
|
||||
"""
|
||||
import json
|
||||
|
||||
from django.core.management import call_command
|
||||
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms, skip_unless_cms
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
def test_for_lms_settings(capsys):
|
||||
"""
|
||||
Ensure LMS's test settings can be dumped, and sanity-check them for certain values.
|
||||
"""
|
||||
dump = _get_settings_dump(capsys)
|
||||
|
||||
# Check: something LMS-specific
|
||||
assert dump['MODULESTORE_BRANCH'] == "published-only"
|
||||
|
||||
# Check: tuples are converted to lists
|
||||
assert isinstance(dump['XBLOCK_MIXINS'], list)
|
||||
|
||||
# Check: objects (like classes) are repr'd
|
||||
assert "<class 'xmodule.x_module.XModuleMixin'>" in dump['XBLOCK_MIXINS']
|
||||
|
||||
# Check: nested dictionaries come through OK, and int'l strings are just strings
|
||||
assert dump['COURSE_ENROLLMENT_MODES']['audit']['display_name'] == "Audit"
|
||||
|
||||
|
||||
@skip_unless_cms
|
||||
def test_for_cms_settings(capsys):
|
||||
"""
|
||||
Ensure CMS's test settings can be dumped, and sanity-check them for certain values.
|
||||
"""
|
||||
dump = _get_settings_dump(capsys)
|
||||
|
||||
# Check: something CMS-specific
|
||||
assert dump['MODULESTORE_BRANCH'] == "draft-preferred"
|
||||
|
||||
# Check: tuples are converted to lists
|
||||
assert isinstance(dump['XBLOCK_MIXINS'], list)
|
||||
|
||||
# Check: objects (like classes) are repr'd
|
||||
assert "<class 'xmodule.x_module.XModuleMixin'>" in dump['XBLOCK_MIXINS']
|
||||
|
||||
# Check: nested dictionaries come through OK, and int'l strings are just strings
|
||||
assert dump['COURSE_ENROLLMENT_MODES']['audit']['display_name'] == "Audit"
|
||||
|
||||
|
||||
def _get_settings_dump(captured_sys):
|
||||
"""
|
||||
Call dump_settings, ensure no error output, and return parsed JSON.
|
||||
"""
|
||||
call_command('dump_settings')
|
||||
out, err = captured_sys.readouterr()
|
||||
assert out
|
||||
assert not err
|
||||
return json.loads(out)
|
||||
Reference in New Issue
Block a user