Skip to content

Commit b4197cd

Browse files
committed
Add test for cylc reinstall with permissions changed
1 parent 51d8919 commit b4197cd

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

tests/integration/test_reinstall.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,23 @@
1919
import asyncio
2020
from contextlib import asynccontextmanager
2121
from pathlib import Path
22+
from secrets import token_hex
2223
from types import SimpleNamespace
23-
from uuid import uuid1
2424

2525
import pytest
2626

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
3329
from cylc.flow.option_parsers import Options
3430
from cylc.flow.scripts.reinstall import (
3531
get_option_parser as reinstall_gop,
3632
reinstall_cli,
3733
)
38-
from cylc.flow.workflow_files import (
39-
WorkflowFiles,
40-
)
34+
from cylc.flow.workflow_files import WorkflowFiles
4135

4236
from .utils.entry_points import EntryPointWrapper
4337

38+
4439
ReInstallOptions = Options(reinstall_gop())
4540

4641
# cli opts
@@ -77,7 +72,7 @@ def one_src(tmp_path):
7772

7873
@pytest.fixture
7974
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)
8176
w_run_dir.mkdir()
8277
(w_run_dir / 'flow.cylc').touch()
8378
(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):
303298
assert 'An error occurred reinstalling' in str(exc_ctx.value)
304299

305300

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+
306330
@pytest.fixture
307331
def my_install_plugin(monkeypatch):
308332
"""This configures a single post_install plugin.

0 commit comments

Comments
 (0)