From 0ae88ff80939758efdcf690ba38a4cbdf9c4cc78 Mon Sep 17 00:00:00 2001 From: vasileios Date: Thu, 1 Jun 2023 09:37:14 +0200 Subject: [PATCH 01/60] [#1448] Added some tests for banner plugins --- src/open_inwoner/cms/banner/tests/__init__.py | 0 .../cms/banner/tests/test_plugin_banner.py | 76 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/open_inwoner/cms/banner/tests/__init__.py create mode 100644 src/open_inwoner/cms/banner/tests/test_plugin_banner.py diff --git a/src/open_inwoner/cms/banner/tests/__init__.py b/src/open_inwoner/cms/banner/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/open_inwoner/cms/banner/tests/test_plugin_banner.py b/src/open_inwoner/cms/banner/tests/test_plugin_banner.py new file mode 100644 index 0000000000..32c8cfb6f2 --- /dev/null +++ b/src/open_inwoner/cms/banner/tests/test_plugin_banner.py @@ -0,0 +1,76 @@ +import os + +from django.conf import settings +from django.core.files import File +from django.test import TestCase + +from filer.models.imagemodels import Image as FilerImage +from PIL import Image + +from open_inwoner.cms.tests import cms_tools +from open_inwoner.utils.test import temp_media_root + +from ..cms_plugins import BannerImagePlugin, BannerTextPlugin + + +@temp_media_root() +class TestBannerImage(TestCase): + def test_banner_image_is_rendered_in_plugin(self): + pil_image = Image.new("RGB", (10, 10)) + tmp_file_path = "{}/{}".format(settings.MEDIA_ROOT, "tmp.jpg") + pil_image.save(tmp_file_path, "JPEG") + + tmp_image_file = open(tmp_file_path, "rb") + file_obj = File(tmp_image_file) + instance = FilerImage() + instance.file.save("image.jpg", file_obj) + + html, context = cms_tools.render_plugin( + BannerImagePlugin, plugin_data={"image": instance} + ) + + self.assertIn(os.path.basename(instance.file.name), html) + self.assertIn('