2021-11-23 08:25:09 +00:00
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
from tests.helpers import temporary_root
|
2021-11-23 08:25:09 +00:00
|
|
|
from tutor import config as tutor_config
|
2022-02-07 17:11:43 +00:00
|
|
|
|
|
|
|
from .base import TestCommandMixin
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
class ConfigTests(unittest.TestCase, TestCommandMixin):
|
2021-11-23 08:25:09 +00:00
|
|
|
def test_config_help(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["config", "--help"])
|
2021-11-23 08:25:09 +00:00
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertFalse(result.exception)
|
|
|
|
|
|
|
|
def test_config_save(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["config", "save"])
|
|
|
|
self.assertFalse(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_save_interactive(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["config", "save", "-i"])
|
|
|
|
self.assertFalse(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_save_skip_update(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["config", "save", "-e"])
|
|
|
|
self.assertFalse(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_save_set_value(self) -> None:
|
|
|
|
with temporary_root() as root:
|
2022-02-07 17:11:43 +00:00
|
|
|
result1 = self.invoke_in_root(root, ["config", "save", "-s", "key=value"])
|
|
|
|
result2 = self.invoke_in_root(root, ["config", "printvalue", "key"])
|
|
|
|
self.assertFalse(result1.exception)
|
|
|
|
self.assertEqual(0, result1.exit_code)
|
|
|
|
self.assertIn("value", result2.output)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_save_unset_value(self) -> None:
|
|
|
|
with temporary_root() as root:
|
2022-02-07 17:11:43 +00:00
|
|
|
result1 = self.invoke_in_root(root, ["config", "save", "-U", "key"])
|
|
|
|
result2 = self.invoke_in_root(root, ["config", "printvalue", "key"])
|
|
|
|
self.assertFalse(result1.exception)
|
|
|
|
self.assertEqual(0, result1.exit_code)
|
|
|
|
self.assertEqual(1, result2.exit_code)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_printroot(self) -> None:
|
|
|
|
with temporary_root() as root:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke_in_root(root, ["config", "printroot"])
|
|
|
|
self.assertFalse(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertIn(root, result.output)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_printvalue(self) -> None:
|
|
|
|
with temporary_root() as root:
|
2022-02-07 17:11:43 +00:00
|
|
|
self.invoke_in_root(root, ["config", "save"])
|
|
|
|
result = self.invoke_in_root(
|
|
|
|
root, ["config", "printvalue", "MYSQL_ROOT_PASSWORD"]
|
2021-11-23 08:25:09 +00:00
|
|
|
)
|
2022-02-07 17:11:43 +00:00
|
|
|
self.assertFalse(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertTrue(result.output)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_render(self) -> None:
|
|
|
|
with tempfile.TemporaryDirectory() as dest:
|
|
|
|
with temporary_root() as root:
|
2022-02-07 17:11:43 +00:00
|
|
|
self.invoke_in_root(root, ["config", "save"])
|
|
|
|
result = self.invoke_in_root(root, ["config", "render", root, dest])
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertFalse(result.exception)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_config_render_with_extra_configs(self) -> None:
|
|
|
|
with tempfile.TemporaryDirectory() as dest:
|
|
|
|
with temporary_root() as root:
|
2022-02-07 17:11:43 +00:00
|
|
|
self.invoke_in_root(root, ["config", "save"])
|
|
|
|
result = self.invoke_in_root(
|
|
|
|
root,
|
2021-11-23 08:25:09 +00:00
|
|
|
[
|
2022-02-07 17:11:43 +00:00
|
|
|
"config",
|
2021-11-23 08:25:09 +00:00
|
|
|
"render",
|
|
|
|
"-x",
|
2022-02-07 17:11:43 +00:00
|
|
|
os.path.join(root, tutor_config.CONFIG_FILENAME),
|
|
|
|
root,
|
2021-11-23 08:25:09 +00:00
|
|
|
dest,
|
|
|
|
],
|
|
|
|
)
|
2022-02-07 17:11:43 +00:00
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertFalse(result.exception)
|