6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-11-15 09:44:07 +00:00
tutor/tests/commands/test_local.py
Régis Behmo 27449f4068 feat: add dev/local copyfrom commands
`copyfrom` copies data from a container to the local filesystem. It's similar
to bindmount, but less clunky, and more intuitive. Also, it plays along great
with `--mount`. Eventually we'll just get rid of the `bindmount` command and
the `--volume` option.
2022-04-24 09:51:46 +02:00

69 lines
2.6 KiB
Python

import os
import tempfile
import unittest
from unittest.mock import patch
from tests.helpers import temporary_root
from .base import TestCommandMixin
class LocalTests(unittest.TestCase, TestCommandMixin):
def test_local_help(self) -> None:
result = self.invoke(["local", "--help"])
self.assertIsNone(result.exception)
self.assertEqual(0, result.exit_code)
def test_local_quickstart_help(self) -> None:
result = self.invoke(["local", "quickstart", "--help"])
self.assertIsNone(result.exception)
self.assertEqual(0, result.exit_code)
def test_local_upgrade_help(self) -> None:
result = self.invoke(["local", "upgrade", "--help"])
self.assertIsNone(result.exception)
self.assertEqual(0, result.exit_code)
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",
mock_docker_compose.call_args.args,
)
self.assertIn(
"cp --recursive --preserve /openedx/venv /tmp/mount",
mock_docker_compose.call_args.args,
)
# 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",
mock_docker_compose.call_args.args,
)
self.assertIn(
"cp --recursive --preserve /openedx/venv /tmp/mount/venv2",
mock_docker_compose.call_args.args,
)