2023-01-03 16:00:42 +00:00
|
|
|
import typing as t
|
2021-11-23 08:25:09 +00:00
|
|
|
import unittest
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
|
|
|
|
from tutor import plugins
|
2022-11-17 11:18:59 +00:00
|
|
|
from tutor.commands import plugins as plugins_commands
|
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 PluginsTests(unittest.TestCase, TestCommandMixin):
|
2021-11-23 08:25:09 +00:00
|
|
|
def test_plugins_help(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["plugins", "--help"])
|
2021-11-23 08:25:09 +00:00
|
|
|
self.assertIsNone(result.exception)
|
2022-02-07 17:11:43 +00:00
|
|
|
self.assertEqual(0, result.exit_code)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_plugins_printroot(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["plugins", "printroot"])
|
|
|
|
self.assertIsNone(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertTrue(result.output)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
@patch.object(plugins, "iter_info", return_value=[])
|
|
|
|
def test_plugins_list(self, _iter_info: Mock) -> None:
|
|
|
|
result = self.invoke(["plugins", "list"])
|
|
|
|
self.assertIsNone(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
2023-01-03 16:00:42 +00:00
|
|
|
self.assertEqual("NAME\tSTATUS\tVERSION\n", result.output)
|
2022-02-07 17:11:43 +00:00
|
|
|
_iter_info.assert_called()
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_plugins_install_not_found_plugin(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["plugins", "install", "notFound"])
|
|
|
|
self.assertEqual(1, result.exit_code)
|
|
|
|
self.assertTrue(result.exception)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_plugins_enable_not_installed_plugin(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["plugins", "enable", "notFound"])
|
|
|
|
self.assertEqual(1, result.exit_code)
|
|
|
|
self.assertTrue(result.exception)
|
2021-11-23 08:25:09 +00:00
|
|
|
|
|
|
|
def test_plugins_disable_not_installed_plugin(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["plugins", "disable", "notFound"])
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertFalse(result.exception)
|
2022-11-17 11:18:59 +00:00
|
|
|
|
|
|
|
@patch.object(
|
|
|
|
plugins,
|
|
|
|
"iter_info",
|
|
|
|
return_value=[("aacd", None), ("abcd", None), ("abef", None), ("alba", None)],
|
|
|
|
)
|
|
|
|
def test_plugins_name_auto_complete(self, _iter_info: Mock) -> None:
|
|
|
|
self.assertEqual([], plugins_commands.PluginName().get_names("z"))
|
|
|
|
self.assertEqual(
|
|
|
|
["abcd", "abef"], plugins_commands.PluginName().get_names("ab")
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
["all", "alba"], plugins_commands.PluginName(allow_all=True).get_names("al")
|
|
|
|
)
|
2023-01-03 16:00:42 +00:00
|
|
|
|
|
|
|
def test_format_table(self) -> None:
|
|
|
|
rows: t.List[t.Tuple[str, ...]] = [
|
|
|
|
("a", "xyz", "value 1"),
|
|
|
|
("abc", "x", "value 12345"),
|
|
|
|
]
|
|
|
|
formatted = plugins_commands.format_table(rows, separator=" ")
|
|
|
|
self.assertEqual(
|
|
|
|
"""
|
|
|
|
a xyz value 1
|
|
|
|
abc x value 12345
|
|
|
|
""".strip(),
|
|
|
|
formatted,
|
|
|
|
)
|