test(test_hyperlink_internal_alive_check): added test
This test checks all internal (to the site) links to ensure they are valid and the page exists. MR !5
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from conftest import Data
|
||||
|
||||
@ -6,6 +7,11 @@ class Test:
|
||||
|
||||
data = Data()
|
||||
|
||||
def setup_class(self):
|
||||
#copy data so it can be used
|
||||
self.source_files = self.data.test_data['source_files']
|
||||
|
||||
|
||||
def setup_method(self):
|
||||
pass
|
||||
|
||||
@ -37,7 +43,57 @@ class Test:
|
||||
f"Hyperlink [{data['url_id']}] to location [{data['url']}] failed,"
|
||||
f"with status [{request.status_code}].")
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
argnames='data',
|
||||
argvalues=[link for url_id, link in data.test_data['hyperlinks'].items() if link['request_protocol'][0:4] =='file' and link['request_path'] != ''],
|
||||
ids=[url_id for url_id, link in data.test_data['hyperlinks'].items() if link['request_protocol'][0:4] =='file' and link['request_path'] != '']
|
||||
)
|
||||
def test_hyperlink_internal_alive_check(self, data):
|
||||
""" Test all internal hyperlinks are valid and the page exists.
|
||||
|
||||
This test constructs the actual file path from a found internal (contains file as the protocol) link. After the link is found it is checked against the pages that exist.
|
||||
|
||||
Args:
|
||||
data (list): list of dictionaries containing the urls to test
|
||||
"""
|
||||
|
||||
path_suffix = os.path.realpath('./build')
|
||||
|
||||
print('URL Data:' + str(data))
|
||||
|
||||
request_path = str(data['request_path'])
|
||||
|
||||
if '#' in request_path:
|
||||
request_path_split = request_path.split('#')
|
||||
request_path = str(request_path_split[0])
|
||||
print('Debug # in path ' + request_path_split[0])
|
||||
|
||||
# Reconstruct a valid url. append 'index.html' for paths ending in '/'
|
||||
if (request_path[len(request_path)-1:] == '/'
|
||||
and request_path[len(request_path)-5:] != '.html'
|
||||
):
|
||||
|
||||
request_path = str(request_path) + 'index.html'
|
||||
|
||||
elif (request_path[len(request_path)-1:] != '/'
|
||||
and request_path[len(request_path)-5:] == '.html'
|
||||
):
|
||||
|
||||
request_path = request_path
|
||||
|
||||
request_path = request_path.replace('/' + path_suffix[1:] + '/','')
|
||||
request_path = request_path.replace(path_suffix[1:] + '/','')
|
||||
|
||||
print('DEBUG consructed path:' + request_path)
|
||||
|
||||
assert request_path in self.source_files, (
|
||||
f"hyperlink [{str(data['request_path'])}] that was reconstructed to[{request_path}] "
|
||||
"does not exist. This link was found "
|
||||
f"within the following pages [{str(data['source_files'])}]"
|
||||
)
|
||||
|
||||
|
||||
def teardown_method(self):
|
||||
pass
|
||||
|
||||
|
Reference in New Issue
Block a user