-
Notifications
You must be signed in to change notification settings - Fork 138
docs links test improvements #20797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs links test improvements #20797
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,17 +12,51 @@ | |
|
|
||
| """ | ||
|
|
||
| from collections import defaultdict | ||
|
|
||
| import pytest | ||
| import requests | ||
|
|
||
| from robottelo.config import settings | ||
| from robottelo.logging import logger | ||
|
|
||
|
|
||
| pages = [ | ||
| 'about', | ||
| 'settings', | ||
| 'bookmark', | ||
| 'role', | ||
| 'ldapauthentication', | ||
| 'cloudinventory', | ||
| 'ansiblevariables', | ||
| 'ansibleroles', | ||
| 'discoveryrule', | ||
| 'global_parameter', | ||
| 'oscapreport', | ||
| 'oscappolicy', | ||
| 'oscapcontent', | ||
| 'jobtemplate', | ||
| 'provisioningtemplate', | ||
| 'partitiontable', | ||
| 'operatingsystem', | ||
| 'host', | ||
| 'discoveredhosts', | ||
| 'reporttemplate', | ||
| 'configreport', | ||
| 'jobinvocation', | ||
| 'audit', | ||
| 'factvalue', | ||
| 'dashboard', | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def session(module_target_sat): | ||
| """Helper function to create a session for testing documentation links.""" | ||
| with module_target_sat.ui_session() as session: | ||
| yield session | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('page', pages) | ||
| @pytest.mark.e2e | ||
| def test_positive_documentation_links(target_sat): | ||
| def test_positive_documentation_links(module_target_sat, session, page): | ||
| """Verify that Satellite documentation links are working. | ||
| Note: At the moment, the test doesn't support verifying links hidden behind a button. | ||
| Currently, the only such link is on RH Cloud > Inventory Upload page. | ||
|
|
@@ -36,69 +70,34 @@ def test_positive_documentation_links(target_sat): | |
|
|
||
| :expectedresults: All the Documentation links present on Satellite are working | ||
| """ | ||
| pages = [ | ||
| 'about', | ||
| 'settings', | ||
| 'bookmark', | ||
| 'role', | ||
| 'ldapauthentication', | ||
| 'cloudinventory', | ||
| 'ansiblevariables', | ||
| 'ansibleroles', | ||
| 'discoveryrule', | ||
| 'global_parameter', | ||
| 'oscapreport', | ||
| 'oscappolicy', | ||
| 'oscapcontent', | ||
| 'jobtemplate', | ||
| 'provisioningtemplate', | ||
| 'partitiontable', | ||
| 'operatingsystem', | ||
| 'host', | ||
| 'discoveredhosts', | ||
| 'reporttemplate', | ||
| 'configreport', | ||
| 'jobinvocation', | ||
| 'audit', | ||
| 'factvalue', | ||
| 'dashboard', | ||
| ] | ||
| sat_version = ".".join(target_sat.version.split('.')[0:2]) | ||
| all_links = defaultdict(list) | ||
| pages_with_broken_links = defaultdict(list) | ||
| with target_sat.ui_session() as session: | ||
| for page in pages: | ||
| page_object = getattr(session, page) | ||
| if page == "host": | ||
| view = page_object.navigate_to(page_object, 'Register') | ||
| elif page == "oscappolicy": | ||
| view = page_object.navigate_to(page_object, 'New') | ||
| else: | ||
| view = page_object.navigate_to(page_object, 'All') | ||
| # Get the doc links present on the page. | ||
| all_links[page] = view.documentation_links() | ||
| assert all_links[page], f"Couldn't find any documentation links on {page} page." | ||
| logger.info( | ||
| f"Following are the documentation links collected from Satellite: \n {all_links}" | ||
| ) | ||
| for page in pages: | ||
| for link in all_links[page]: | ||
| # Test stage docs url for Non-GA'ed Satellite | ||
| if float(sat_version) in settings.robottelo.sat_non_ga_versions: | ||
| # The internal satellite doc url redirects to prod doc that is not available for Non-GA versions. | ||
| # Get the end url first and then update it in later part of test. | ||
| if target_sat.hostname in link: | ||
| link = requests.get(link, verify=False).url | ||
| link = link.replace( | ||
| 'https://docs.redhat.com', settings.robottelo.stage_docs_url | ||
| ) | ||
| link = link.replace('html', 'html-single') | ||
| if requests.get(link, verify=False).status_code != 200: | ||
| pages_with_broken_links[page].append(link) | ||
| logger.info(f"Following link on {page} page seems broken: \n {link}") | ||
| assert not pages_with_broken_links, ( | ||
| f"There are Satellite pages with broken documentation links. \n {print(pages_with_broken_links)}" | ||
| ) | ||
| sat_version = ".".join(module_target_sat.version.split('.')[0:2]) | ||
| all_links = [] | ||
| broken_links = [] | ||
| page_object = getattr(session, page) | ||
| if page == "host": | ||
| view = page_object.navigate_to(page_object, 'Register') | ||
| elif page == "oscappolicy": | ||
| view = page_object.navigate_to(page_object, 'New') | ||
| else: | ||
| view = page_object.navigate_to(page_object, 'All') | ||
| # Get the doc links present on the page. | ||
| all_links = view.documentation_links() | ||
| assert all_links, f"Couldn't find any documentation links on {page} page." | ||
| logger.info(f"Following are the documentation links collected from Satellite: \n {all_links}") | ||
| for link in all_links: | ||
| # Test stage docs url for Non-GA'ed Satellite | ||
| if float(sat_version) in settings.robottelo.sat_non_ga_versions: | ||
| # The internal satellite doc url redirects to prod doc that is not available for Non-GA versions. | ||
| # Get the end url first and then update it in later part of test. | ||
| if module_target_sat.hostname in link: | ||
| link = requests.get(link, verify=False).url | ||
| link = link.replace('https://docs.redhat.com', settings.robottelo.stage_docs_url) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel instead of hardcoding this prod docs url here, we can move it to settings as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the same concern, but there's already some work going on within SAT-41490. The documentation portal can be customizable. I expect to modify this hardcoded part when creating new test(s) for this new feature. |
||
| if requests.get(link, verify=False).status_code != 200: | ||
| broken_links.append(link) | ||
| logger.info(f"Following link on {page} page seems broken: \n {link}") | ||
| assert not broken_links, ( | ||
| f"There are broken documentation links on page \"{page}\": \n {broken_links}" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.