Skip to content

Commit 4975ca9

Browse files
rene-slowenski-checkmkasyash26
authored andcommitted
Add skipped URLs to gui crawler test
* Add general logic to skip URLs in the gui crawler test. CMK-28477 Change-Id: I87524512f62748522125cccb60ded0c9533bb8cf
1 parent 9c441ac commit 4975ca9

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

tests/testlib/crawler.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
CrashIdRegex = r"\w{8}-\w{4}-\w{4}-\w{4}-\w{12}"
4242
CrashLinkRegex = rf"crash\.py\?crash_id=({CrashIdRegex})"
43+
SkipReason = str
44+
RelativeUrl = str
4345

4446

4547
class PageContent(NamedTuple):
@@ -184,7 +186,7 @@ def __init__(self, test_site: Site, report_file: str | None, max_urls: int = 0)
184186
"text/x-chdr",
185187
"text/x-sh",
186188
}
187-
189+
self._ignored_urls: dict[SkipReason, list[RelativeUrl]] = {}
188190
# override value using environment-variable
189191
maxlen = int(os.environ.get("GUI_CRAWLER_URL_LIMIT", "0")) or max_urls
190192
# limit minimum value to 0.
@@ -370,7 +372,12 @@ async def visit_url(
370372
url: Url,
371373
) -> bool:
372374
start = time.time()
373-
375+
relative_url = url.url.removeprefix(self.site.internal_url)
376+
if ignore_reason := next(
377+
(reason for reason, urls in self._ignored_urls.items() if relative_url in urls), None
378+
):
379+
self.handle_skipped_reference(url, reason="ignored url", message=ignore_reason)
380+
return self.handle_page_done(url, duration=time.time() - start)
374381
content_type = self.requests_session.head(url.url).headers["content-type"]
375382
if content_type.startswith("text/html"):
376383
try:

0 commit comments

Comments
 (0)