From f3f10c6a486b1ce02849f668287a0c3c8dab9634 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Sat, 4 Aug 2018 12:52:56 +0200 Subject: [PATCH] Add 1x1 image to test_markdown.py --- tests/plugins/images/test_markdown.py | 76 ++++++++++++++++++++------- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/tests/plugins/images/test_markdown.py b/tests/plugins/images/test_markdown.py index 6c31b195..6c7106f6 100644 --- a/tests/plugins/images/test_markdown.py +++ b/tests/plugins/images/test_markdown.py @@ -1,45 +1,81 @@ +import base64 +from io import BytesIO + +from django.core.files.uploadedfile import InMemoryUploadedFile from tests.base import RequireRootArticleMixin, TestBase from wiki.core import markdown +from wiki.plugins.images import models class ImageMarkdownTests(RequireRootArticleMixin, TestBase): + def setUp(self): + super().setUp() + + self.image_revision = models.ImageRevision( + image=self._create_test_gif_file(), width=1, height=1 + ) + self.image = models.Image(article=self.root_article) + self.image.add_revision(self.image_revision) + self.assertEqual(1, self.image.id) + + def _create_test_gif_file(self): + # A black 1x1 gif + str_base64 = "R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" + filename = "test.gif" + data = base64.b64decode(str_base64) + filedata = BytesIO(data) + return InMemoryUploadedFile(filedata, None, filename, "image", len(data), None) + def test_before_and_after(self): md = markdown.ArticleMarkdown(article=self.root_article) - md_text = md.convert("before [image:1 align:left] after") - before_pos = md_text.index('before') - figure_pos = md_text.index('this is visual", md_text) + self.assertRegex( + md_text, r'
\s*this is visual\s*
' + ) md = markdown.ArticleMarkdown(article=self.root_article) - md_text = md.convert("[image:1 align:left]\n this is visual\n second line") + md_text = md.convert( + "[image:%s align:left]\n this is visual\n second line" % self.image.id + ) self.assertIn("this is visual\nsecond line", md_text) + self.assertRegex( + md_text, + r'
\s*this is visual\s*second line\s*
', + ) - def test_escape(self): + def check_escape(self, text_to_escape): md = markdown.ArticleMarkdown(article=self.root_article) - md_text = md.convert("`[image:1 align:left]`") + md_text = md.convert("`%s`" % text_to_escape) self.assertNotIn("