class TestFormat(TestCase): def setUp(self): # test format self.format = Format('test name', 'test label', 'test classnames', 'test filter spec') # test image self.image = MagicMock() self.image.id = 0 def test_editor_attributes(self): result = self.format.editor_attributes(self.image, 'test alt text') self.assertEqual( result, 'data-embedtype="image" data-id="0" data-format="test name" data-alt="test alt text" ' ) def test_image_to_editor_html(self): result = self.format.image_to_editor_html(self.image, 'test alt text') self.assertRegex( result, '<img data-embedtype="image" data-id="0" data-format="test name" ' 'data-alt="test alt text" class="test classnames" src="[^"]+" width="1" height="1" alt="test alt text">', ) def test_image_to_editor_html_with_quoting(self): result = self.format.image_to_editor_html( self.image, 'Arthur "two sheds" Jackson') self.assertRegex( result, '<img data-embedtype="image" data-id="0" data-format="test name" ' 'data-alt="Arthur "two sheds" Jackson" class="test classnames" src="[^"]+" width="1" height="1" alt="Arthur "two sheds" Jackson">', ) def test_image_to_html_no_classnames(self): self.format.classnames = None result = self.format.image_to_html(self.image, 'test alt text') self.assertRegex( result, '<img src="[^"]+" width="1" height="1" alt="test alt text">') self.format.classnames = 'test classnames' def test_image_to_html_with_quoting(self): result = self.format.image_to_html(self.image, 'Arthur "two sheds" Jackson') self.assertRegex( result, '<img class="test classnames" src="[^"]+" width="1" height="1" alt="Arthur "two sheds" Jackson">' ) def test_get_image_format(self): register_image_format(self.format) result = get_image_format('test name') self.assertEqual(result, self.format)
class TestFormat(TestCase, WagtailTestUtils): def setUp(self): # test format self.format = Format("test name", "test label", "test classnames", "original") # test image self.image = Image.objects.create( title="Test image", file=get_test_image_file(), ) def test_editor_attributes(self): result = self.format.editor_attributes(self.image, "test alt text") self.assertEqual( result, { "data-alt": "test alt text", "data-embedtype": "image", "data-format": "test name", "data-id": self.image.pk, }, ) def test_image_to_editor_html(self): result = self.format.image_to_editor_html(self.image, "test alt text") self.assertTagInHTML( '<img data-embedtype="image" data-id="%d" data-format="test name" ' 'data-alt="test alt text" class="test classnames" ' 'width="640" height="480" alt="test alt text" >' % self.image.pk, result, allow_extra_attrs=True, ) def test_image_to_editor_html_with_quoting(self): result = self.format.image_to_editor_html( self.image, 'Arthur "two sheds" Jackson') expected_html = ( '<img data-embedtype="image" data-id="%d" data-format="test name" ' 'data-alt="Arthur "two sheds" Jackson" class="test classnames" ' 'width="640" height="480" alt="Arthur "two sheds" Jackson" >' % self.image.pk) self.assertTagInHTML(expected_html, result, allow_extra_attrs=True) def test_image_to_html_no_classnames(self): self.format.classnames = None result = self.format.image_to_html(self.image, "test alt text") self.assertTagInHTML( '<img width="640" height="480" alt="test alt text">', result, allow_extra_attrs=True, ) self.format.classnames = "test classnames" def test_image_to_html_with_quoting(self): result = self.format.image_to_html(self.image, 'Arthur "two sheds" Jackson') self.assertTagInHTML( '<img class="test classnames" width="640" height="480" ' 'alt="Arthur "two sheds" Jackson">', result, allow_extra_attrs=True, ) def test_get_image_format(self): register_image_format(self.format) result = get_image_format("test name") self.assertEqual(result, self.format)
class TestFormat(TestCase): def setUp(self): # test format self.format = Format( 'test name', 'test label', 'test classnames', 'test filter spec' ) # test image self.image = MagicMock() self.image.id = 0 def test_editor_attributes(self): result = self.format.editor_attributes( self.image, 'test alt text' ) self.assertEqual(result, 'data-embedtype="image" data-id="0" data-format="test name" data-alt="test alt text" ') def test_image_to_editor_html(self): result = self.format.image_to_editor_html( self.image, 'test alt text' ) self.assertRegex( result, '<img data-embedtype="image" data-id="0" data-format="test name" ' 'data-alt="test alt text" class="test classnames" src="[^"]+" width="1" height="1" alt="test alt text">', ) def test_image_to_editor_html_with_quoting(self): result = self.format.image_to_editor_html( self.image, 'Arthur "two sheds" Jackson' ) self.assertRegex( result, '<img data-embedtype="image" data-id="0" data-format="test name" ' 'data-alt="Arthur "two sheds" Jackson" class="test classnames" src="[^"]+" width="1" height="1" alt="Arthur "two sheds" Jackson">', ) def test_image_to_html_no_classnames(self): self.format.classnames = None result = self.format.image_to_html(self.image, 'test alt text') self.assertRegex( result, '<img src="[^"]+" width="1" height="1" alt="test alt text">' ) self.format.classnames = 'test classnames' def test_image_to_html_with_quoting(self): result = self.format.image_to_html(self.image, 'Arthur "two sheds" Jackson') self.assertRegex( result, '<img class="test classnames" src="[^"]+" width="1" height="1" alt="Arthur "two sheds" Jackson">' ) def test_get_image_format(self): register_image_format(self.format) result = get_image_format('test name') self.assertEqual(result, self.format)
class TestFormat(TestCase, WagtailTestUtils): def setUp(self): # test format self.format = Format( 'test name', 'test label', 'test classnames', 'original' ) # test image self.image = Image.objects.create( title="Test image", file=get_test_image_file(), ) def test_editor_attributes(self): result = self.format.editor_attributes( self.image, 'test alt text' ) self.assertEqual(result, {'data-alt': 'test alt text', 'data-embedtype': 'image', 'data-format': 'test name', 'data-id': self.image.pk}) def test_image_to_editor_html(self): result = self.format.image_to_editor_html( self.image, 'test alt text' ) self.assertTagInHTML( '<img data-embedtype="image" data-id="%d" data-format="test name" ' 'data-alt="test alt text" class="test classnames" ' 'width="640" height="480" alt="test alt text" >' % self.image.pk, result, allow_extra_attrs=True) def test_image_to_editor_html_with_quoting(self): result = self.format.image_to_editor_html( self.image, 'Arthur "two sheds" Jackson' ) expected_html = ( '<img data-embedtype="image" data-id="%d" data-format="test name" ' 'data-alt="Arthur "two sheds" Jackson" class="test classnames" ' 'width="640" height="480" alt="Arthur "two sheds" Jackson" >' % self.image.pk ) self.assertTagInHTML(expected_html, result, allow_extra_attrs=True) def test_image_to_html_no_classnames(self): self.format.classnames = None result = self.format.image_to_html(self.image, 'test alt text') self.assertTagInHTML( '<img width="640" height="480" alt="test alt text">', result, allow_extra_attrs=True) self.format.classnames = 'test classnames' def test_image_to_html_with_quoting(self): result = self.format.image_to_html(self.image, 'Arthur "two sheds" Jackson') self.assertTagInHTML( '<img class="test classnames" width="640" height="480" ' 'alt="Arthur "two sheds" Jackson">', result, allow_extra_attrs=True) def test_get_image_format(self): register_image_format(self.format) result = get_image_format('test name') self.assertEqual(result, self.format)