From 1023370a9ba59555c420d487ad683f155ea4e135 Mon Sep 17 00:00:00 2001 From: Steffen Jasper Date: Tue, 28 Nov 2023 00:22:23 +0100 Subject: [PATCH] Added a test for helper extract_images which subsequently also tests the helper create_picture_plugin --- tests/test_plugin.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index cc89d3583..62c2be9ff 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -40,6 +40,13 @@ HAS_DJANGOCMS_TRANSLATIONS = False +try: + import djangocms_picture # noqa + HAS_DJANGOCMS_PICTURE = True +except ImportError: + HAS_DJANGOCMS_PICTURE = False + + class PluginActionsTestCase(TestFixture, BaseTestCase): def get_custom_admin_url(self, plugin_class, name): @@ -1079,3 +1086,32 @@ def test_textfield_with_untranslatable_children(self): result = TextPlugin.set_translation_import_content(result, plugin) self.assertDictEqual(result, {child1.pk: ''}) + + +@unittest.skipUnless( + HAS_DJANGOCMS_PICTURE, + 'Optional dependency djangocms-picture for tests is not installed.', +) +class DjangoCMSPictureIntegrationTestCase(TestFixture, BaseTestCase): + def setUp(self): + super().setUp() + self.page = self.create_page('test page', template='page.html', language='en') + self.placeholder = self.get_placeholders(self.page, 'en').get(slot='content') + + def test_extract_images(self): + text_plugin = add_plugin( + self.placeholder, + 'TextPlugin', + 'en', + body='', + ) + + from djangocms_picture.models import Picture + picture_plugin = Picture.objects.order_by('-id')[0] + self.assertEqual(picture_plugin.parent.id, text_plugin.id) + self.assertEqual( + text_plugin.body, + ''.format( + picture_plugin.id, + ), + )