-
Notifications
You must be signed in to change notification settings - Fork 127
test clearing the host_owner setting after user deletion #19968
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 - here's some feedback:
- Consider capturing and restoring the original host_owner setting in teardown to ensure test isolation and avoid side effects on other tests.
- Rename test_positive_host_owner to something more descriptive (e.g., test_host_owner_setting_cleared_on_user_deletion) to clearly convey the behavior under test.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider capturing and restoring the original host_owner setting in teardown to ensure test isolation and avoid side effects on other tests.
- Rename test_positive_host_owner to something more descriptive (e.g., test_host_owner_setting_cleared_on_user_deletion) to clearly convey the behavior under test.
## Individual Comments
### Comment 1
<location> `tests/foreman/cli/test_user.py:585-588` </location>
<code_context>
+ :expectedresults: host_owner is cleared when the assigned user is deleted
+
+ """
+ user = target_sat.cli_factory.user()
+ target_sat.cli.Settings.set({'name': "host_owner", 'value': user['login']})
+ host_owner = target_sat.cli.Settings.list({'search': 'name=host_owner'})[0]
+ assert host_owner['value'] == user['login']
+ target_sat.cli.User.delete({'id': user['id']})
+ host_owner = target_sat.cli.Settings.list({'search': 'name=host_owner'})[0]
</code_context>
<issue_to_address>
**suggestion (testing):** Add cleanup for created user and settings to avoid test pollution.
Please add teardown steps or use fixtures to remove the created user and reset the host_owner setting after the test completes to prevent residual state from affecting other tests.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
tests/foreman/cli/test_user.py
Outdated
user = target_sat.cli_factory.user() | ||
target_sat.cli.Settings.set({'name': "host_owner", 'value': user['login']}) | ||
host_owner = target_sat.cli.Settings.list({'search': 'name=host_owner'})[0] | ||
assert host_owner['value'] == user['login'] |
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 (testing): Add cleanup for created user and settings to avoid test pollution.
Please add teardown steps or use fixtures to remove the created user and reset the host_owner setting after the test completes to prevent residual state from affecting other tests.
tests/foreman/cli/test_user.py
Outdated
""" | ||
user = target_sat.cli_factory.user() | ||
target_sat.cli.Settings.set({'name': "host_owner", 'value': user['login']}) |
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.
I think you need to set the type, whether it's Users
or Usergroups
. Something like:
target_sat.cli.Settings.set({'name': "host_owner", 'value': user['login']}) | |
target_sat.cli.Settings.set({'name': "host_owner", 'value': f'{user['login']}-Users'}) |
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.
seems it must be user['id']
|
PRT Result
|
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.
Looks fine based on the PR, left a suggestion but i'm not an expert with Python.
host_owner = target_sat.cli.Settings.list({'search': 'name=host_owner'})[0] | ||
assert host_owner['value'] == f'{user["id"]}-Users' | ||
target_sat.cli.User.delete({'id': user['id']}) | ||
host_owner = target_sat.cli.Settings.list({'search': 'name=host_owner'})[0] |
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.
What do you think of:
host_owner = target_sat.cli.Settings.list({'search': 'name=host_owner'})[0]
assert host_owner['value'] == '', f'Host owner is not cleared: {host_owner["value"]}'
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.
this is perfectly fine, but I'd like to clear the value if the assertion fails, hence the try except block
tests/foreman/cli/test_user.py
Outdated
try: | ||
assert host_owner['value'] == '' | ||
except AssertionError: | ||
target_sat.cli.Settings.set({'name': "host_owner", 'value': ''}) |
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.
Shouldn't this be under a finally
so it's cleared regardless of whether an exception is raised or not?
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.
hm, should be fine if it's not raised, though if there's some other exception kind finally is indeed better
:expectedresults: host_owner is cleared when the assigned user is deleted | ||
""" | ||
user = target_sat.cli_factory.user() |
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.
This is using the CLI, but wouldn't using the plain API be easier and faster?
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.
would be faster to execute, not sure if easier as the factory creates names for us. There are no strict rules for this, but since we are in the cli module for user, I opt to create user through cli :)
|
PRT Result
|
trigger: test-robottelo |
PRT Result
|
ah, prt won't pass until snap is out |
Problem Statement
to cover theforeman/foreman#10719
Solution
Related Issues