2022-04-20 20:24:17 +00:00
|
|
|
import os
|
|
|
|
import tempfile
|
2021-11-23 08:25:09 +00:00
|
|
|
import unittest
|
2022-04-20 20:24:17 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from tests.helpers import temporary_root
|
2021-11-23 08:25:09 +00:00
|
|
|
|
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 LocalTests(unittest.TestCase, TestCommandMixin):
|
2021-11-23 08:25:09 +00:00
|
|
|
def test_local_help(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["local", "--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_local_quickstart_help(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["local", "quickstart", "--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_local_upgrade_help(self) -> None:
|
2022-02-07 17:11:43 +00:00
|
|
|
result = self.invoke(["local", "upgrade", "--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)
|
2022-04-20 20:24:17 +00:00
|
|
|
|
|
|
|
def test_copyfrom(self) -> None:
|
|
|
|
with temporary_root() as root:
|
|
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
|
|
with patch("tutor.utils.docker_compose") as mock_docker_compose:
|
|
|
|
self.invoke_in_root(root, ["config", "save"])
|
|
|
|
|
|
|
|
# Copy to existing directory
|
|
|
|
result = self.invoke_in_root(
|
|
|
|
root, ["local", "copyfrom", "lms", "/openedx/venv", directory]
|
|
|
|
)
|
|
|
|
self.assertIsNone(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertIn(
|
|
|
|
f"--volume={directory}:/tmp/mount",
|
2022-04-24 08:39:51 +00:00
|
|
|
mock_docker_compose.call_args[0],
|
2022-04-20 20:24:17 +00:00
|
|
|
)
|
|
|
|
self.assertIn(
|
|
|
|
"cp --recursive --preserve /openedx/venv /tmp/mount",
|
2022-04-24 08:39:51 +00:00
|
|
|
mock_docker_compose.call_args[0],
|
2022-04-20 20:24:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Copy to non-existing directory
|
|
|
|
result = self.invoke_in_root(
|
|
|
|
root,
|
|
|
|
[
|
|
|
|
"local",
|
|
|
|
"copyfrom",
|
|
|
|
"lms",
|
|
|
|
"/openedx/venv",
|
|
|
|
os.path.join(directory, "venv2"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertIsNone(result.exception)
|
|
|
|
self.assertEqual(0, result.exit_code)
|
|
|
|
self.assertIn(
|
|
|
|
f"--volume={directory}:/tmp/mount",
|
2022-04-24 08:39:51 +00:00
|
|
|
mock_docker_compose.call_args[0],
|
2022-04-20 20:24:17 +00:00
|
|
|
)
|
|
|
|
self.assertIn(
|
|
|
|
"cp --recursive --preserve /openedx/venv /tmp/mount/venv2",
|
2022-04-24 08:39:51 +00:00
|
|
|
mock_docker_compose.call_args[0],
|
2022-04-20 20:24:17 +00:00
|
|
|
)
|