Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyInfo: prevent read_only usage with can_disable, remove_value, absent_value, default, or required #265

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/module_utils/_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
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:
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')

Check warning on line 203 in plugins/module_utils/_api_data.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/_api_data.py#L203

Added line #L203 was not covered by tests
self.can_disable = can_disable
self.remove_value = remove_value
self.automatically_computed_from = automatically_computed_from
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/plugins/module_utils/test__api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def test_key_info_errors():
KeyInfo(read_only=True, write_only=True)
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 = [
('', [], ''),
Expand Down
Loading