Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions test_sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from env import Env, env, env_
import pytest


def grab_all_links(htm: str):
Expand All @@ -9,10 +10,10 @@ def grab_all_links(htm: str):
# print(" ************** END-OF-Prettify ******************* ")

links = [link.get('href') for link in soup.find_all('a')
if link not in ['/', ""] # skip trash ones
if link not in ['/', ""] # skip trash ones
]
print(f"==>> Found {len(links)} links")
return links
return links[:10] # TODO : remove this limitation (10 links) after xfail demo


def link_to_full_url(env: Env, link: str):
Expand All @@ -30,19 +31,40 @@ def link_to_full_url(env: Env, link: str):
return env.host_url + link


def pytest_generate_tests(metafunc):
print("** pytest_generate_tests ** ")
# print(metafunc.fixturenames)
# def pytest_generate_tests(metafunc):
# print("** pytest_generate_tests ** ")
# # print(metafunc.fixturenames)
#
# if "link" in metafunc.fixturenames:
# htm = env_().get_endpoint('').text
# links = [link_to_full_url(env=env_(), link=link) for link in grab_all_links(htm)]
# print(links)
# metafunc.parametrize("link", links, ids=links)

if "link" in metafunc.fixturenames:
htm = env_().get_endpoint('').text
links = [link_to_full_url(env=env_(), link=link) for link in grab_all_links(htm)]
print(links)
metafunc.parametrize("link", links, ids=links)
xfail_urls = [
"https://www.w3.org/standards/",
"https://www.w3.org/WAI/",
"https://www.w3.org/",
"https://www.w3.org/participate/",
"https://www.w3.org/Security/",
"https://www.w3.org/Privacy/"
]


def url_to_param(url: str) -> pytest.param:
if url in xfail_urls:
return pytest.param(url, marks=pytest.mark.xfail)
else:
return pytest.param(url)


@pytest.mark.parametrize("link", [
url_to_param(link_to_full_url(env=env_(), link=link))
for link in grab_all_links(env_().get_endpoint('').text)
])
def test_link_valid(env, link: str):
print(f" >> testing link {link} --{link[-1]}")
assert ("on" in link) ### TODO : Remove after XFAIL demo
res = env.get(link)
assert res.status_code == 200

Expand All @@ -52,4 +74,3 @@ def test_link_valid(env, link: str):
for link in grab_all_links(htm):
# print(link)
print(link_to_full_url(env=env_(), link=link))