New Version
This commit is contained in:
@@ -5,6 +5,7 @@ import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
spec = importlib.util.spec_from_file_location('wizard', Path(__file__).resolve().parents[1] / 'setup.py')
|
||||
wizard = importlib.util.module_from_spec(spec)
|
||||
@@ -35,6 +36,28 @@ class SetupTests(unittest.TestCase):
|
||||
self.assertEqual(target.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(len(list(Path(folder).iterdir())), 1)
|
||||
|
||||
def test_rollback_success_and_failure(self):
|
||||
for fail in (False, True):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
(root / 'group_vars').mkdir()
|
||||
config = root / 'group_vars/all.yml'
|
||||
config.write_text('pve_logout_enabled: true\npve_realm: main.heim.lan\n')
|
||||
previous = Path.cwd()
|
||||
try:
|
||||
with patch.object(wizard, 'ROOT', root), patch.object(wizard.shutil, 'which', return_value='/test/ansible-playbook'), patch.object(wizard, 'ask', return_value='inventory.yml'), patch.object(wizard, 'yes', side_effect=[False, False, True]), patch.object(wizard.subprocess, 'run') as run:
|
||||
if fail:
|
||||
run.side_effect = subprocess.CalledProcessError(1, 'test')
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
wizard.rollback_logout()
|
||||
self.assertIn('pve_logout_enabled: true', config.read_text())
|
||||
else:
|
||||
wizard.rollback_logout()
|
||||
self.assertIn('pve_logout_enabled: false', config.read_text())
|
||||
self.assertNotIn('--ask-vault-pass', run.call_args.args[0])
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
|
||||
@unittest.skipUnless(shutil.which('ansible-vault'), 'ansible-vault not installed')
|
||||
def test_real_vault_roundtrip(self):
|
||||
payload = {'test': 'fake-test-value-with-umlaut-ä'}
|
||||
|
||||
Reference in New Issue
Block a user