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

Use fixtures instead of finalizers #14568

Closed
Closed
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
74 changes: 57 additions & 17 deletions tests/foreman/api/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,84 @@
import pytest


@pytest.fixture
def param_name():
dosas marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to just use parametrization for the test and generate the name and value there. You can pass those variables to your other fixtures using request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Generate name string for common parameter and return to test cases"""
"""Generate name for common parameter"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Generate name for common parameter"""

return gen_string('alpha')


@pytest.fixture
def param_value():
dosas marked this conversation as resolved.
Show resolved Hide resolved
"""Generate value string for common parameter and return to test cases"""
"""Generate value for common parameter"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Generate value for common parameter"""

return gen_string('alpha')


@pytest.fixture
def cp(param_name, param_value, module_target_sat):
dosas marked this conversation as resolved.
Show resolved Hide resolved
"""Create common parameter object, yields it for test cases, delete object before teardown"""
"""Create common parameter"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Create common parameter"""

cp = module_target_sat.api.CommonParameter(name=param_name, value=param_value).create()

yield cp

cp.delete()


@pytest.fixture
def host(param_name, param_value, module_org, module_location, module_target_sat, cp, hostgroup):
dosas marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many parameters here appear to be unused.

Suggested change
def host(param_name, param_value, module_org, module_location, module_target_sat, cp, hostgroup):
def host(module_org, module_location, module_target_sat):

"""Create host object, yeilds it for test cases, delete object before teardown"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Create host object, yeilds it for test cases, delete object before teardown"""
"""Create host object, yields it for test cases, delete object before teardown"""

"""Create host"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Create host"""

host = module_target_sat.api.Host(organization=module_org, location=module_location).create()

yield host

host.delete()


@pytest.fixture
def hostgroup(param_name, param_value, module_org, module_target_sat):
dosas marked this conversation as resolved.
Show resolved Hide resolved
"""Create hostgroup object, yeilds it for test cases, delete object before teardown"""
"""Create hostgroup"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Create hostgroup"""

hg = module_target_sat.api.HostGroup(
organization=[module_org],
group_parameters_attributes=[{'name': param_name, 'value': param_value}],
).create()

yield hg

hg.delete()


@pytest.mark.tier1
@pytest.mark.e2e
@pytest.mark.upgrade
def test_positive_parameter_precedence_impact(
request, module_org, module_location, module_target_sat
request, host, hostgroup, cp, param_name, param_value
dosas marked this conversation as resolved.
Show resolved Hide resolved
):
"""Check parameter precedences for Global, Hostgroup, and Host parameters

:id: 8dd6c4e8-4ec9-4bee-8a04-f5788960979b

:steps:
:setup:
1. Create Global Parameter
2. Create host and verify global parameter is assigned
3. Create Host Group with parameter
4. Assign hostgroup to host created above and verify hostgroup parameter is assigned.
5. Add parameter on the host directly, and verify that this should take precedence

:steps:
1. Assign hostgroup to host created above and verify hostgroup parameter is assigned.
2. Add parameter on the host directly, and verify that this should take precedence
over Host group and Global Parameter

:expectedresults: Host parameter take precedence over hostgroup and global parameter,
and hostgroup take precedence over global parameter when there are no host parameters
"""
param_name = gen_string('alpha')
param_value = gen_string('alpha')

cp = module_target_sat.api.CommonParameter(name=param_name, value=param_value).create()
request.addfinalizer(cp.delete)
host = module_target_sat.api.Host(organization=module_org, location=module_location).create()
request.addfinalizer(host.delete)
result = [res for res in host.all_parameters if res['name'] == param_name]
assert result[0]['name'] == param_name
assert result[0]['associated_type'] == 'global'

hg = module_target_sat.api.HostGroup(
organization=[module_org],
group_parameters_attributes=[{'name': param_name, 'value': param_value}],
).create()
request.addfinalizer(hg.delete)
host.hostgroup = hg
host.hostgroup = hostgroup
host = host.update(['hostgroup'])
result = [res for res in host.all_parameters if res['name'] == param_name]
assert result[0]['name'] == param_name
Expand Down
Loading