mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
test_docs: Add test to check all images in integration docs.
Instead of a separate `test_integration_doc_images` function, the test is executed as part of `test_integration_doc_endpoints`, to optimize performance by re-using the doc response.
This commit is contained in:
@@ -321,7 +321,9 @@ class DocPageTest(ZulipTestCase):
|
||||
)
|
||||
|
||||
def test_integration_doc_endpoints(self) -> None:
|
||||
self._test(
|
||||
images_in_docs = set()
|
||||
|
||||
response = self._test(
|
||||
"/integrations/",
|
||||
expected_strings=[
|
||||
"native integrations.",
|
||||
@@ -330,10 +332,16 @@ class DocPageTest(ZulipTestCase):
|
||||
"IFTTT",
|
||||
],
|
||||
)
|
||||
page = response.content.decode("utf-8")
|
||||
for image in re.findall(r"/static/images/integrations/(logos/.*)\"", page):
|
||||
images_in_docs.add(image)
|
||||
|
||||
for integration in INTEGRATIONS:
|
||||
url = f"/integrations/doc-html/{integration}"
|
||||
self._test(url, expected_strings=[])
|
||||
response = self._test(url, expected_strings=[])
|
||||
doc = response.content.decode("utf-8")
|
||||
for image in re.findall(r"/static/images/integrations/(.*)\"", doc):
|
||||
images_in_docs.add(image)
|
||||
|
||||
result = self.client_get(
|
||||
"/integrations/doc-html/nonexistent_integration",
|
||||
@@ -342,6 +350,32 @@ class DocPageTest(ZulipTestCase):
|
||||
)
|
||||
self.assertEqual(result.status_code, 404)
|
||||
|
||||
directory = "static/images/integrations"
|
||||
images_in_dir = {
|
||||
image_path
|
||||
for root, _, files in os.walk(directory)
|
||||
for file in files
|
||||
if "bot_avatars"
|
||||
not in (image_path := os.path.relpath(os.path.join(root, file), directory))
|
||||
}
|
||||
|
||||
self.assertEqual(
|
||||
images_in_dir,
|
||||
images_in_docs,
|
||||
(
|
||||
"\n\nThe following images are not used in documentation and can be removed:\n"
|
||||
+ "\n".join(extra_images)
|
||||
if (extra_images := images_in_dir - images_in_docs)
|
||||
else ""
|
||||
)
|
||||
+ (
|
||||
"\n\nThe following images are used in documentation but do not exist:\n"
|
||||
+ "\n".join(missing_images)
|
||||
if (missing_images := images_in_docs - images_in_dir)
|
||||
else ""
|
||||
),
|
||||
)
|
||||
|
||||
def test_integration_pages_open_graph_metadata(self) -> None:
|
||||
og_description = '<meta property="og:description" content="Zulip comes with over'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user