2020from robottelo .config import settings
2121from robottelo .logging import logger
2222
23-
23+ pages = [
24+ 'about' ,
25+ 'settings' ,
26+ 'bookmark' ,
27+ 'role' ,
28+ 'ldapauthentication' ,
29+ 'cloudinventory' ,
30+ 'ansiblevariables' ,
31+ 'ansibleroles' ,
32+ 'discoveryrule' ,
33+ 'global_parameter' ,
34+ 'oscapreport' ,
35+ 'oscappolicy' ,
36+ 'oscapcontent' ,
37+ 'jobtemplate' ,
38+ 'provisioningtemplate' ,
39+ 'partitiontable' ,
40+ 'operatingsystem' ,
41+ 'host' ,
42+ 'discoveredhosts' ,
43+ 'reporttemplate' ,
44+ 'configreport' ,
45+ 'jobinvocation' ,
46+ 'audit' ,
47+ 'factvalue' ,
48+ 'dashboard' ,
49+ ]
50+
51+
52+ @pytest .fixture (scope = 'module' )
53+ def session (module_target_sat ):
54+ """Helper function to create a session for testing documentation links."""
55+ with module_target_sat .ui_session () as session :
56+ yield session
57+
58+
59+ @pytest .mark .parametrize ('page' , pages )
2460@pytest .mark .e2e
25- def test_positive_documentation_links (target_sat ):
61+ def test_positive_documentation_links (module_target_sat , session , page ):
2662 """Verify that Satellite documentation links are working.
2763 Note: At the moment, the test doesn't support verifying links hidden behind a button.
2864 Currently, the only such link is on RH Cloud > Inventory Upload page.
@@ -36,69 +72,35 @@ def test_positive_documentation_links(target_sat):
3672
3773 :expectedresults: All the Documentation links present on Satellite are working
3874 """
39- pages = [
40- 'about' ,
41- 'settings' ,
42- 'bookmark' ,
43- 'role' ,
44- 'ldapauthentication' ,
45- 'cloudinventory' ,
46- 'ansiblevariables' ,
47- 'ansibleroles' ,
48- 'discoveryrule' ,
49- 'global_parameter' ,
50- 'oscapreport' ,
51- 'oscappolicy' ,
52- 'oscapcontent' ,
53- 'jobtemplate' ,
54- 'provisioningtemplate' ,
55- 'partitiontable' ,
56- 'operatingsystem' ,
57- 'host' ,
58- 'discoveredhosts' ,
59- 'reporttemplate' ,
60- 'configreport' ,
61- 'jobinvocation' ,
62- 'audit' ,
63- 'factvalue' ,
64- 'dashboard' ,
65- ]
66- sat_version = "." .join (target_sat .version .split ('.' )[0 :2 ])
75+ sat_version = "." .join (module_target_sat .version .split ('.' )[0 :2 ])
6776 all_links = defaultdict (list )
6877 pages_with_broken_links = defaultdict (list )
69- with target_sat .ui_session () as session :
70- for page in pages :
71- page_object = getattr (session , page )
72- if page == "host" :
73- view = page_object .navigate_to (page_object , 'Register' )
74- elif page == "oscappolicy" :
75- view = page_object .navigate_to (page_object , 'New' )
76- else :
77- view = page_object .navigate_to (page_object , 'All' )
78- # Get the doc links present on the page.
79- all_links [page ] = view .documentation_links ()
80- assert all_links [page ], f"Couldn't find any documentation links on { page } page."
81- logger .info (
82- f"Following are the documentation links collected from Satellite: \n { all_links } "
83- )
84- for page in pages :
85- for link in all_links [page ]:
86- # Test stage docs url for Non-GA'ed Satellite
87- if float (sat_version ) in settings .robottelo .sat_non_ga_versions :
88- # The internal satellite doc url redirects to prod doc that is not available for Non-GA versions.
89- # Get the end url first and then update it in later part of test.
90- if target_sat .hostname in link :
91- link = requests .get (link , verify = False ).url
92- link = link .replace (
93- 'https://docs.redhat.com' , settings .robottelo .stage_docs_url
94- )
95- link = link .replace ('html' , 'html-single' )
96- if requests .get (link , verify = False ).status_code != 200 :
97- pages_with_broken_links [page ].append (link )
98- logger .info (f"Following link on { page } page seems broken: \n { link } " )
99- assert not pages_with_broken_links , (
100- f"There are Satellite pages with broken documentation links. \n { print (pages_with_broken_links )} "
101- )
78+ page_object = getattr (session , page )
79+ if page == "host" :
80+ view = page_object .navigate_to (page_object , 'Register' )
81+ elif page == "oscappolicy" :
82+ view = page_object .navigate_to (page_object , 'New' )
83+ else :
84+ view = page_object .navigate_to (page_object , 'All' )
85+ # Get the doc links present on the page.
86+ all_links [page ] = view .documentation_links ()
87+ assert all_links [page ], f"Couldn't find any documentation links on { page } page."
88+ logger .info (f"Following are the documentation links collected from Satellite: \n { all_links } " )
89+ for link in all_links [page ]:
90+ # Test stage docs url for Non-GA'ed Satellite
91+ if float (sat_version ) in settings .robottelo .sat_non_ga_versions :
92+ # The internal satellite doc url redirects to prod doc that is not available for Non-GA versions.
93+ # Get the end url first and then update it in later part of test.
94+ if module_target_sat .hostname in link :
95+ link = requests .get (link , verify = False ).url
96+ link = link .replace ('https://docs.redhat.com' , settings .robottelo .stage_docs_url )
97+ # link = link.replace('html', 'html-single')
98+ if requests .get (link , verify = False ).status_code != 200 :
99+ pages_with_broken_links [page ].append (link )
100+ logger .info (f"Following link on { page } page seems broken: \n { link } " )
101+ assert not pages_with_broken_links , (
102+ f"There are Satellite pages with broken documentation links. \n { print (pages_with_broken_links )} "
103+ )
102104
103105
104106@pytest .mark .e2e
0 commit comments