Skip to content

test(unit_test): check for broken links

Jon requested to merge (removed):7-unit-test-dead-links into development

📝 Notes

break this code up so that the fetching of hyperlinks is part of the data collection in conftest.py.

The unit test should just use the data.

def test_dead_link_check(self):

  good_http_status = [200, 302]

  for file_check in html_pages:

    with self.subTest(f"{check_file.replace('./build/','')}"):

      check_url = 'file://' + suffux_path + check_file.replace('./build','')

      self.driver.get(check_url)

      links =  driver.find_elements_by_css_selector("a")

        for link in links:

          with self.subTest(f"{link.get_attribute('href')}"):
            r = r equests.head(link.get_attribute('href'))

            self.assertTrue(r.status_code in good_http_status, 
                                      msg=f"page {} has a link to {link.get_attribute('href')} that returned http {r.status_code}")


          # print(link.get_attribute('href'), r.status_code)
  • test page load all resources

    • external page load resources - approved
  • all internal links - valid and work

test data structure from note in !15 (merged)

data  
  |--page_load_resource_links  
        |--{hash, protocol, domain, path, http_status, source_files[]}  
  |--source_files[]  
  |--hyperlinks
       |--{id, protocol, domain, path, http_status, source_file line_number}

found a working one load external request links: [link for key in data.page_load_resource_links for link in key['links']] if link['protocol'][0:4] == "http"

load all links [link for key in data.page_load_resource_links for link in key['links']]

🔗 References

  • Related #3

  • Closes #7

  • child of nofusscomputing/ops#41

👷 Tasks

  • Dead Link Check internal and external (Task from #7)

    all links from page must be checked to ensure they work

  • #7 closes in commit message

  • add a deploy stage after build stage and before test stage where a gitlab pages job runs to deploy the site.

    • only deploys when not on master branch

    • needs added to deploy job and test job so they are chained

  • update sitemap template to use the git updated date if module installed.

Edited by Jon

Merge request reports

Loading