Skip to content

Commit

Permalink
remove user to prevent ForeignKeyViolation
Browse files Browse the repository at this point in the history
  • Loading branch information
amolpati30 committed Dec 16, 2024
1 parent ea1716d commit b3943d2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tests/foreman/api/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@pytest.fixture
def filtered_user(target_sat, module_org, module_location):
def filtered_user(request, target_sat, module_org, module_location):
"""
:steps:
1. Create a role with a host view filtered
Expand All @@ -31,6 +31,12 @@ def filtered_user(target_sat, module_org, module_location):
role = target_sat.api.Role(
name=gen_string('alpha'), location=[module_location], organization=[module_org]
).create()
password = gen_string('alpha')
user = target_sat.api.User(
role=[role], password=password, location=[module_location], organization=[module_org]
).create()
if is_open('SAT-18656'):
request.addfinalizer(user.delete)
# assign view_hosts (with a filter, to test BZ 1699188),
# view_hostgroups, view_facts permissions to the role
permission_hosts = target_sat.api.Permission().search(query={'search': 'name="view_hosts"'})
Expand All @@ -43,12 +49,6 @@ def filtered_user(target_sat, module_org, module_location):
).create()
target_sat.api.Filter(permission=permission_hostgroups, role=role).create()
target_sat.api.Filter(permission=permission_facts, role=role).create()

password = gen_string('alpha')
user = target_sat.api.User(
role=[role], password=password, location=[module_location], organization=[module_org]
).create()

return user, password


Expand Down Expand Up @@ -296,7 +296,6 @@ def test_positive_read_facts_with_filter(
host.organization = module_org
host.location = module_location
host.update(['organization', 'location'])

# gather ansible facts by running ansible roles on the host
host.play_ansible_roles()
if is_open('SAT-18656'):
Expand Down

0 comments on commit b3943d2

Please sign in to comment.