'Ensure that invalid embedded documents cannot be assigned to
embedded document fields.'

def test_embedded_document_validation(self):

    class Comment(EmbeddedDocument, ):
        content = StringField()
    class PersonPreferences(EmbeddedDocument, ):
        food = StringField(required=True)
        number = IntField()
    class Person(Document, ):
        name = StringField()
        preferences = EmbeddedDocumentField(PersonPreferences)
    Person.drop_collection()
    person = Person(name='Test    User')
    person.preferences = 'My    Preferences'
    self.assertRaises(ValidationError, person.validate)
    person.preferences = Comment(content='Nice    blog    post...')
    self.assertRaises(ValidationError, person.validate)
    person.preferences = PersonPreferences()
    self.assertRaises(ValidationError, person.validate)
    person.preferences = PersonPreferences(food='Cheese', number=47)
    self.assertEqual(person.preferences.food, 'Cheese')
    person.validate()
