Skip to content

Commit 9569a96

Browse files
authored
Remove no_http_proxy parameter in HTTP Proxy testing (#19046)
* Refactor setup_http_proxy fixture * Remove no_http_proxy parameter for test_positive_repo_discovery
1 parent 95830aa commit 9569a96

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

pytest_fixtures/component/http_proxy.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,36 @@ def session_auth_proxy(session_target_sat):
1313
@pytest.fixture
1414
def setup_http_proxy(request, module_org, target_sat):
1515
"""Create a new HTTP proxy and set related settings based on proxy"""
16-
content_proxy = target_sat.api.Setting().search(
17-
query={'search': 'name=content_default_http_proxy'}
18-
)[0]
19-
content_proxy_value = '' if content_proxy.value is None else content_proxy.value
20-
general_proxy = target_sat.api.Setting().search(query={'search': 'name=http_proxy'})[0]
21-
general_proxy_value = '' if general_proxy.value is None else general_proxy.value
16+
proxy_settings = ['content_default_http_proxy', 'http_proxy']
17+
saved_proxies = list(
18+
map(
19+
lambda x: target_sat.api.Setting().search(query={'search': f'name={x}'})[0],
20+
proxy_settings,
21+
)
22+
)
2223

2324
http_proxy = target_sat.api_factory.make_http_proxy(module_org, request.param)
24-
content_proxy = target_sat.api.Setting().search(
25-
query={'search': 'name=content_default_http_proxy'}
26-
)[0]
27-
assert content_proxy.value == (http_proxy.name if request.param is not None else '')
2825

29-
if request.param is not None:
30-
general_proxy = (
31-
f'http://{settings.http_proxy.username}:{settings.http_proxy.password}@{http_proxy.url[7:]}'
26+
if request.param is None:
27+
target_sat.update_setting('content_default_http_proxy', '')
28+
target_sat.update_setting('http_proxy', '')
29+
else:
30+
content_proxy_setting = target_sat.api.Setting().search(
31+
query={'search': 'name=content_default_http_proxy'}
32+
)[0]
33+
assert content_proxy_setting.value == http_proxy.name
34+
protocol, hostname_port = http_proxy.url.split('://')
35+
general_proxy_url = (
36+
f'{protocol}://{settings.http_proxy.username}:{settings.http_proxy.password}@{hostname_port}'
3237
if request.param
3338
else http_proxy.url
3439
)
35-
target_sat.update_setting('http_proxy', general_proxy)
36-
else:
37-
target_sat.update_setting('content_default_http_proxy', '')
38-
target_sat.update_setting('http_proxy', '')
40+
target_sat.update_setting('http_proxy', general_proxy_url)
3941

4042
yield http_proxy, request.param
41-
target_sat.update_setting('content_default_http_proxy', content_proxy_value)
42-
target_sat.update_setting('http_proxy', general_proxy_value)
43+
44+
for setting in proxy_settings:
45+
target_sat.update_setting(setting, saved_proxies.pop(0).value)
4346
if http_proxy:
4447
http_proxy.delete()
4548

robottelo/hosts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,7 @@ def skip_yum_update_during_provisioning(self, template=None):
23372337

23382338
def update_setting(self, name, value):
23392339
"""changes setting value and returns the setting value before the change."""
2340+
value = value if value is not None else ''
23402341
setting = self.api.Setting().search(query={'search': f'name="{name}"'})[0]
23412342
default_setting_value = setting.value
23422343
if default_setting_value is None:

tests/foreman/ui/test_http_proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ def test_http_proxy_containing_special_characters(
467467
@pytest.mark.usefixtures('allow_repo_discovery')
468468
@pytest.mark.parametrize(
469469
'setup_http_proxy',
470-
[None, True, False],
470+
[True, False],
471471
indirect=True,
472-
ids=['no_http_proxy', 'auth_http_proxy', 'unauth_http_proxy'],
472+
ids=['auth_http_proxy', 'unauth_http_proxy'],
473473
)
474474
def test_positive_repo_discovery(setup_http_proxy, module_target_sat, module_org):
475475
"""Create repository via repo discovery under new product

0 commit comments

Comments
 (0)