2021-11-23 08:25:09 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
from tests.helpers import PluginsTestCase, temporary_root
|
2022-10-18 14:57:07 +00:00
|
|
|
from tutor.commands import jobs
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
from .base import TestCommandMixin
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
|
|
|
|
class JobsTests(PluginsTestCase, TestCommandMixin):
|
|
|
|
def test_initialise(self) -> None:
|
2021-11-23 08:25:09 +00:00
|
|
|
with temporary_root() as root:
|
2022-10-19 15:46:31 +00:00
|
|
|
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)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
def test_create_user_template_without_staff(self) -> None:
|
|
|
|
command = jobs.create_user_template(
|
|
|
|
"superuser", False, "username", "email", "p4ssw0rd"
|
|
|
|
)
|
2021-11-23 08:25:09 +00:00
|
|
|
self.assertNotIn("--staff", command)
|
2022-10-18 14:57:07 +00:00
|
|
|
self.assertIn("set_password", command)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
def test_create_user_template_with_staff(self) -> None:
|
|
|
|
command = jobs.create_user_template(
|
|
|
|
"superuser", True, "username", "email", "p4ssw0rd"
|
|
|
|
)
|
2021-11-23 08:25:09 +00:00
|
|
|
self.assertIn("--staff", command)
|
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
def test_import_demo_course(self) -> None:
|
2021-11-23 08:25:09 +00:00
|
|
|
with temporary_root() as root:
|
2022-10-19 15:46:31 +00:00
|
|
|
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)
|
2022-11-24 17:26:00 +00:00
|
|
|
self.assertIn(
|
|
|
|
"git clone https://github.com/openedx/edx-demo-course", dc_args[-1]
|
2022-10-19 15:46:31 +00:00
|
|
|
)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
def test_set_theme(self) -> None:
|
2021-11-23 08:25:09 +00:00
|
|
|
with temporary_root() as root:
|
2022-10-19 15:46:31 +00:00
|
|
|
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
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-10-19 15:46:31 +00:00
|
|
|
self.assertIsNone(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertIn("lms-job", dc_args)
|
|
|
|
self.assertIn("assign_theme('beautiful', 'domain1')", dc_args[-1])
|
|
|
|
self.assertIn("assign_theme('beautiful', 'domain2')", dc_args[-1])
|