Anonymous avatar Anonymous committed 65041f8

HTML field tests of input that shouldn't change

Comments (0)

Files changed (2)

tests/testapp/forms.py

 
 ALLOWED_TAGS = ['a', 'em', 'h1', 'h2', 'p', 'strong']
 ALLOWED_ATTRIBUTES = ['class','id','style','title',]
-ALLOWED_STYLES = ['border','height','width',]
+ALLOWED_STYLES = {
+    '*': ['display', 'clear', 'text-align'],
+    'p': ['border*'],
+}
 ELEMENT_REPLACEMENTS = {
     'b': 'strong',
     'i': 'em',
     html = HTMLField(ALLOWED_TAGS, ALLOWED_ATTRIBUTES)
 
 class HTMLStylesForm(forms.Form):
-    html = HTMLField(ALLOWED_TAGS, allowed_styles=ALLOWED_STYLES)
+    html = HTMLField(ALLOWED_TAGS, ALLOWED_ATTRIBUTES, ALLOWED_STYLES)
 
 class HTMLEleReplaceForm(forms.Form):
     html = HTMLField(ALLOWED_TAGS, element_replacements=ELEMENT_REPLACEMENTS)

tests/testapp/tests.py

 """
 
 from django.test import TestCase
+from lxml import objectify
 from .forms import HoneypotForm, HoneypotInitForm, USCurrencyForm, CreditCardForm
 from .forms import HTMLForm, HTMLTagsForm, HTMLAttrsForm, HTMLStylesForm, HTMLEleReplaceForm
 
         form = HTMLForm(data)
         self.assertTrue(form.is_valid())
 
+    def test_tags_no_change(self):
+        input = '<p>Testing tags.</p>'
+        data = {
+            'html': input
+        }
+        form = HTMLTagsForm(data)
+        self.assertTrue(form.is_valid())
+        output = form.cleaned_data['html']
+        self.assertEqual(input, output)
+
+    def test_tags_removes_tags(self):
+        input = '<d>This should be without tags after.</d>'
+        data = {
+            'html': input
+        }
+        form = HTMLTagsForm(data)
+        self.assertTrue(form.is_valid())
+        output = form.cleaned_data['html']
+        self.assertEqual(input, output)
+
+    def test_attrs_no_change(self):
+        input = '<p class="example">Testing attributes.</p>'
+        data = {
+            'html': input
+        }
+        form = HTMLAttrsForm(data)
+        self.assertTrue(form.is_valid())
+        output = form.cleaned_data['html']
+        self.assertEqual(input, output)
+
+
+    def test_styles_no_change(self):
+        input = '<p style="border: 2px solid black;">Testing styles.</p>'
+        data = {
+            'html': input
+        }
+        form = HTMLStylesForm(data)
+        self.assertTrue(form.is_valid())
+        output = form.cleaned_data['html']
+        self.assertEqual(input, output)
+
+    def test_element_replace_no_change(self):
+        input = '<b>Testing element replacements.</b>'
+        data = {
+            'html': input
+        }
+        form = HTMLEleReplaceForm(data)
+        self.assertTrue(form.is_valid())
+        output = form.cleaned_data['html']
+        self.assertEqual(input, output)
 
 class USCurrencyFieldTests(TestCase):
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.