Skip to content

Commit

Permalink
Added a test for helper extract_images which subsequently also tests …
Browse files Browse the repository at this point in the history
…the helper create_picture_plugin
  • Loading branch information
leture committed Nov 27, 2023
1 parent ff9c2c5 commit 1023370
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
HAS_DJANGOCMS_TRANSLATIONS = False


try:
import djangocms_picture # noqa

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'djangocms_picture' is not used.
HAS_DJANGOCMS_PICTURE = True
except ImportError:
HAS_DJANGOCMS_PICTURE = False


class PluginActionsTestCase(TestFixture, BaseTestCase):

def get_custom_admin_url(self, plugin_class, name):
Expand Down Expand Up @@ -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='<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==">',
)

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,
'<cms-plugin alt="Image - unnamed file " title="Image - unnamed file" id="{}"></cms-plugin>'.format(
picture_plugin.id,
),
)

0 comments on commit 1023370

Please sign in to comment.