test: automate subnet CLI parameter scenarios#21283
Conversation
…ith multiple values
…ith key having multipart name
…ith key having invalid name separator
Reviewer's GuideAutomates previously stubbed subnet CLI parameter tests by turning them into real, data-driven CLI scenarios that create subnets, set parameters via File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Subnet creation and deletion logic is duplicated across the new tests; consider extracting a small helper/fixture to create a subnet and ensure it is always deleted (e.g., via a context manager or
try/finally) to avoid leaks on failures. - When locating parameters in
params, you currently useif param_name in parameter['name']; if parameter names can be similar, switching to an equality check (==) would make the tests more precise and less brittle. - In the negative separator test, asserting
len(params) == 0assumes there are no other parameters on the subnet; it would be more robust to assert specifically that no parameter withparam_nameexists inparams.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Subnet creation and deletion logic is duplicated across the new tests; consider extracting a small helper/fixture to create a subnet and ensure it is always deleted (e.g., via a context manager or `try/finally`) to avoid leaks on failures.
- When locating parameters in `params`, you currently use `if param_name in parameter['name']`; if parameter names can be similar, switching to an equality check (`==`) would make the tests more precise and less brittle.
- In the negative separator test, asserting `len(params) == 0` assumes there are no other parameters on the subnet; it would be more robust to assert specifically that no parameter with `param_name` exists in `params`.
## Individual Comments
### Comment 1
<location path="tests/foreman/cli/test_subnet.py" line_range="288-289" />
<code_context>
+ )
+ subnet_info = module_target_sat.cli.Subnet.info({'id': subnet['id']}, output_format='json')
+ params = subnet_info['parameters']
+ param = next(parameter for parameter in params if param_name in parameter['name'])
+ stored = param['value']
+ stored_str = str(stored).strip()
</code_context>
<issue_to_address>
**suggestion:** Use exact name matching instead of substring matching when locating the created parameter
Using `if param_name in parameter['name']` can match the wrong parameter when names share substrings (e.g. `param`, `param-1`, `param-2`). To avoid false positives and ensure the test validates the intended parameter, use exact matching: `parameter['name'] == param_name`.
```suggestion
params = subnet_info['parameters']
param = next(parameter for parameter in params if parameter['name'] == param_name)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| params = subnet_info['parameters'] | ||
| param = next(parameter for parameter in params if param_name in parameter['name']) |
There was a problem hiding this comment.
suggestion: Use exact name matching instead of substring matching when locating the created parameter
Using if param_name in parameter['name'] can match the wrong parameter when names share substrings (e.g. param, param-1, param-2). To avoid false positives and ensure the test validates the intended parameter, use exact matching: parameter['name'] == param_name.
| params = subnet_info['parameters'] | |
| param = next(parameter for parameter in params if param_name in parameter['name']) | |
| params = subnet_info['parameters'] | |
| param = next(parameter for parameter in params if parameter['name'] == param_name) |
…ith multiple parameters
c343cd9 to
dfedba1
Compare
|
trigger: test-robottelo |
|
PRT Result |
evgeni
left a comment
There was a problem hiding this comment.
I think I lean towards dropping these stubbed tests instead of implementing them, but not clicking "request changes" as I am not 100% sure.
| stored = param['value'] | ||
| stored_str = str(stored).strip() | ||
| assert stored_str == comma_value | ||
| module_target_sat.cli.Subnet.delete({'id': subnet['id']}) |
There was a problem hiding this comment.
if the assert fails, this won't be executed, leaving the subnet behind and possibly interfering with other tests.
you can add a finalizer instead (will need to add the request fixture too):
| module_target_sat.cli.Subnet.delete({'id': subnet['id']}) | |
| request.addfinalizer(lambda: module_target_sat.cli.Subnet.delete({'id': subnet['id']})) |
| @@ -278,10 +277,23 @@ def test_positive_create_with_parameter_and_multiple_values(): | |||
|
|
|||
| :BZ: 1426612 | |||
There was a problem hiding this comment.
this BZ is long closed and doesn't really relate to the things that we're testing here (it was just marked here as the test would fail before the BZ was fixed), so I think we can remove this marker from all tests.
| def test_positive_create_with_parameter_and_multiple_values(module_target_sat): | ||
| """Subnet parameters can be created with multiple values |
There was a problem hiding this comment.
I'm trying to understand what the intent was for this test in #4941. The name is "create_with_parameter_…" which implies the parameter should be already set during creation, but that's not possible, you can only set parameters on existing subnets. In #21127 you already removed test_positive_create_with_parameter as a duplicate of test_positive_subnet_CRUD_parameters and the only difference here is that the value contains a comma, which doesn't sound too useful to me?
One could interpret "multiple values" as "the value is an array" (we have parameter_type, which is not covered in tests for subnets at all), but then "multiple names" in the test below still makes no real sense?
Problem Statement
Subnet CLI parameter tests were stubbed, so subnet set-parameter behavior was not covered in automation.
Solution
Implemented those tests: make_subnet → set_parameter → info (JSON) → assert → delete subnet; negative case expects CLIReturnCodeError and empty parameters.
Related Issues