forked from E3SM-Project/mache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_permissions.py
More file actions
34 lines (27 loc) · 906 Bytes
/
test_permissions.py
File metadata and controls
34 lines (27 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import stat
from types import SimpleNamespace
from mache import permissions
def test_update_permissions_removes_group_write_bits(tmp_path, monkeypatch):
shared_dir = tmp_path / 'shared'
shared_dir.mkdir()
shared_file = shared_dir / 'data.txt'
shared_file.write_text('demo\n', encoding='utf-8')
shared_dir.chmod(0o775)
shared_file.chmod(0o664)
monkeypatch.setattr(
permissions.grp,
'getgrnam',
lambda _group: SimpleNamespace(gr_gid=os.getgid()),
)
monkeypatch.setattr(permissions.os, 'chown', lambda *_args: None)
permissions.update_permissions(
str(shared_dir),
'e3sm',
show_progress=False,
group_writable=False,
other_readable=True,
recursive=True,
)
assert stat.S_IMODE(shared_dir.stat().st_mode) == 0o755
assert stat.S_IMODE(shared_file.stat().st_mode) == 0o644