From 10c712e5b3245168efd3dcc4ab836115ff8e242b Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Thu, 18 Jan 2024 20:20:41 -0500 Subject: [PATCH] fix: separate importdemolibrary from importdemocourse --- ...0240110_101228_kyle_importnewdemocourse.md | 3 +- tests/commands/test_jobs.py | 18 ++++-- tutor/commands/jobs.py | 59 ++++++++++++------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/changelog.d/20240110_101228_kyle_importnewdemocourse.md b/changelog.d/20240110_101228_kyle_importnewdemocourse.md index b0a97125e0..7abb24f3f3 100644 --- a/changelog.d/20240110_101228_kyle_importnewdemocourse.md +++ b/changelog.d/20240110_101228_kyle_importnewdemocourse.md @@ -1 +1,2 @@ -- 💥 [Feature] `tutor local do importdemocourse` will now import the new [Open edX Demo Course](https://github.com/openedx/openedx-demo-course), which has been rebuilt from scratch, as well as its new accompanying Demo Content Library. If you wish to import the old demo course instead (which no longer receives updates), you can run: `tutor local do importdemocourse --repo-dir . --version open-release/palm.4`. +- 💥 [Feature] `tutor local do importdemocourse` will now import the new [Open edX Demo Course](https://github.com/openedx/openedx-demo-course), which has been rebuilt from scratch. If you wish to import the old demo course instead (which no longer receives updates), you can run: `tutor local do importdemocourse --repo-dir . --version open-release/palm.4`. +- [Feature] The new command `tutor local do importdemolibrary` will import a Demo Content Library, which is an optional but helpful extension to the Open edX Demo Course. diff --git a/tests/commands/test_jobs.py b/tests/commands/test_jobs.py index 25147d9535..7aecb0cfbf 100644 --- a/tests/commands/test_jobs.py +++ b/tests/commands/test_jobs.py @@ -40,14 +40,21 @@ def test_import_demo_course(self) -> None: self.assertIn( "git clone https://github.com/openedx/openedx-demo-course", dc_args[-1] ) - self.assertIn("Skipped demo library import", dc_args[-1]) - def test_import_demo_course_and_library(self) -> None: + def test_import_demo_library(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", "importdemocourse", "-L", "admin"] + root, + [ + "local", + "do", + "importdemolibrary", + "-t", + "fake/path.tar.gz", + "admin", + ], ) dc_args, _dc_kwargs = mock_docker_compose.call_args self.assertIsNone(result.exception) @@ -56,7 +63,10 @@ def test_import_demo_course_and_library(self) -> None: self.assertIn( "git clone https://github.com/openedx/openedx-demo-course", dc_args[-1] ) - self.assertIn("./manage.py cms import_content_library ", dc_args[-1]) + self.assertIn( + "./manage.py cms import_content_library /tmp/course/fake/path.tar.gz admin", + dc_args[-1], + ) def test_set_theme(self) -> None: with temporary_root() as root: diff --git a/tutor/commands/jobs.py b/tutor/commands/jobs.py index 49b2ac4daa..0707b57959 100644 --- a/tutor/commands/jobs.py +++ b/tutor/commands/jobs.py @@ -120,7 +120,7 @@ def create_user_template( """ -@click.command(help="Import the demo course and content library") +@click.command(help="Import the demo course") @click.option( "-r", "--repo", @@ -133,41 +133,55 @@ def create_user_template( "--repo-dir", default="demo-course/course", show_default=True, - help="Git relative subdirectory to import course data from", + help="Git relative subdirectory to import data from", ) @click.option( - "-l", - "--library-tar", - default="dist/demo-content-library.tar.gz", + "-v", + "--version", + help="Git branch, tag or sha1 identifier. If unspecified, will default to the value of the OPENEDX_COMMON_VERSION setting.", +) +def importdemocourse( + repo: str, repo_dir: str, version: t.Optional[str] +) -> t.Iterable[tuple[str, str]]: + version = version or "{{ OPENEDX_COMMON_VERSION }}" + template = f""" +# Import demo course +git clone {repo} --branch {version} --depth 1 /tmp/course +python ./manage.py cms import ../data /tmp/course/{repo_dir} + +# Re-index courses +./manage.py cms reindex_course --all --setup""" + yield ("cms", template) + + +@click.command(help="Import the demo content library") +@click.argument("owner_username") +@click.option( + "-r", + "--repo", + default="https://github.com/openedx/openedx-demo-course", show_default=True, - help="Git relative .tar.gz path to import content library from", + help="Git repository that contains the library to be imported", ) @click.option( - "-L", - "--library-owner", + "-t", + "--repo-tar-path", + default="dist/demo-content-library.tar.gz", show_default=True, - help="Name of Open edX user who will own the library. If omitted, library import will be skipped.", + help="Git relative .tar.gz path to import content library from", ) @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 importdemocourse( - repo: str, - repo_dir: str, - library_tar: str, - library_owner: t.Optional[str], - version: t.Optional[str], +def importdemolibrary( + owner_username: str, repo: str, repo_tar_path: str, version: t.Optional[str] ) -> t.Iterable[tuple[str, str]]: version = version or "{{ OPENEDX_COMMON_VERSION }}" - template = f"git clone {repo} --branch {version} --depth 1 /tmp/course" - if library_owner: - template += f"\nyes | ./manage.py cms import_content_library /tmp/course/{library_tar} {library_owner}" - else: - template += "\necho 'WARNING: Skipped demo library import because --library-owner was not provided.'" - template += f"\npython ./manage.py cms import ../data /tmp/course/{repo_dir}" - template += f"\n./manage.py cms reindex_course --all --setup" + template = f""" +git clone {repo} --branch {version} --depth 1 /tmp/course +yes | ./manage.py cms import_content_library /tmp/course/{repo_tar_path} {owner_username}""" yield ("cms", template) @@ -341,6 +355,7 @@ def do_callback(service_commands: t.Iterable[tuple[str, str]]) -> None: [ createuser, importdemocourse, + importdemolibrary, initialise, print_edx_platform_setting, settheme,