6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-11-16 18:15:09 +00:00
tutor/tests/commands/test_jobs.py
Régis Behmo 16e6131f96 feat: pluggable local/dev/k8s do <job> commands
We introduce a new filter to implement custom commands in arbitrary containers.
It becomes easy to write convenient ad-hoc commands that users will
then be able to run either on Kubernetes or locally using a documented CLI.

Pluggable jobs are declared as Click commands and are responsible for
parsing their own arguments. See the new CLI_DO_COMMANDS filter.

Close https://github.com/overhangio/2u-tutor-adoption/issues/75
2022-11-15 09:46:08 +01:00

75 lines
2.9 KiB
Python

from unittest.mock import patch
from tests.helpers import PluginsTestCase, temporary_root
from tutor.commands import jobs
from .base import TestCommandMixin
class JobsTests(PluginsTestCase, TestCommandMixin):
def test_initialise(self) -> None:
with temporary_root() as root:
self.invoke_in_root(root, ["config", "save"])
result = self.invoke_in_root(root, ["local", "do", "init"])
self.assertIsNone(result.exception)
self.assertEqual(0, result.exit_code)
self.assertIn("All services initialised.", result.output)
def test_create_user_template_without_staff(self) -> None:
command = jobs.create_user_template(
"superuser", False, "username", "email", "p4ssw0rd"
)
self.assertNotIn("--staff", command)
self.assertIn("set_password", command)
def test_create_user_template_with_staff(self) -> None:
command = jobs.create_user_template(
"superuser", True, "username", "email", "p4ssw0rd"
)
self.assertIn("--staff", command)
def test_import_demo_course(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"])
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.assertTrue(
dc_args[-1]
.strip()
.startswith('echo "Loading settings $DJANGO_SETTINGS_MODULE"')
)
def test_set_theme(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",
"settheme",
"--domain",
"domain1",
"--domain",
"domain2",
"beautiful",
],
)
dc_args, _dc_kwargs = mock_docker_compose.call_args
self.assertIsNone(result.exception)
self.assertEqual(0, result.exit_code)
self.assertIn("lms-job", dc_args)
self.assertTrue(
dc_args[-1]
.strip()
.startswith('echo "Loading settings $DJANGO_SETTINGS_MODULE"')
)
self.assertIn("assign_theme('beautiful', 'domain1')", dc_args[-1])
self.assertIn("assign_theme('beautiful', 'domain2')", dc_args[-1])