Skip to content

Commit

Permalink
Add test coverage for SAT-28860
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Talreja <[email protected]>
  • Loading branch information
Gauravtalreja1 committed Dec 11, 2024
1 parent f1ca32b commit 66dd68e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
29 changes: 19 additions & 10 deletions pytest_fixtures/component/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ def session_auth_proxy(session_target_sat):
@pytest.fixture
def setup_http_proxy(request, module_manifest_org, target_sat):
"""Create a new HTTP proxy and set related settings based on proxy"""
content_proxy_value = target_sat.api.Setting().search(
query={'search': 'name=content_default_http_proxy'}
)[0]
general_proxy_value = target_sat.api.Setting().search(query={'search': 'name=http_proxy'})[0]

http_proxy = target_sat.api_factory.make_http_proxy(module_manifest_org, request.param)
general_proxy = http_proxy.url if request.param is False else ''
if request.param:
content_proxy = target_sat.api.Setting().search(
query={'search': 'name=content_default_http_proxy'}
)[0]
assert content_proxy.value == http_proxy.name

if request.param is not None:
general_proxy = (
f'http://{settings.http_proxy.username}:'
f'{settings.http_proxy.password}@{http_proxy.url[7:]}'
f'http://{settings.http_proxy.username}:{settings.http_proxy.password}@{http_proxy.url[7:]}'
if request.param
else http_proxy.url
)
content_proxy_value = target_sat.update_setting(
'content_default_http_proxy', http_proxy.name if request.param is not None else ''
)
general_proxy_value = target_sat.update_setting(
'http_proxy', general_proxy if request.param is not None else ''
)
target_sat.update_setting('http_proxy', general_proxy)
else:
target_sat.update_setting('content_default_http_proxy', '')
target_sat.update_setting('http_proxy', '')

yield http_proxy, request.param
target_sat.update_setting('content_default_http_proxy', content_proxy_value)
target_sat.update_setting('http_proxy', general_proxy_value)
Expand Down
2 changes: 2 additions & 0 deletions robottelo/host_helpers/api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def make_http_proxy(self, org, http_proxy_type):
name=gen_string('alpha', 15),
url=settings.http_proxy.un_auth_proxy_url,
organization=[org.id],
default_content_http_proxy=True,
).create()
if http_proxy_type:
return self._satellite.api.HTTPProxy(
Expand All @@ -46,6 +47,7 @@ def make_http_proxy(self, org, http_proxy_type):
username=settings.http_proxy.username,
password=settings.http_proxy.password,
organization=[org.id],
default_content_http_proxy=True,
).create()
return None

Expand Down
49 changes: 48 additions & 1 deletion tests/foreman/ui/test_http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def test_positive_assign_http_proxy_to_products_repositories(
@pytest.mark.tier1
@pytest.mark.run_in_one_thread
@pytest.mark.parametrize('setting_update', ['content_default_http_proxy'], indirect=True)
def test_set_default_http_proxy(module_org, module_location, setting_update, target_sat):
def test_set_default_http_proxy_no_global_default(
module_org, module_location, setting_update, target_sat
):
"""Setting "Default HTTP proxy" to "no global default".
:id: e93733e1-5c05-4b7f-89e4-253b9ce55a5a
Expand Down Expand Up @@ -244,6 +246,51 @@ def test_set_default_http_proxy(module_org, module_location, setting_update, tar
assert result['table'][0]['Value'] == "Empty"


@pytest.mark.tier1
@pytest.mark.run_in_one_thread
@pytest.mark.parametrize('setting_update', ['content_default_http_proxy'], indirect=True)
def test_positive_set_default_http_proxy(
request, module_org, module_location, setting_update, target_sat
):
"""Setting "Default HTTP proxy" when new HTTP proxy is created.
:id: e93733e1-5c05-4b7f-89e4-253b9ce55a5b
:steps:
1. Navigate to Infrastructure > Http Proxies
2. Create a Http Proxy and set "Default content HTTP proxy"
3. Navigate to Administer > Settings > Content tab
4. Verify the "Default HTTP Proxy" setting with created above.
5. Update "Default HTTP Proxy" to "no global default".
:Verifies: SAT-28860
:expectedresults: Creating Http Proxy with option "Default content HTTP proxy",
updates setting "Default HTTP Proxy" succesfully.
"""
property_name = setting_update.name
http_proxy_name = gen_string('alpha', 15)
http_proxy_url = settings.http_proxy.un_auth_proxy_url

with target_sat.ui_session() as session:
session.http_proxy.create(
{
'http_proxy.name': http_proxy_name,
'http_proxy.url': http_proxy_url,
'http_proxy.default_content_http_proxy': 'true',
'locations.resources.assigned': [module_location.name],
'organizations.resources.assigned': [module_org.name],
}
)
request.addfinalizer(
lambda: target_sat.api.HTTPProxy()
.search(query={'search': f'name={http_proxy_name}'})[0]
.delete()
)
result = session.settings.read(f'name = {property_name}')
assert result['table'][0]['Value'] == f'{http_proxy_name} ({http_proxy_url})'


@pytest.mark.tier1
@pytest.mark.run_in_one_thread
@pytest.mark.parametrize('setting_update', ['content_default_http_proxy'], indirect=True)
Expand Down

0 comments on commit 66dd68e

Please sign in to comment.