mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-11-16 01:57:16 +00:00
Compare commits
2 Commits
60a5f25c9b
...
4a30c4ab35
Author | SHA1 | Date | |
---|---|---|---|
|
4a30c4ab35 | ||
|
487ca89885 |
7
changelog.d/20240110_101228_kyle_importnewdemocourse.md
Normal file
7
changelog.d/20240110_101228_kyle_importnewdemocourse.md
Normal file
@ -0,0 +1,7 @@
|
||||
- [Feature] Several enhancements to the Demo Course (by @kdmccormick):
|
||||
- The [Open edX Demo Course](https://github.com/openedx/openedx-demo-course) has been re-built from scratch with up-to-date instruction-focused content. Its directory structure has changed.
|
||||
- In order to support both the old and new structures of the Demo Course's repository, the command `tutor local do importdemocourse` will now auto-determine the course root based on the location of `course.xml`. Use the `--repo-dir` argument to override this behavior.
|
||||
- The new command `tutor local do importdemolibraries` will import any content libraries defined within the Demo Course repository. At the moment, that is just the "Respiratory System Question Bank", which is an optional but helpful extension to the new Demo Course.
|
||||
- To try out the new Demo Course now, run: `tutor local do importdemocourse --version master`.
|
||||
- To try out the demo Respiratory System Question Bank now, run: `tutor local do importdemolibraries --version master`.
|
||||
- To revert back to an older Demo Course version at any point, run: `tutor local do importdemocourse --version open-release/quince.2`, replacing `quince.2` with your preferred course version.
|
2
changelog.d/20240130_123351_regis_fix_save_on_plugins.md
Normal file
2
changelog.d/20240130_123351_regis_fix_save_on_plugins.md
Normal file
@ -0,0 +1,2 @@
|
||||
- [Bugfix] Actually update the environment on `tutor plugins enable ...`. (by @regisb)
|
||||
- [Feature] Introduce a `tutor.hooks.lru_cache` decorator that is automatically cleared whenever a plugin is loaded or unloaded. This is useful, in particular when a plugin implements a costly function that depends on tutor hooks. (by @regisb)
|
@ -38,7 +38,32 @@ class JobsTests(PluginsTestCase, TestCommandMixin):
|
||||
self.assertEqual(0, result.exit_code)
|
||||
self.assertIn("cms-job", dc_args)
|
||||
self.assertIn(
|
||||
"git clone https://github.com/openedx/edx-demo-course", dc_args[-1]
|
||||
"git clone https://github.com/openedx/openedx-demo-course", dc_args[-1]
|
||||
)
|
||||
|
||||
def test_import_demo_libraries(self) -> None:
|
||||
with temporary_root() as root:
|
||||
self.invoke_in_root(root, ["config", "save"])
|
||||
with patch("tutor.utils.docker_compose") as mock_docker_compose:
|
||||
result = self.invoke_in_root(
|
||||
root,
|
||||
[
|
||||
"local",
|
||||
"do",
|
||||
"importdemolibraries",
|
||||
"admin",
|
||||
],
|
||||
)
|
||||
dc_args, _dc_kwargs = mock_docker_compose.call_args
|
||||
self.assertIsNone(result.exception)
|
||||
self.assertEqual(0, result.exit_code)
|
||||
self.assertIn("cms-job", dc_args)
|
||||
self.assertIn(
|
||||
"git clone https://github.com/openedx/openedx-demo-course", dc_args[-1]
|
||||
)
|
||||
self.assertIn(
|
||||
"./manage.py cms import_content_library /tmp/library.tar.gz admin",
|
||||
dc_args[-1],
|
||||
)
|
||||
|
||||
def test_set_theme(self) -> None:
|
||||
|
16
tests/test_plugins.py
Normal file
16
tests/test_plugins.py
Normal file
@ -0,0 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from tests.helpers import PluginsTestCase
|
||||
from tutor import hooks, plugins
|
||||
|
||||
|
||||
class PluginsTests(PluginsTestCase):
|
||||
def test_env_patches_updated_on_new_plugin(self) -> None:
|
||||
self.assertEqual([], list(plugins.iter_patches("mypatch")))
|
||||
|
||||
hooks.Filters.ENV_PATCHES.add_item(("mypatch", "hello!"))
|
||||
|
||||
# env patches cache should be cleared on new plugin
|
||||
hooks.Actions.PLUGIN_LOADED.do("dummyplugin")
|
||||
|
||||
self.assertEqual(["hello!"], list(plugins.iter_patches("mypatch")))
|
@ -124,7 +124,7 @@ u.save()"
|
||||
@click.option(
|
||||
"-r",
|
||||
"--repo",
|
||||
default="https://github.com/openedx/edx-demo-course",
|
||||
default="https://github.com/openedx/openedx-demo-course",
|
||||
show_default=True,
|
||||
help="Git repository that contains the course to be imported",
|
||||
)
|
||||
@ -133,7 +133,7 @@ u.save()"
|
||||
"--repo-dir",
|
||||
default="",
|
||||
show_default=True,
|
||||
help="Git relative subdirectory to import data from",
|
||||
help="Git relative subdirectory to import data from. If unspecified, will default to the directory containing course.xml",
|
||||
)
|
||||
@click.option(
|
||||
"-v",
|
||||
@ -145,15 +145,82 @@ def importdemocourse(
|
||||
) -> t.Iterable[tuple[str, str]]:
|
||||
version = version or "{{ OPENEDX_COMMON_VERSION }}"
|
||||
template = f"""
|
||||
# Import demo course
|
||||
# Clone the repo
|
||||
git clone {repo} --branch {version} --depth 1 /tmp/course
|
||||
python ./manage.py cms import ../data /tmp/course/{repo_dir}
|
||||
|
||||
# Determine root directory for course import. If one is provided, use that.
|
||||
# Otherwise, use the directory containing course.xml, failing if there isn't exactly one.
|
||||
if [ -n "{repo_dir}" ] ; then
|
||||
course_root=/tmp/course/{repo_dir}
|
||||
else
|
||||
course_xml_first="$(find /tmp/course -name course.xml | head -n 1)"
|
||||
course_xml_extra="$(find /tmp/course -name course.xml | tail -n +2)"
|
||||
echo "INFO: Found course.xml files(s): $course_xml_first $course_xml_extra"
|
||||
if [ -z "$course_xml_first" ] ; then
|
||||
echo "ERROR: Could not find course.xml. Are you sure this is the right repository?"
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$course_xml_extra" ] ; then
|
||||
echo "ERROR: Found multiple course.xml files--course root is ambiguous!"
|
||||
echo " Please specify a course root dir (relative to repo root) using --repo-dir."
|
||||
exit 1
|
||||
fi
|
||||
course_root="$(dirname "$course_xml_first")"
|
||||
fi
|
||||
echo "INFO: Will import course data at: $course_root" && echo
|
||||
|
||||
# Import into CMS
|
||||
python ./manage.py cms import ../data "$course_root"
|
||||
|
||||
# Re-index courses
|
||||
./manage.py cms reindex_course --all --setup"""
|
||||
yield ("cms", template)
|
||||
|
||||
|
||||
@click.command(help="Import the demo content libraries")
|
||||
@click.argument("owner_username")
|
||||
@click.option(
|
||||
"-r",
|
||||
"--repo",
|
||||
default="https://github.com/openedx/openedx-demo-course",
|
||||
show_default=True,
|
||||
help="Git repository that contains the library/libraries to be imported",
|
||||
)
|
||||
@click.option(
|
||||
"-v",
|
||||
"--version",
|
||||
help="Git branch, tag or sha1 identifier. If unspecified, will default to the value of the OPENEDX_COMMON_VERSION setting.",
|
||||
)
|
||||
def importdemolibraries(
|
||||
owner_username: str, repo: str, version: t.Optional[str]
|
||||
) -> t.Iterable[tuple[str, str]]:
|
||||
version = version or "{{ OPENEDX_COMMON_VERSION }}"
|
||||
template = f"""
|
||||
# Clone the repo
|
||||
git clone {repo} --branch {version} --depth 1 /tmp/library
|
||||
|
||||
# Fail loudly if:
|
||||
# * there no library.xml files, or
|
||||
# * any library.xml is not within a directory named "library/" (upstream edx-platform expectation).
|
||||
if ! find /tmp/library -name library.xml | grep -q "." ; then
|
||||
echo "ERROR: No library.xml files found in repository. Are you sure this is the right repository and version?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# For every library.xml file, create a tar of its parent directory, and import into CMS.
|
||||
for lib_root in $(find /tmp/library -name library.xml | xargs dirname) ; do
|
||||
echo "INFO: Will import library at $lib_root"
|
||||
if [ "$(basename "$lib_root")" != "library" ] ; then
|
||||
echo "ERROR: can only import library.xml files that are within a directory named 'library'"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf /tmp/library.tar.gz
|
||||
( cd "$(dirname "$lib_root")" && tar czvf /tmp/library.tar.gz library )
|
||||
yes | ./manage.py cms import_content_library /tmp/library.tar.gz {owner_username}
|
||||
done"""
|
||||
yield ("cms", template)
|
||||
|
||||
|
||||
@click.command(
|
||||
name="print-edx-platform-setting",
|
||||
help="Print the value of an edx-platform Django setting.",
|
||||
@ -324,6 +391,7 @@ hooks.Filters.CLI_DO_COMMANDS.add_items(
|
||||
[
|
||||
createuser,
|
||||
importdemocourse,
|
||||
importdemolibraries,
|
||||
initialise,
|
||||
print_edx_platform_setting,
|
||||
settheme,
|
||||
|
Loading…
Reference in New Issue
Block a user