diff --git a/src/rougail_tests/__pycache__/utils.cpython-313.pyc b/src/rougail_tests/__pycache__/utils.cpython-313.pyc deleted file mode 100644 index 3e1e43a..0000000 Binary files a/src/rougail_tests/__pycache__/utils.cpython-313.pyc and /dev/null differ diff --git a/src/rougail_tests/utils.py b/src/rougail_tests/utils.py index daa3ba5..5ab0371 100644 --- a/src/rougail_tests/utils.py +++ b/src/rougail_tests/utils.py @@ -32,7 +32,7 @@ def get_rougail_config(test_dir, namespace=False): extras = list(test_dir.iterdir()) extras.sort() for extra in extras: - if extra.name in ['rougail', 'rougail2']: + if extra.name in ['rougail', 'rougail2', 'file']: continue if extra.is_dir(): extra_dictionaries[extra.name] = [str(extra)] @@ -47,19 +47,23 @@ def get_rougail_config(test_dir, namespace=False): return rougailconfig -def get_values_for_config(config, specify_dynamic_id=True, level="all"): +def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unrestraint=True): # level is "all" or "mandatories" + if use_unrestraint: + uconfig = config.unrestraint + else: + uconfig = config excludes = [] - get_excludes(config.unrestraint, excludes) + get_excludes(uconfig, excludes) config.property.read_only() - root_config = config.unrestraint + root_config = uconfig if level == 'all': only = False else: only = True values = {} - get_variables(root_config, root_config, values, only, excludes, specify_dynamic_id) + get_variables(root_config, root_config, values, only, excludes, specify_dynamic_id, use_unrestraint) if not specify_dynamic_id: for exclude in excludes: _values = values @@ -85,7 +89,7 @@ def get_excludes(config, excludes): get_excludes(option, excludes) -def get_value(variable, index, excludes): +def get_value(variable, index, excludes, config, use_unrestraint): if 'force_store_value' in variable.property.get(): return variable.value.get() tests = variable.information.get('test', None) @@ -118,13 +122,31 @@ def get_value(variable, index, excludes): tests = ['192.168.1.6/32', '10.0.10.0/24'] else: tests = ['192.168.1.6', '10.0.10.10'] + elif variable.type() == 'email address': + tests = ["user1@domain1.lan", "user2@domain1.lan"] + elif variable.type() == 'file name': + tests = ["/directory1/file.txt", "/directory2/file.txt"] + elif variable.type() == 'URL': + tests = ['http://domain1.lan', 'https://domain2.lan'] + elif variable.type() == 'password': + password = 'onE7vaLues_len1' + if variable.extra('max_len'): + password = password[:variable.extra('max_len')] + tests = [password] else: tests = ['string1', 'string2', 'string3'] if not variable.ismulti(): tests = tests[0] elif index is not None and variable.isfollower() and variable.issubmulti() is False: - tests = tests[index] + if len(tests) > index: + tests = tests[index] + else: + tests = tests[0] + if not use_unrestraint: + config.property.read_write() variable.value.set(tests) + if not use_unrestraint: + config.property.read_only() # if tests == None: # tests = "" if index is not None and variable.isleader(): @@ -132,8 +154,10 @@ def get_value(variable, index, excludes): return tests -def get_variables(root_config, config, values, only, excludes, specify_dynamic_id, *, index=None, leader_is_mandatory=False): +def get_variables(root_config, config, values, only, excludes, specify_dynamic_id, use_unrestraint, *, index=None, leader_is_mandatory=False): for idx, key in enumerate(config): + if not use_unrestraint and 'hidden' in key.property.get(): + continue if key.isoptiondescription(): if key.isleadership(): value = [] @@ -142,16 +166,19 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i leader_value = leader.value.get() leader_is_mandatory = False else: - leader_value = get_value(leader, None, excludes) + leader_value = get_value(leader, None, excludes, root_config, use_unrestraint) leader_is_mandatory = True + has_value = False for idx_, val in enumerate(leader_value): value.append({}) - get_variables(root_config, key, value[-1], only, excludes, specify_dynamic_id, index=idx_, leader_is_mandatory=leader_is_mandatory) - if value: + get_variables(root_config, key, value[-1], only, excludes, specify_dynamic_id, use_unrestraint, index=idx_, leader_is_mandatory=leader_is_mandatory) + if value[-1]: + has_value = True + if has_value: values[key.name()] = value else: value = {} - get_variables(root_config, key, value, only, excludes, specify_dynamic_id) + get_variables(root_config, key, value, only, excludes, specify_dynamic_id, use_unrestraint) if value: values[key.name()] = value else: @@ -166,7 +193,7 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i if not only or mandatory: if key.index() is not None and index is not None and index != key.index(): continue - value = get_value(key, index, excludes) + value = get_value(key, index, excludes, root_config, use_unrestraint) if specify_dynamic_id or key.path(uncalculated=True) not in excludes: values[key.name()] = value diff --git a/structures/00_6choice_link/rougail/00-base.yml b/structures/00_6choice_link/rougail/00-base.yml new file mode 100644 index 0000000..24e0839 --- /dev/null +++ b/structures/00_6choice_link/rougail/00-base.yml @@ -0,0 +1,12 @@ +--- +version: '1.1' +var1: + description: the first variable + choices: + - a + - b + - c +var2: + description: the second variable + default: + variable: _.var1 diff --git a/structures/00_6choice_variable_link/rougail/00-base.yml b/structures/00_6choice_variable_link/rougail/00-base.yml new file mode 100644 index 0000000..d05aa17 --- /dev/null +++ b/structures/00_6choice_variable_link/rougail/00-base.yml @@ -0,0 +1,15 @@ +--- +version: '1.1' +var1: # a second variable + - a + - b + - c +var2: + description: a first variable + default: a + choices: + variable: _.var1 +var3: + description: a third variable + default: + variable: _.var2 diff --git a/structures/00_6choice_variable_link2/rougail/00-base.yml b/structures/00_6choice_variable_link2/rougail/00-base.yml new file mode 100644 index 0000000..901e907 --- /dev/null +++ b/structures/00_6choice_variable_link2/rougail/00-base.yml @@ -0,0 +1,16 @@ +--- +version: '1.1' +var1: # a second variable + - a + - b + - c +var2: + description: a first variable + default: a + choices: + variable: _.var1 +family: + var3: + description: a third variable + default: + variable: __.var2 diff --git a/structures/00_6regexp_link/rougail/00-base.yml b/structures/00_6regexp_link/rougail/00-base.yml new file mode 100644 index 0000000..0d48004 --- /dev/null +++ b/structures/00_6regexp_link/rougail/00-base.yml @@ -0,0 +1,17 @@ +--- +version: '1.1' +var1: + description: a first variable + regexp: "^#(?:[0-9a-f]{3}){1,2}$" + default: "#a1a1a1" + test: + - "#b1b1b1" + - "#b2b2b2" + +var2: + description: a second variable + default: + variable: _.var1 + test: + - "#b2b1b1" + - "#b3b2b2" diff --git a/structures/00_6secret_param/rougail/00-base.yml b/structures/00_6secret_param/rougail/00-base.yml new file mode 100644 index 0000000..c2f0783 --- /dev/null +++ b/structures/00_6secret_param/rougail/00-base.yml @@ -0,0 +1,24 @@ +--- +version: '1.1' +secret1: + description: the first variable + type: secret + params: + min_len: 10 +secret2: + description: the second variable + type: secret + default: value + params: + max_len: 10 + forbidden_char: + - $ + - ^ +secret3: + description: the third variable + type: secret + default: value + params: + max_len: 10 + forbidden_char: + - $ diff --git a/structures/00_7help/rougail/00-base.yml b/structures/00_7help/rougail/00-base.yml new file mode 100644 index 0000000..2d2ab4c --- /dev/null +++ b/structures/00_7help/rougail/00-base.yml @@ -0,0 +1,18 @@ +--- +version: '1.1' +var1: + description: the first variable + help: |- + Multi line + + Help + + With useful information +var2: + description: the second variable + help: >- + Multi line + + Help + + With useful information diff --git a/structures/00_7help_sup/rougail/00-base.yml b/structures/00_7help_sup/rougail/00-base.yml new file mode 100644 index 0000000..e564658 --- /dev/null +++ b/structures/00_7help_sup/rougail/00-base.yml @@ -0,0 +1,18 @@ +--- +version: '1.1' +var1: + description: the first + help: |- + Multi line + + + + With useful information +var2: + description: the second + help: >- + Multi line + + + + With useful information diff --git a/structures/00_8calculation_namespace/force_namespace b/structures/00_8calculation_namespace/force_namespace new file mode 100644 index 0000000..e69de29 diff --git a/structures/00_8calculation_namespace/rougail/00-base.yml b/structures/00_8calculation_namespace/rougail/00-base.yml new file mode 100644 index 0000000..7545cf7 --- /dev/null +++ b/structures/00_8calculation_namespace/rougail/00-base.yml @@ -0,0 +1,7 @@ +--- +version: '1.1' +variable: + description: a variable + mandatory: false + default: + type: namespace diff --git a/structures/00_8calculation_param_namespace/force_namespace b/structures/00_8calculation_param_namespace/force_namespace new file mode 100644 index 0000000..e69de29 diff --git a/structures/00_8calculation_param_namespace/rougail/00-base.yml b/structures/00_8calculation_param_namespace/rougail/00-base.yml new file mode 100644 index 0000000..da4364f --- /dev/null +++ b/structures/00_8calculation_param_namespace/rougail/00-base.yml @@ -0,0 +1,10 @@ +--- +version: '1.1' +variable: + description: a variable + mandatory: false + default: + jinja: '{{ namespace }}' + params: + namespace: + type: namespace diff --git a/structures/16_3family_empty_at_ends/rougail/00-base.yml b/structures/16_3family_empty_at_ends/rougail/00-base.yml new file mode 100644 index 0000000..4e86152 --- /dev/null +++ b/structures/16_3family_empty_at_ends/rougail/00-base.yml @@ -0,0 +1,6 @@ +--- +version: '1.1' + +family: + + var1: diff --git a/structures/16_3family_empty_at_ends/rougail/01-base.yml b/structures/16_3family_empty_at_ends/rougail/01-base.yml new file mode 100644 index 0000000..d5fa21e --- /dev/null +++ b/structures/16_3family_empty_at_ends/rougail/01-base.yml @@ -0,0 +1,4 @@ +--- +version: 1.1 + +family: diff --git a/structures/40_0leadership_leader_follower/rougail/00-base.yml b/structures/40_0leadership_leader_follower/rougail/00-base.yml new file mode 100644 index 0000000..7f2bef3 --- /dev/null +++ b/structures/40_0leadership_leader_follower/rougail/00-base.yml @@ -0,0 +1,17 @@ +--- +version: 1.1 + +leadership: + description: a leadership + type: leadership + + leader: + description: a leader + default: + - value1 + - value2 + + follower: + description: a follower + default: + variable: _.leader diff --git a/structures/40_8calculation_multi_variable_parent2/rougail/00-base.yml b/structures/40_8calculation_multi_variable_parent2/rougail/00-base.yml index e890f42..cffd337 100644 --- a/structures/40_8calculation_multi_variable_parent2/rougail/00-base.yml +++ b/structures/40_8calculation_multi_variable_parent2/rougail/00-base.yml @@ -4,6 +4,6 @@ fam1: # first family var: "no" # a variable fam2: # second family var: - description: a varaible + description: a variable default: variable: __.fam1.var diff --git a/structures/40_9calculation_variable_leader_follower_multi_inside/errno_18 b/structures/40_9calculation_variable_leader_follower_multi_inside/errno_18 new file mode 100644 index 0000000..e69de29 diff --git a/structures/40_9calculation_variable_leader_follower_multi_inside/rougail/00-base.yml b/structures/40_9calculation_variable_leader_follower_multi_inside/rougail/00-base.yml new file mode 100644 index 0000000..eac853b --- /dev/null +++ b/structures/40_9calculation_variable_leader_follower_multi_inside/rougail/00-base.yml @@ -0,0 +1,17 @@ +--- +version: 1.1 + +leadership: + description: a leadership + type: leadership + + leader: + description: a leader + default: + - value1 + - value2 + + follower: + description: a follower + default: + - variable: _.leader diff --git a/structures/40_9leadership-calculation-outside-follower-no-mandatory/rougail/00-base.yml b/structures/40_9leadership-calculation-outside-follower-no-mandatory/rougail/00-base.yml new file mode 100644 index 0000000..76756a2 --- /dev/null +++ b/structures/40_9leadership-calculation-outside-follower-no-mandatory/rougail/00-base.yml @@ -0,0 +1,18 @@ +--- +version: 1.1 + +leader: + type: leadership + + leader: + default: + - a + - b + + follower: + mandatory: false + +variable: + mandatory: false + default: + variable: _.leader.follower diff --git a/structures/40_9leadership-calculation-variable/rougail/00-base.yml b/structures/40_9leadership-calculation-variable/rougail/00-base.yml new file mode 100644 index 0000000..6bde870 --- /dev/null +++ b/structures/40_9leadership-calculation-variable/rougail/00-base.yml @@ -0,0 +1,16 @@ +--- +version: '1.1' +calculate: + description: a calculated variable + default: + - value1 + - value2 +leader: + description: a leadership + type: leadership + leader: + description: a leader + default: + variable: __.calculate + follower1: val11 # a follower + follower2: val21 # an other follower diff --git a/structures/40_9leadership-calculation-variable_leader_follower/errno_21 b/structures/40_9leadership-calculation-variable_leader_follower/errno_21 new file mode 100644 index 0000000..e69de29 diff --git a/structures/40_9leadership-calculation-variable_leader_follower/rougail/00-base.yml b/structures/40_9leadership-calculation-variable_leader_follower/rougail/00-base.yml new file mode 100644 index 0000000..a223247 --- /dev/null +++ b/structures/40_9leadership-calculation-variable_leader_follower/rougail/00-base.yml @@ -0,0 +1,28 @@ +--- +version: 1.1 + +leadership_1: + description: a leadership + type: leadership + + leader: + description: a leader + default: + - value1 + - value2 + + follower: + description: a follower + +leadership_2: + description: a second leadership + type: leadership + + leader: + description: a leader + default: + variable: __.leadership_1.follower + + follower: + description: a follower + default: val diff --git a/structures/40_9leadership-calculation-variable_leader_follower_not_same/rougail/00-base.yml b/structures/40_9leadership-calculation-variable_leader_follower_not_same/rougail/00-base.yml new file mode 100644 index 0000000..f73bf1b --- /dev/null +++ b/structures/40_9leadership-calculation-variable_leader_follower_not_same/rougail/00-base.yml @@ -0,0 +1,30 @@ +--- +version: 1.1 + +leadership_1: + description: a leadership + type: leadership + + leader: + description: a leader + default: + - value1 + - value2 + + follower: + description: a follower + +leadership_2: + description: a second leadership + type: leadership + + leader: + description: a leader + default: + - value1 + - value2 + + follower: + description: a follower + default: + variable: __.leadership_1.leader diff --git a/structures/60_0family_dynamic_forbidden_char/rougail/00-base.yml b/structures/60_0family_dynamic_forbidden_char/rougail/00-base.yml new file mode 100644 index 0000000..7574848 --- /dev/null +++ b/structures/60_0family_dynamic_forbidden_char/rougail/00-base.yml @@ -0,0 +1,23 @@ +--- +version: '1.1' + +var: # A suffix variable + - val.1 + - val.2 + +"dyn{{ identifier }}": + description: A dynamic family + dynamic: + variable: _.var + var1: + description: A dynamic variable + default: + type: identifier + var2: + description: A dynamic variable + default: + jinja: >- + {{ identifier }} + params: + identifier: + type: identifier diff --git a/structures/60_0family_dynamic_upper_char/rougail/00-base.yml b/structures/60_0family_dynamic_upper_char/rougail/00-base.yml new file mode 100644 index 0000000..64b2f15 --- /dev/null +++ b/structures/60_0family_dynamic_upper_char/rougail/00-base.yml @@ -0,0 +1,12 @@ +--- +version: '1.1' + +var: # A suffix variable + - Val1 + - VAL2 + +"dyn{{ identifier }}": + description: A dynamic family + dynamic: + variable: _.var + var: # A dynamic variable diff --git a/structures/60_5family_dynamic_calc_suffix_disabled2/force_namespace b/structures/60_5family_dynamic_calc_suffix_disabled2/force_namespace new file mode 100644 index 0000000..e69de29 diff --git a/structures/60_5family_dynamic_calc_suffix_disabled2/rougail/00-base.yml b/structures/60_5family_dynamic_calc_suffix_disabled2/rougail/00-base.yml new file mode 100644 index 0000000..3e7abb0 --- /dev/null +++ b/structures/60_5family_dynamic_calc_suffix_disabled2/rougail/00-base.yml @@ -0,0 +1,24 @@ +--- +version: '1.1' + +var1: + description: A suffix variable + multi: true + mandatory: false + test: + - val1 + - val2 + +"dyn{{ identifier }}": + dynamic: + variable: _.var1 + + var: + description: A dynamic variable + disabled: true + +var2: + description: A variable calculated + default: + variable: rougail.dynval1.var + optional: true diff --git a/structures/60_5family_dynamic_calc_suffix_empty_3/force_namespace b/structures/60_5family_dynamic_calc_suffix_empty_3/force_namespace new file mode 100644 index 0000000..e69de29 diff --git a/structures/60_5family_dynamic_calc_suffix_empty_3/rougail/00-base.yml b/structures/60_5family_dynamic_calc_suffix_empty_3/rougail/00-base.yml new file mode 100644 index 0000000..0616e94 --- /dev/null +++ b/structures/60_5family_dynamic_calc_suffix_empty_3/rougail/00-base.yml @@ -0,0 +1,23 @@ +--- +version: '1.1' + +var2: + description: A variable calculated + default: + variable: rougail.dynval1.var + optional: true + +var1: + description: A suffix variable + multi: true + mandatory: false + test: + - val1 + - val2 + +"dyn{{ identifier }}": + dynamic: + variable: _.var1 + + var: + description: A dynamic variable diff --git a/structures/60_6family_dynamic_suffix_auto_multi/force_namespace b/structures/60_6family_dynamic_suffix_auto_multi/force_namespace new file mode 100644 index 0000000..e69de29 diff --git a/structures/60_6family_dynamic_suffix_auto_multi/rougail/00-base.yml b/structures/60_6family_dynamic_suffix_auto_multi/rougail/00-base.yml new file mode 100644 index 0000000..4690983 --- /dev/null +++ b/structures/60_6family_dynamic_suffix_auto_multi/rougail/00-base.yml @@ -0,0 +1,25 @@ +--- +version: 1.1 + +var1: + description: A suffix variable + default: + - val1 + - val2 + +dyn{{ identifier }}: + dynamic: + variable: _.var1 + + dyn{{ identifier }}: + dynamic: + variable: __.var1 + + var: + description: A dynamic variable + +var2: + description: A variable calculated + unique: false + default: + variable: rougail.dyn{{ identifier }}.dynval1.var diff --git a/structures/60_6family_dynamic_suffix_auto_multi2/force_namespace b/structures/60_6family_dynamic_suffix_auto_multi2/force_namespace new file mode 100644 index 0000000..e69de29 diff --git a/structures/60_6family_dynamic_suffix_auto_multi2/rougail/00-base.yml b/structures/60_6family_dynamic_suffix_auto_multi2/rougail/00-base.yml new file mode 100644 index 0000000..7931bd7 --- /dev/null +++ b/structures/60_6family_dynamic_suffix_auto_multi2/rougail/00-base.yml @@ -0,0 +1,25 @@ +--- +version: 1.1 + +var1: + description: A suffix variable + default: + - val1 + - val2 + +dyn{{ identifier }}: + dynamic: + variable: _.var1 + + dyn{{ identifier }}: + dynamic: + variable: __.var1 + + var: + description: A dynamic variable + +var2: + description: A variable calculated + unique: false + default: + variable: rougail.dynval1.dyn{{ identifier }}.var diff --git a/structures/60_9extra_dynamic_extra/extra/00-base.yml b/structures/60_9extra_dynamic_extra/extra/00-base.yml index 4670394..0cb47ed 100644 --- a/structures/60_9extra_dynamic_extra/extra/00-base.yml +++ b/structures/60_9extra_dynamic_extra/extra/00-base.yml @@ -1,6 +1,6 @@ --- version: '1.1' -var: # a varaible +var: # a variable - a "dyn_{{ identifier }}": dynamic: