1212
1313"""
1414
15- from collections import defaultdict
16-
1715import pytest
1816import requests
1917
2018from robottelo .config import settings
2119from robottelo .logging import logger
2220
23-
21+ pages = [
22+ 'about' ,
23+ 'settings' ,
24+ 'bookmark' ,
25+ 'role' ,
26+ 'ldapauthentication' ,
27+ 'cloudinventory' ,
28+ 'ansiblevariables' ,
29+ 'ansibleroles' ,
30+ 'discoveryrule' ,
31+ 'global_parameter' ,
32+ 'oscapreport' ,
33+ 'oscappolicy' ,
34+ 'oscapcontent' ,
35+ 'jobtemplate' ,
36+ 'provisioningtemplate' ,
37+ 'partitiontable' ,
38+ 'operatingsystem' ,
39+ 'host' ,
40+ 'discoveredhosts' ,
41+ 'reporttemplate' ,
42+ 'configreport' ,
43+ 'jobinvocation' ,
44+ 'audit' ,
45+ 'factvalue' ,
46+ 'dashboard' ,
47+ ]
48+
49+
50+ @pytest .fixture (scope = 'module' )
51+ def session (module_target_sat ):
52+ """Helper function to create a session for testing documentation links."""
53+ with module_target_sat .ui_session () as session :
54+ yield session
55+
56+
57+ @pytest .mark .parametrize ('page' , pages )
2458@pytest .mark .e2e
25- def test_positive_documentation_links (target_sat ):
59+ def test_positive_documentation_links (module_target_sat , session , page ):
2660 """Verify that Satellite documentation links are working.
2761 Note: At the moment, the test doesn't support verifying links hidden behind a button.
2862 Currently, the only such link is on RH Cloud > Inventory Upload page.
@@ -36,69 +70,34 @@ def test_positive_documentation_links(target_sat):
3670
3771 :expectedresults: All the Documentation links present on Satellite are working
3872 """
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 ])
67- all_links = defaultdict (list )
68- 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- )
73+ sat_version = "." .join (module_target_sat .version .split ('.' )[0 :2 ])
74+ all_links = []
75+ broken_links = []
76+ page_object = getattr (session , page )
77+ if page == "host" :
78+ view = page_object .navigate_to (page_object , 'Register' )
79+ elif page == "oscappolicy" :
80+ view = page_object .navigate_to (page_object , 'New' )
81+ else :
82+ view = page_object .navigate_to (page_object , 'All' )
83+ # Get the doc links present on the page.
84+ all_links = view .documentation_links ()
85+ assert all_links , f"Couldn't find any documentation links on { page } page."
86+ logger .info (f"Following are the documentation links collected from Satellite: \n { all_links } " )
87+ for link in all_links :
88+ # Test stage docs url for Non-GA'ed Satellite
89+ if float (sat_version ) in settings .robottelo .sat_non_ga_versions :
90+ # The internal satellite doc url redirects to prod doc that is not available for Non-GA versions.
91+ # Get the end url first and then update it in later part of test.
92+ if module_target_sat .hostname in link :
93+ link = requests .get (link , verify = False ).url
94+ link = link .replace ('https://docs.redhat.com' , settings .robottelo .stage_docs_url )
95+ if requests .get (link , verify = False ).status_code != 200 :
96+ broken_links .append (link )
97+ logger .info (f"Following link on { page } page seems broken: \n { link } " )
98+ assert not broken_links , (
99+ f"There are broken documentation links on page \" { page } \" : \n { broken_links } "
100+ )
102101
103102
104103@pytest .mark .e2e
0 commit comments