|
19 | 19 | import asyncio |
20 | 20 | from contextlib import asynccontextmanager |
21 | 21 | from pathlib import Path |
| 22 | +from secrets import token_hex |
22 | 23 | from types import SimpleNamespace |
23 | | -from uuid import uuid1 |
24 | 24 |
|
25 | 25 | import pytest |
26 | 26 |
|
27 | | -from cylc.flow.exceptions import ( |
28 | | - WorkflowFilesError, |
29 | | -) |
30 | | -from cylc.flow.install import ( |
31 | | - reinstall_workflow, |
32 | | -) |
| 27 | +from cylc.flow.exceptions import WorkflowFilesError |
| 28 | +from cylc.flow.install import reinstall_workflow |
33 | 29 | from cylc.flow.option_parsers import Options |
34 | 30 | from cylc.flow.scripts.reinstall import ( |
35 | 31 | get_option_parser as reinstall_gop, |
36 | 32 | reinstall_cli, |
37 | 33 | ) |
38 | | -from cylc.flow.workflow_files import ( |
39 | | - WorkflowFiles, |
40 | | -) |
| 34 | +from cylc.flow.workflow_files import WorkflowFiles |
41 | 35 |
|
42 | 36 | from .utils.entry_points import EntryPointWrapper |
43 | 37 |
|
| 38 | + |
44 | 39 | ReInstallOptions = Options(reinstall_gop()) |
45 | 40 |
|
46 | 41 | # cli opts |
@@ -77,7 +72,7 @@ def one_src(tmp_path): |
77 | 72 |
|
78 | 73 | @pytest.fixture |
79 | 74 | def one_run(one_src, test_dir, run_dir): |
80 | | - w_run_dir = test_dir / str(uuid1()) |
| 75 | + w_run_dir = test_dir / token_hex(4) |
81 | 76 | w_run_dir.mkdir() |
82 | 77 | (w_run_dir / 'flow.cylc').touch() |
83 | 78 | (w_run_dir / 'rose-suite.conf').touch() |
@@ -303,6 +298,35 @@ async def test_rsync_fail(one_src, one_run, mock_glbl_cfg, non_interactive): |
303 | 298 | assert 'An error occurred reinstalling' in str(exc_ctx.value) |
304 | 299 |
|
305 | 300 |
|
| 301 | +async def test_permissions_change( |
| 302 | + one_src, |
| 303 | + one_run, |
| 304 | + interactive, |
| 305 | + monkeypatch: pytest.MonkeyPatch, |
| 306 | + capsys: pytest.CaptureFixture, |
| 307 | +): |
| 308 | + """It detects permissions changes.""" |
| 309 | + # Add script file: |
| 310 | + script_path: Path = one_src.path / 'myscript' |
| 311 | + script_path.touch() |
| 312 | + await reinstall_cli( |
| 313 | + opts=ReInstallOptions(skip_interactive=True), workflow_id=one_run.id |
| 314 | + ) |
| 315 | + assert (one_run.path / 'myscript').is_file() |
| 316 | + capsys.readouterr() # clears capsys |
| 317 | + |
| 318 | + # Change permissions (e.g. user forgot to make it executable before) |
| 319 | + script_path.chmod(0o777) |
| 320 | + # Answer "no" to reinstall prompt (we just want to test dry run) |
| 321 | + monkeypatch.setattr('cylc.flow.scripts.reinstall._input', lambda x: 'n') |
| 322 | + monkeypatch.setattr('cylc.flow.flags.verbosity', 1) |
| 323 | + await reinstall_cli( |
| 324 | + opts=ReInstallOptions(), workflow_id=one_run.id |
| 325 | + ) |
| 326 | + out, _ = capsys.readouterr() |
| 327 | + assert "send myscript" in out |
| 328 | + |
| 329 | + |
306 | 330 | @pytest.fixture |
307 | 331 | def my_install_plugin(monkeypatch): |
308 | 332 | """This configures a single post_install plugin. |
|
0 commit comments