refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
from __future__ import annotations
|
2023-01-06 18:02:17 +00:00
|
|
|
|
2022-07-25 13:58:49 +00:00
|
|
|
import typing as t
|
2022-04-15 08:51:19 +00:00
|
|
|
import unittest
|
2022-07-25 17:19:28 +00:00
|
|
|
from io import StringIO
|
|
|
|
from unittest.mock import patch
|
2022-04-15 08:51:19 +00:00
|
|
|
|
|
|
|
from click.exceptions import ClickException
|
2022-04-20 20:24:17 +00:00
|
|
|
|
2022-07-25 13:58:49 +00:00
|
|
|
from tutor import hooks
|
2022-04-15 08:51:19 +00:00
|
|
|
from tutor.commands import compose
|
2022-07-25 17:19:28 +00:00
|
|
|
from tutor.commands.local import LocalContext
|
2022-04-15 08:51:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ComposeTests(unittest.TestCase):
|
2022-07-25 13:58:49 +00:00
|
|
|
maxDiff = None # Ensure we can see long diffs of YAML files.
|
|
|
|
|
2022-04-15 08:51:19 +00:00
|
|
|
def test_mount_option_parsing(self) -> None:
|
|
|
|
param = compose.MountParam()
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
[("lms", "/path/to/edx-platform", "/openedx/edx-platform")],
|
|
|
|
param("lms:/path/to/edx-platform:/openedx/edx-platform"),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
[
|
|
|
|
("lms", "/path/to/edx-platform", "/openedx/edx-platform"),
|
|
|
|
("cms", "/path/to/edx-platform", "/openedx/edx-platform"),
|
|
|
|
],
|
|
|
|
param("lms,cms:/path/to/edx-platform:/openedx/edx-platform"),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
[
|
|
|
|
("lms", "/path/to/edx-platform", "/openedx/edx-platform"),
|
|
|
|
("cms", "/path/to/edx-platform", "/openedx/edx-platform"),
|
|
|
|
],
|
|
|
|
param("lms, cms:/path/to/edx-platform:/openedx/edx-platform"),
|
|
|
|
)
|
2022-04-21 15:43:44 +00:00
|
|
|
self.assertEqual(
|
|
|
|
[
|
|
|
|
("lms", "/path/to/edx-platform", "/openedx/edx-platform"),
|
|
|
|
("lms-worker", "/path/to/edx-platform", "/openedx/edx-platform"),
|
|
|
|
],
|
|
|
|
param("lms,lms-worker:/path/to/edx-platform:/openedx/edx-platform"),
|
|
|
|
)
|
2022-04-15 08:51:19 +00:00
|
|
|
with self.assertRaises(ClickException):
|
|
|
|
param("lms,:/path/to/edx-platform:/openedx/edx-platform")
|
2022-07-25 13:58:49 +00:00
|
|
|
|
2022-07-25 17:19:28 +00:00
|
|
|
@patch("sys.stdout", new_callable=StringIO)
|
|
|
|
def test_compose_local_tmp_generation(self, _mock_stdout: StringIO) -> None:
|
2022-07-25 13:58:49 +00:00
|
|
|
"""
|
2022-07-25 17:19:28 +00:00
|
|
|
Ensure that docker-compose.tmp.yml is correctly generated.
|
2022-07-25 13:58:49 +00:00
|
|
|
"""
|
|
|
|
param = compose.MountParam()
|
2022-07-25 17:19:28 +00:00
|
|
|
mount_args = (
|
2022-07-25 13:58:49 +00:00
|
|
|
# Auto-mounting of edx-platform to lms* and cms*
|
2022-07-25 17:19:28 +00:00
|
|
|
param.convert_implicit_form("/path/to/edx-platform"),
|
2022-07-25 13:58:49 +00:00
|
|
|
# Manual mounting of some other folder to mfe and lms
|
2022-07-25 17:19:28 +00:00
|
|
|
param.convert_explicit_form(
|
|
|
|
"mfe,lms:/path/to/something-else:/openedx/something-else"
|
|
|
|
),
|
2022-07-25 13:58:49 +00:00
|
|
|
)
|
2022-07-25 17:19:28 +00:00
|
|
|
# Mount volumes
|
|
|
|
compose.mount_tmp_volumes(mount_args, LocalContext(""))
|
2022-07-25 13:58:49 +00:00
|
|
|
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
compose_file: dict[str, t.Any] = hooks.Filters.COMPOSE_LOCAL_TMP.apply({})
|
|
|
|
actual_services: dict[str, t.Any] = compose_file["services"]
|
|
|
|
expected_services: dict[str, t.Any] = {
|
2022-07-25 13:58:49 +00:00
|
|
|
"cms": {"volumes": ["/path/to/edx-platform:/openedx/edx-platform"]},
|
|
|
|
"cms-worker": {"volumes": ["/path/to/edx-platform:/openedx/edx-platform"]},
|
|
|
|
"lms": {
|
|
|
|
"volumes": [
|
|
|
|
"/path/to/edx-platform:/openedx/edx-platform",
|
|
|
|
"/path/to/something-else:/openedx/something-else",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"lms-worker": {"volumes": ["/path/to/edx-platform:/openedx/edx-platform"]},
|
|
|
|
"mfe": {"volumes": ["/path/to/something-else:/openedx/something-else"]},
|
|
|
|
}
|
|
|
|
self.assertEqual(actual_services, expected_services)
|
|
|
|
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
compose_jobs_file = hooks.Filters.COMPOSE_LOCAL_JOBS_TMP.apply({})
|
|
|
|
actual_jobs_services = compose_jobs_file["services"]
|
|
|
|
expected_jobs_services: dict[str, t.Any] = {
|
2022-07-25 13:58:49 +00:00
|
|
|
"cms-job": {"volumes": ["/path/to/edx-platform:/openedx/edx-platform"]},
|
|
|
|
"lms-job": {"volumes": ["/path/to/edx-platform:/openedx/edx-platform"]},
|
|
|
|
}
|
|
|
|
self.assertEqual(actual_jobs_services, expected_jobs_services)
|