'Ensure that invalid values cannot be assigned to string fields.'

def test_string_validation(self):

    class Person(Document, ):
        name = StringField(max_length=20)
        userid = StringField('[0-9a-z_]+$')
    person = Person(name=34)
    self.assertRaises(ValidationError, person.validate)
    person = Person(userid='test.User')
    self.assertRaises(ValidationError, person.validate)
    person.userid = 'test_user'
    self.assertEqual(person.userid, 'test_user')
    person.validate()
    person = Person(name='Name    that    is    more    than    twenty    characters')
    self.assertRaises(ValidationError, person.validate)
    person.name = 'Shorter    name'
    person.validate()
