Skip to content

Commit

Permalink
Use fixtures instead of finalizers
Browse files Browse the repository at this point in the history
The teardown order was not correct
and host was not deleted before hostgroup
pytest-dev/pytest#10023 (comment)
  • Loading branch information
dosas committed Mar 28, 2024
1 parent e009caa commit 8854234
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions tests/foreman/api/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,51 @@
import pytest


@pytest.fixture
def param_name():
return gen_string('alpha')


@pytest.fixture
def param_value():
return gen_string('alpha')


@pytest.fixture
def cp(param_name, param_value, module_target_sat):
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):
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):
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
):
"""Check parameter precedences for Global, Hostgroup, and Host parameters
Expand All @@ -35,23 +75,11 @@ def test_positive_parameter_precedence_impact(
: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

0 comments on commit 8854234

Please sign in to comment.