From 5892dac9fc491b8b0f4f415ebf2af6630ea26282 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Fri, 3 Jan 2025 05:42:51 +0530 Subject: [PATCH] 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. --- zerver/tests/test_docs.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index 949ba4e178..9b8611e3c9 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -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 = '