mirror of
https://github.com/ansible-collections/community.routeros.git
synced 2025-06-28 04:20:13 +02:00
KeyInfo: prevent read_only usage with can_disable, remove_value, absent_value, default, or required (#265)
* Prevent read_only usage with can_disable, remove_value, absent_value, default, or required. * Add test.
This commit is contained in:
parent
84009262d0
commit
2ea1fef535
2 changed files with 6 additions and 0 deletions
|
@ -199,6 +199,8 @@ class KeyInfo(object):
|
||||||
raise ValueError('absent_value can not be combined with default, automatically_computed_from, can_disable=True, or absent_value')
|
raise ValueError('absent_value can not be combined with default, automatically_computed_from, can_disable=True, or absent_value')
|
||||||
if read_only and write_only:
|
if read_only and write_only:
|
||||||
raise ValueError('read_only and write_only cannot be used at the same time')
|
raise ValueError('read_only and write_only cannot be used at the same time')
|
||||||
|
if read_only and any([can_disable, remove_value is not None, absent_value is not None, default is not None, required]):
|
||||||
|
raise ValueError('read_only can not be combined with can_disable, remove_value, absent_value, default, or required')
|
||||||
self.can_disable = can_disable
|
self.can_disable = can_disable
|
||||||
self.remove_value = remove_value
|
self.remove_value = remove_value
|
||||||
self.automatically_computed_from = automatically_computed_from
|
self.automatically_computed_from = automatically_computed_from
|
||||||
|
|
|
@ -103,6 +103,10 @@ def test_key_info_errors():
|
||||||
KeyInfo(read_only=True, write_only=True)
|
KeyInfo(read_only=True, write_only=True)
|
||||||
assert exc.value.args[0] == 'read_only and write_only cannot be used at the same time'
|
assert exc.value.args[0] == 'read_only and write_only cannot be used at the same time'
|
||||||
|
|
||||||
|
with pytest.raises(ValueError) as exc:
|
||||||
|
KeyInfo(read_only=True, default=0)
|
||||||
|
assert exc.value.args[0] == 'read_only can not be combined with can_disable, remove_value, absent_value, default, or required'
|
||||||
|
|
||||||
|
|
||||||
SPLIT_PATHS = [
|
SPLIT_PATHS = [
|
||||||
('', [], ''),
|
('', [], ''),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue