Exemple #1
0
 def test_validate(self):
     """
     By default, a SetOf field is a set of Unicode fields.
     """
     f = SetOf()
     f.validate(set([u'foo', u'bar']))
     self.assertRaises(ValidationError, f.validate, u'this is not a set')
     self.assertRaises(ValidationError, f.validate, set(['a', 2]))
     self.assertRaises(ValidationError, f.validate, [u'a', u'b'])
Exemple #2
0
 def test_validate(self):
     """
     By default, a SetOf field is a set of Unicode fields.
     """
     f = SetOf()
     f.validate(set([u'foo', u'bar']))
     self.assertRaises(ValidationError, f.validate, u'this is not a set')
     self.assertRaises(ValidationError, f.validate, set(['a', 2]))
     self.assertRaises(ValidationError, f.validate, [u'a', u'b'])
Exemple #3
0
    def test_validate_with_subtype(self):
        """
        If an explicit subtype is provided, its validation is used.
        """
        setof_unicode = SetOf(Unicode())
        setof_unicode.validate(set([u"a", u"b"]))
        self.assertRaises(ValidationError, setof_unicode.validate, set([1, 2]))

        setof_int = SetOf(Integer())
        setof_int.validate(set([1, 2]))
        self.assertRaises(
            ValidationError, setof_int.validate, set([u"a", u"b"]))

        setof_smallint = SetOf(Integer(max=10))
        setof_smallint.validate(set([1, 2]))
        self.assertRaises(
            ValidationError, setof_smallint.validate, set([1, 100]))
Exemple #4
0
 def test_from_riak(self):
     """
     The JSON list is turned into a set when read.
     """
     f = SetOf()
     self.assertEqual(f.from_riak([1, 2, 3]), set([1, 2, 3]))
Exemple #5
0
 def test_to_riak(self):
     """
     The JSON representation of a SetOf field is a sorted list.
     """
     f = SetOf()
     self.assertEqual(f.to_riak(set([1, 2, 3])), [1, 2, 3])
Exemple #6
0
 def test_validate(self):
     f = SetOf()
     f.validate(set([u'foo', u'bar']))
     self.assertRaises(ValidationError, f.validate, u'this is not a set')
     self.assertRaises(ValidationError, f.validate, set(['a', 2]))
Exemple #7
0
 def test_from_riak(self):
     """
     The JSON list is turned into a set when read.
     """
     f = SetOf()
     self.assertEqual(f.from_riak([1, 2, 3]), set([1, 2, 3]))
Exemple #8
0
 def test_to_riak(self):
     """
     The JSON representation of a SetOf field is a sorted list.
     """
     f = SetOf()
     self.assertEqual(f.to_riak(set([1, 2, 3])), [1, 2, 3])
Exemple #9
0
 def test_validate(self):
     f = SetOf()
     f.validate(set([u'foo', u'bar']))
     self.assertRaises(ValidationError, f.validate, u'this is not a set')
     self.assertRaises(ValidationError, f.validate, set(['a', 2]))
Exemple #10
0
 class IndexedSetOfModel(Model):
     """
     Toy model for SetOf index tests.
     """
     items = SetOf(Integer(), index=True)
Exemple #11
0
 class SetOfModel(Model):
     """
     Toy model for SetOf tests.
     """
     items = SetOf(Integer())
     texts = SetOf(Unicode())
Exemple #12
0
    def test_validate_with_subtype(self):
        """
        If an explicit subtype is provided, its validation is used.
        """
        setof_unicode = SetOf(Unicode())
        setof_unicode.validate(set([u"a", u"b"]))
        self.assertRaises(ValidationError, setof_unicode.validate, set([1, 2]))

        setof_int = SetOf(Integer())
        setof_int.validate(set([1, 2]))
        self.assertRaises(ValidationError, setof_int.validate,
                          set([u"a", u"b"]))

        setof_smallint = SetOf(Integer(max=10))
        setof_smallint.validate(set([1, 2]))
        self.assertRaises(ValidationError, setof_smallint.validate,
                          set([1, 100]))