Skip to content
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

[Help wanted] Add URL anchor breakage tests #1169

Open
1 task done
databyjp opened this issue Oct 2, 2023 · 2 comments
Open
1 task done

[Help wanted] Add URL anchor breakage tests #1169

databyjp opened this issue Oct 2, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@databyjp
Copy link
Contributor

databyjp commented Oct 2, 2023

Code of Conduct

What part of document/web-page on weaviate.io is affected?

We have CI pipeline tests for broken links. However, it is not possible for that test to currently check for broken in-page anchors.

The site already includes a suite of tests that can be run via pytest.

It would be great if a test could be added to our pytest suite, checking whether links to any in-page anchors are actually valid, so that they can be run periodically.

Additional comments?

A community contribution would be fantastic :).

@databyjp databyjp added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Oct 2, 2023
@ankur0904
Copy link

Hey @databyjp I want to work on this issue.

@ankur0904
Copy link

ankur0904 commented Nov 6, 2023

I have decided to create a new file here named test_in_page_anchors.py and add the logic of the unit test.

Basic Code:

import requests
import pytest

@pytest.mark.parametrize("url", [REQUIRED_URL])
def test_inpage_anchors(url):
    response = requests.get(url)
    assert response.status_code == 200

    anchor_links = set()
    for anchor in response.html.find("a"):
        href = anchor.attrs.get("href")
        if href and href.startswith("#"):
            anchor_links.add(href)

    for anchor_link in anchor_links:
        target_id = anchor_link[1:] 
        target_element = response.html.find(f"#{target_id}")
        assert target_element, f"Missing target element for {anchor_link}"

@databyjp What are your thoughts about this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants