Commits

Matthew Schinckel committed 0ae5e6c

Add form field tests.
Fix broken .hgignore file.

Comments (0)

Files changed (4)

 MANIFEST
 build
 dist
-
-syntax: regexp
-.*\#.*\#$ 
 .test
 .tox
 .coverage

jsonfield/tests/__init__.py

 from .test_fields import *
-# from .test_forms import *
+from .test_forms import *

jsonfield/tests/jsonfield_test_app/forms.py

+from django import forms
+
+from jsonfield.forms import JSONFormField
+from .models import JSONFieldTestModel
+
+class JSONTestForm(forms.Form):
+    json_data = JSONFormField()
+    optional_json_data = JSONFormField(required=False)
+
+class JSONTestModelForm(forms.ModelForm):
+    class Meta:
+        model = JSONFieldTestModel

jsonfield/tests/test_forms.py

+from django.test import TestCase as DjangoTestCase
+from django.utils import unittest
+
+from jsonfield.forms import JSONFormField
+from jsonfield.tests.jsonfield_test_app.forms import JSONTestForm, JSONTestModelForm
+
+class JSONFormFieldTest(DjangoTestCase):
+    def test_form_field_clean(self):
+        field = JSONFormField(required=False)
+        self.assertEquals({}, field.clean('{}'))
+        
+        self.assertEquals(
+            {'foo':'bar', 'baz':2},
+            field.clean('{"foo":"bar","baz":2}')
+        )
+        
+        self.assertEquals([],field.clean('[]'))
+
+class JSONFormTest(DjangoTestCase):
+    def test_form_clean(self):
+        form = JSONTestForm({})
+        self.assertFalse(form.is_valid())