def test__get_tags_used_in_content(self):
        JanitorTestModel.objects.create(
            content="<p><strong>Hi</strong><em>World</em></p>"
        )
        fs = FieldSanitizer(content_type=self.ct, field_name="content")
        fs.save()

        tags = sorted(_get_tags_used_in_content())
        self.assertEqual(tags, ['em', 'p', 'strong'])
 def test_default_clean(self):
     """Creates an instance of the test model with some sample content,
     then verifies that it gets cleaned upon saving.
     """
     fs = FieldSanitizer(content_type=self.ct, field_name="content")
     fs.save()
     obj = self.test_model(content=self.sample_content)
     obj.save()
     self.assertEqual(obj.content, self.cleaned_content)
     self.assertEqual(fs.app_name, 'tests')
     self.assertEqual(fs.model_name, 'janitortestmodel')
 def test_strip_content(self):
     """Adds an HTML comment to the class's sample content, then verifies
     that it gets removed.
     """
     fs = FieldSanitizer(
         content_type=self.ct,
         field_name="content",
         strip=True,
         strip_comments=True
     )
     fs.save()
     obj = self.test_model(content="<!-- Hello! -->" + self.sample_content)
     obj.save()
     self.assertEqual(obj.content, self.stripped_content)
    def test_default_object_data(self):
        """Tests that FieldSanitizer's default tags, attributes, and clean_args
        are in place.
        """
        fs = FieldSanitizer()
        self.assertEqual(fs.get_tags_list(), whitelists.basic_content_tags)
        self.assertEqual(fs.get_attributes_list(), whitelists.attributes)

        expected_args = {
            'styles': [],
            'attributes': [u'alt', u'class', u'href', u'id', u'src', u'title'],
            'strip': False,
            'strip_comments': True,
            'tags': [
                u'a', u'abbr', u'acronym', u'blockquote', u'cite', u'code',
                u'dd', u'del', u'dfn', u'dl', u'dt', u'em', u'h1', u'h2',
                u'h3', u'h4', u'h5', u'h6', u'hr', u'img', u'ins', u'kbd',
                u'li', u'ol', u'p', u'pre', u'q', u'samp', u'strong', u'ul'
            ]
        }
        self.assertEqual(fs.get_bleach_clean_args(), expected_args)
    def test_default_object_data(self):
        """Tests that FieldSanitizer's default tags, attributes, and clean_args
        are in place.
        """
        fs = FieldSanitizer()
        self.assertEqual(fs.get_tags_list(), whitelists.basic_content_tags)
        self.assertEqual(fs.get_attributes_list(), whitelists.attributes)

        expected_args = {
            'styles': [],
            'attributes': [u'alt', u'class', u'href', u'id', u'src', u'title'],
            'strip': False,
            'strip_comments': True,
            'tags': [
                u'a', u'abbr', u'acronym', u'blockquote', u'cite', u'code',
                u'dd', u'del', u'dfn', u'dl', u'dt', u'em', u'h1', u'h2',
                u'h3', u'h4', u'h5', u'h6', u'hr', u'img', u'ins', u'kbd',
                u'li', u'ol', u'p', u'pre', u'q', u'samp', u'strong', u'ul'
            ]
        }
        self.assertEqual(fs.get_bleach_clean_args(), expected_args)
 def test__unicode__(self):
     """Tests the FieldSanitizer.__unicode__ method."""
     fs = FieldSanitizer(content_type=self.ct, field_name="content")
     self.assertEqual(fs.__unicode__(), "Janitor Test Model - content")