50 lines
2.4 KiB
Python
50 lines
2.4 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
spec = importlib.util.spec_from_file_location('voice', Path(__file__).with_name('set-default-voice-permissions.py'))
|
|
voice = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(voice)
|
|
|
|
|
|
class DefaultVoiceTests(unittest.TestCase):
|
|
def test_group_only_change_and_safe_restart(self):
|
|
admin = ('staff', 'voicechat.admin', 1, 'global', 'global', 0, '{}')
|
|
parent = voice.global_grant('group.dr_access_user')
|
|
rows = {admin, parent, voice.global_grant(voice.WILDCARD), voice.global_grant(voice.PLAY[0])}
|
|
commands = []
|
|
|
|
def issue(command):
|
|
commands.append(command)
|
|
fields = command.split()
|
|
if fields[4] == 'set':
|
|
rows.add(voice.global_grant(fields[5]))
|
|
else:
|
|
self.assertTrue({voice.global_grant(node) for node in voice.PLAY} <= rows)
|
|
rows.remove(voice.global_grant(fields[5]))
|
|
|
|
self.assertEqual(voice.update(lambda: rows.copy(), issue, False)['status'], 'planned')
|
|
self.assertEqual(commands, [])
|
|
self.assertEqual(voice.update(lambda: rows.copy(), issue, True)['status'], 'verified')
|
|
self.assertEqual(rows, {admin, parent, *(voice.global_grant(node) for node in voice.PLAY)})
|
|
self.assertEqual(commands, [f'luckperms group default permission set {node} true' for node in voice.PLAY[1:]]
|
|
+ ['luckperms group default permission unset voicechat.*'])
|
|
voice.update(lambda: rows.copy(), lambda _: self.fail('unexpected replay command'), True)
|
|
|
|
def test_context_override_is_never_rewritten(self):
|
|
rows = {voice.global_grant(voice.WILDCARD), ('default', voice.PLAY[0], 0, 'global', 'nether', 0, '{}')}
|
|
with self.assertRaises(ValueError):
|
|
voice.update(lambda: rows.copy(), lambda _: self.fail('unexpected command'), True)
|
|
|
|
def test_readback_waits_for_command_and_rejects_unrelated_writes(self):
|
|
previous = {voice.global_grant(voice.WILDCARD)}
|
|
expected = set()
|
|
snapshots = iter([previous, previous, expected])
|
|
voice.wait_exact(lambda: next(snapshots), previous, expected, pause=lambda _: None)
|
|
with self.assertRaises(RuntimeError):
|
|
voice.wait_exact(lambda: {voice.global_grant('unexpected')}, previous, expected, pause=lambda _: None)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|

Staff