110 lines
3.4 KiB
Python
110 lines
3.4 KiB
Python
import os
|
|
from pathlib import Path
|
|
from rougail import Rougail, RougailConfig
|
|
from rougail.error import DictConsistencyError
|
|
#########################
|
|
from rougail.user_data_bitwarden import RougailUserDataBitwarden as RougailUserData
|
|
from json import load, dump
|
|
#########################
|
|
from pytest import raises
|
|
|
|
|
|
from rougail_tests.utils import config_to_dict
|
|
|
|
|
|
test_dir = Path(__file__).parent / 'structures'
|
|
|
|
|
|
def _test_dictionaries(test_dir):
|
|
rougailconfig = RougailConfig.copy()
|
|
rougailconfig['main_dictionaries'] = [str(test_dir)]
|
|
# rougailconfig['tiramisu_cache'] = "cache.py"
|
|
rougailconfig['step.user_data'] = ['bitwarden']
|
|
rougail = Rougail(rougailconfig)
|
|
config = rougail.run()
|
|
# loads variables in the tiramisu config
|
|
errors = RougailUserData(config, rougailconfig=rougailconfig).run()
|
|
#expected output
|
|
config_dict = dict(config_to_dict(config.value.get()))
|
|
ok_file = Path('tests') / 'results' / test_dir.name / 'makedict' / 'bitwarden.json'
|
|
if not ok_file.is_file():
|
|
ok_file.parent.mkdir(parents=True, exist_ok=True)
|
|
with open(ok_file, 'a') as json_file:
|
|
dump(config_dict, json_file, indent=4)
|
|
with open(ok_file) as json_file:
|
|
expected = load(json_file)
|
|
errors_file = Path('tests') / 'results' / test_dir.name / 'errors' / 'bitwarden.json'
|
|
if not errors_file.is_file():
|
|
errors_file.parent.mkdir(parents=True, exist_ok=True)
|
|
with open(errors_file, 'a') as json_file:
|
|
dump(errors, json_file, indent=4)
|
|
with open(errors_file) as json_file:
|
|
expected_errors = load(json_file)
|
|
# expected_errors = {
|
|
# 'errors': [],
|
|
# 'warnings': [],
|
|
# }
|
|
assert expected_errors == errors
|
|
#
|
|
config.property.read_only()
|
|
assert expected == config_dict
|
|
|
|
|
|
def test_dictionaries_1_secret():
|
|
"tests the output"
|
|
_test_dictionaries(test_dir / '1_secret')
|
|
|
|
|
|
def test_dictionaries_2_username_secret():
|
|
"tests the output"
|
|
_test_dictionaries(test_dir / '2_username_secret')
|
|
|
|
|
|
def test_dictionaries_3_leadership_secret():
|
|
"tests the output"
|
|
_test_dictionaries(test_dir / '3_leadership_secret')
|
|
|
|
|
|
def test_dictionaries_3_leadership_secret_several():
|
|
"tests the output"
|
|
_test_dictionaries(test_dir / '3_leadership_secret_several')
|
|
|
|
|
|
def test_dictionaries_4_several_secrets():
|
|
"tests the output"
|
|
_test_dictionaries(test_dir / '4_several_secrets')
|
|
|
|
|
|
def test_dictionaries_5_default_value():
|
|
"tests the output"
|
|
with raises(DictConsistencyError) as err:
|
|
_test_dictionaries(test_dir / '5_default_value')
|
|
assert err.errno == 304
|
|
|
|
|
|
def test_dictionaries_6_leadership_secret_default_value():
|
|
"tests the output"
|
|
with raises(DictConsistencyError) as err:
|
|
_test_dictionaries(test_dir / '6_leadership_secret_default_value')
|
|
assert err.errno == 304
|
|
|
|
|
|
def test_dictionaries_6_leadership_secret_follower_variable():
|
|
"tests the output"
|
|
with raises(DictConsistencyError) as err:
|
|
_test_dictionaries(test_dir / '6_leadership_secret_follower_variable')
|
|
assert err.errno == 303
|
|
|
|
|
|
def test_dictionaries_8_multi_variable():
|
|
"tests the output"
|
|
with raises(DictConsistencyError) as err:
|
|
_test_dictionaries(test_dir / '8_multi_variable')
|
|
assert err.errno == 302
|
|
|
|
|
|
def test_dictionaries_9_unknown_type():
|
|
"tests the output"
|
|
with raises(DictConsistencyError) as err:
|
|
_test_dictionaries(test_dir / '9_unknown_type')
|
|
assert err.errno == 301
|