# -*- coding: utf-8 -*-

"""Tests for vumi.persist.fields."""

from twisted.trial.unittest import TestCase

from vumi.persist.fields import Field, ValidationError, Integer, Unicode


class TestInteger(TestCase):
    def test_unbounded(self):
        i = Integer()
        i.validate(5)
        i.validate(-3)
        self.assertRaises(ValidationError, i.validate, 5.0)
        self.assertRaises(ValidationError, i.validate, "5")

    def test_minimum(self):
        i = Integer(min=3)
        i.validate(3)
        i.validate(4)
        self.assertRaises(ValidationError, i.validate, 2)

    def test_maximum(self):
        i = Integer(max=5)
        i.validate(5)
        i.validate(4)
        self.assertRaises(ValidationError, i.validate, 6)


class TestUnicode(TestCase):
    def test_unicode(self):
        u = Unicode()
        u.validate(u"")
        u.validate(u"a")
        u.validate(u"æ")
        u.validate(u"foé")
        self.assertRaises(ValidationError, u.validate, "")
        self.assertRaises(ValidationError, u.validate, "foo")
        self.assertRaises(ValidationError, u.validate, 3)

@@ -137,14 +137,13 @@
 ort 
-Field,
+(%0A   
  Val
@@ -160,24 +160,419 @@
 or, 
-Integer, Unicode
+Field, FieldDescriptor, Integer, Unicode, ForeignKey,%0A    ForeignKeyDescriptor)%0A%0A%0Aclass TestBaseField(TestCase):%0A    def test_validate(self):%0A        f = Field()%0A        f.validate(%22foo%22)%0A        f.validate(object())%0A%0A    def test_get_descriptor(self):%0A        f = Field()%0A        descriptor = f.get_descriptor(%22foo%22)%0A        self.assertEqual(descriptor.key, %22foo%22)%0A        self.assertEqual(descriptor.field, f)
 %0A%0A%0Ac

Add tests for the Field class.