-
Notifications
You must be signed in to change notification settings - Fork 127
only add location if it is not already present #19985
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tests/foreman/ui/test_remoteexecution.py:223-225` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid conditionals in tests. ([`no-conditionals-in-tests`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/no-conditionals-in-tests))
<details><summary>Explanation</summary>Avoid complex code, like conditionals, in test functions.
Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:
* loops
* conditionals
Some ways to fix this:
* Use parametrized tests to get rid of the loop.
* Move the complex logic into helpers.
* Move the complex part into pytest fixtures.
> Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.
Software Engineering at Google / [Don't Put Logic in Tests](https://abseil.io/resources/swe-book/html/ch12.html#donapostrophet_put_logic_in_tests)
</details>
</issue_to_address>
### Comment 2
<location> `tests/foreman/ui/test_remoteexecution.py:223` </location>
<code_context>
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
@pytest.mark.parametrize(
'ui_user', [{'admin': True}, {'admin': False}], indirect=True, ids=['adminuser', 'nonadminuser']
)
def test_positive_run_custom_job_template(
session, module_org, default_location, target_sat, ui_user, rex_contenthost
):
"""Run a job template on a host
:id: 3a59eb15-67c4-46e1-ba5f-203496ec0b0c
:Setup: Create a working job template.
:steps:
1. Set remote_execution_connect_by_ip on host to true
2. Navigate to an individual host and click Run Job
3. Select the job and appropriate template
4. Run the job
:expectedresults: Verify the job was successfully ran against the host
:parametrized: yes
:bz: 2220965
:customerscenario: true
"""
hostname = rex_contenthost.hostname
if not any(loc.id == default_location.id for loc in ui_user.location):
ui_user.location.append(target_sat.api.Location(id=default_location.id))
ui_user.update(['location'])
job_template_name = gen_string('alpha')
with target_sat.ui_session() as session:
session.organization.select(module_org.name)
assert session.host.search(hostname)[0]['Name'] == hostname
session.jobtemplate.create(
{
'template.name': job_template_name,
'template.template_editor.rendering_options': 'Editor',
'template.template_editor.editor': '<%= input("command") %>',
'job.provider_type': 'Script',
'inputs': [{'name': 'command', 'required': True, 'input_type': 'User input'}],
}
)
assert session.jobtemplate.search(job_template_name)[0]['Name'] == job_template_name
session.jobinvocation.run(
{
'category_and_template.job_category': 'Miscellaneous',
'category_and_template.job_template_text_input': job_template_name,
'target_hosts_and_inputs.targets': hostname,
'target_hosts_and_inputs.command': 'ls',
}
)
job_description = f'{camelize(job_template_name.lower())} with inputs command="ls"'
session.jobinvocation.wait_job_invocation_state(
entity_name=job_description, host_name=hostname
)
status = session.jobinvocation.read(entity_name=job_description, host_name=hostname)
assert status['hosts'][0]['Status'] == 'Succeeded'
</code_context>
<issue_to_address>
**suggestion (code-quality):** Invert any/all to simplify comparisons ([`invert-any-all`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/invert-any-all/))
```suggestion
if all(loc.id != default_location.id for loc in ui_user.location):
```
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
hostname = rex_contenthost.hostname | ||
ui_user.location.append(target_sat.api.Location(id=default_location.id)) | ||
ui_user.update(['location']) | ||
if not any(loc.id == default_location.id for loc in ui_user.location): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Invert any/all to simplify comparisons (invert-any-all
)
if not any(loc.id == default_location.id for loc in ui_user.location): | |
if all(loc.id != default_location.id for loc in ui_user.location): |
trigger: test-robottelo |
PRT Result
|
Problem Statement
In dualstack runs this caused Validation failed: Taxonomy has already been taken
Solution
Prt probably won't pass due to some other work being in progress on the ui part of the test, will try though
Related Issues