Add tests

This commit is contained in:
Florent Lebreton
2013-09-19 16:23:57 +02:00
parent 5c17f753e7
commit a8ef50d8d0
6 changed files with 197 additions and 0 deletions

26
jsignature/tests/forms.py Normal file
View File

@@ -0,0 +1,26 @@
import json
import django
from django.test import SimpleTestCase
from django.core.exceptions import ValidationError
from ..widgets import JSignatureWidget
from ..forms import JSignatureField
class JSignatureFormFieldTest(SimpleTestCase):
def test_widget(self):
f = JSignatureField()
self.assertIsInstance(f.widget, JSignatureWidget)
def test_to_python(self):
f = JSignatureField()
# Empty values
for val in ['', [], '[]']:
self.assertIsNone(f.to_python(val))
# Correct values
val = '[{"x":[1,2], "y":[3,4]}]'
self.assertEquals([{'x':[1,2], 'y':[3,4]}], f.to_python(val))
# Incorrect values
val = 'foo'
self.assertRaises(ValidationError, f.to_python, val)