예제 #1
0
 def test_expand_db_attributes_for_frontend_with_missing_alt(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = FrontendImageEmbedHandler.expand_db_attributes({
         'id': 1,
         'format': 'left',
     })
     self.assertTagInHTML('<img class="richtext-image left" alt="" />', result, allow_extra_attrs=True)
예제 #2
0
 def test_expand_db_attributes_for_frontend_escapes_alt_text(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = FrontendImageEmbedHandler.expand_db_attributes({
         'id': 1,
         'alt': 'Arthur "two sheds" Jackson',
         'format': 'left',
     })
     self.assertIn('alt="Arthur &quot;two sheds&quot; Jackson"', result)
예제 #3
0
 def test_expand_db_attributes_escapes_alt_text(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {
             'id': 1,
             'alt': 'Arthur "two sheds" Jackson',
             'format': 'left'
         }, False)
     self.assertIn('alt="Arthur &quot;two sheds&quot; Jackson"', result)
예제 #4
0
 def test_expand_db_attributes_for_editor_with_missing_alt(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {'id': 1,
          'format': 'left'},
     )
     self.assertTagInHTML(
         '<img data-embedtype="image" data-id="1" data-format="left" data-alt="" '
         'class="richtext-image left" />', result, allow_extra_attrs=True)
예제 #5
0
 def test_expand_db_attributes_with_missing_alt(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {
             'id': 1,
             'format': 'left'
         }, False)
     self.assertIn('<img class="richtext-image left"', result)
     self.assertIn('alt=""', result)
예제 #6
0
 def test_expand_db_attributes_not_for_editor(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {'id': 1,
          'alt': 'test-alt',
          'format': 'left'},
         False
     )
     self.assertIn('<img class="richtext-image left"', result)
예제 #7
0
 def test_expand_db_attributes_for_editor_with_missing_alt(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {
             'id': 1,
             'format': 'left'
         }, )
     self.assertIn(
         '<img data-embedtype="image" data-id="1" data-format="left" '
         'data-alt="" class="richtext-image left"', result)
예제 #8
0
 def test_expand_db_attributes_for_frontend_with_missing_alt(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = FrontendImageEmbedHandler.expand_db_attributes({
         'id':
         1,
         'format':
         'left',
     })
     self.assertTagInHTML('<img class="richtext-image left" alt="" />',
                          result,
                          allow_extra_attrs=True)
예제 #9
0
 def test_get_db_attributes(self):
     soup = BeautifulSoup(
         '<b data-id="test-id" data-format="test-format" data-alt="test-alt">foo</b>',
         'html5lib'
     )
     tag = soup.b
     result = ImageEmbedHandler.get_db_attributes(tag)
     self.assertEqual(result,
                      {'alt': 'test-alt',
                       'id': 'test-id',
                       'format': 'test-format'})
예제 #10
0
 def test_expand_db_attributes_for_frontend_escapes_alt_text(self):
     Image.objects.create(id=1, title="Test", file=get_test_image_file())
     result = FrontendImageEmbedHandler.expand_db_attributes({
         "id":
         1,
         "alt":
         'Arthur "two sheds" Jackson',
         "format":
         "left",
     })
     self.assertIn('alt="Arthur &quot;two sheds&quot; Jackson"', result)
예제 #11
0
 def test_get_db_attributes(self):
     soup = BeautifulSoup(
         '<b data-id="test-id" data-format="test-format" data-alt="test-alt">foo</b>',
         'html5lib')
     tag = soup.b
     result = ImageEmbedHandler.get_db_attributes(tag)
     self.assertEqual(result, {
         'alt': 'test-alt',
         'id': 'test-id',
         'format': 'test-format'
     })
예제 #12
0
 def test_expand_db_attributes_for_editor(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {'id': 1,
          'alt': 'test-alt',
          'format': 'left'},
         True
     )
     self.assertIn(
         '<img data-embedtype="image" data-id="1" data-format="left" '
         'data-alt="test-alt" class="richtext-image left"', result
     )
예제 #13
0
 def test_expand_db_attributes_for_frontend(self):
     Image.objects.create(id=1, title="Test", file=get_test_image_file())
     result = FrontendImageEmbedHandler.expand_db_attributes({
         "id":
         1,
         "alt":
         "test-alt",
         "format":
         "left",
     })
     self.assertTagInHTML('<img class="richtext-image left" />',
                          result,
                          allow_extra_attrs=True)
예제 #14
0
 def test_expand_db_attributes_for_editor_escapes_alt_text(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {
             'id': 1,
             'alt': 'Arthur "two sheds" Jackson',
             'format': 'left'
         }, )
     self.assertIn(
         '<img data-embedtype="image" data-id="1" data-format="left" '
         'data-alt="Arthur &quot;two sheds&quot; Jackson" class="richtext-image left"',
         result)
     self.assertIn('alt="Arthur &quot;two sheds&quot; Jackson"', result)
예제 #15
0
    def test_expand_db_attributes_for_editor_escapes_alt_text(self):
        Image.objects.create(id=1, title='Test', file=get_test_image_file())
        result = ImageEmbedHandler.expand_db_attributes(
            {'id': 1,
             'alt': 'Arthur "two sheds" Jackson',
             'format': 'left'},
        )
        self.assertTagInHTML(
            '<img data-embedtype="image" data-id="1" data-format="left" '
            'data-alt="Arthur &quot;two sheds&quot; Jackson" class="richtext-image left" />',
            result, allow_extra_attrs=True)

        self.assertIn('alt="Arthur &quot;two sheds&quot; Jackson"', result)
예제 #16
0
 def test_expand_db_attributes_for_editor(self):
     Image.objects.create(id=1, title='Test', file=get_test_image_file())
     result = ImageEmbedHandler.expand_db_attributes(
         {
             'id': 1,
             'alt': 'test-alt',
             'format': 'left'
         }, )
     self.assertTagInHTML(
         '<img data-embedtype="image" data-id="1" data-format="left" '
         'data-alt="test-alt" class="richtext-image left" />',
         result,
         allow_extra_attrs=True)
예제 #17
0
 def test_expand_db_attributes_for_frontend_with_nonexistent_image(self):
     result = FrontendImageEmbedHandler.expand_db_attributes({'id': 0})
     self.assertEqual(result, '<img>')
예제 #18
0
 def test_expand_db_attributes_page_does_not_exist(self):
     result = ImageEmbedHandler.expand_db_attributes({'id': 0}, False)
     self.assertEqual(result, '<img>')
예제 #19
0
 def test_expand_db_attributes_for_frontend_with_nonexistent_image(self):
     result = FrontendImageEmbedHandler.expand_db_attributes({'id': 0})
     self.assertEqual(result, '<img alt="">')
예제 #20
0
 def test_expand_db_attributes_page_does_not_exist(self):
     result = ImageEmbedHandler.expand_db_attributes(
         {'id': 0},
         False
     )
     self.assertEqual(result, '<img>')