'Ensure that dict types work as expected.'

def test_dict_field(self):

    class BlogPost(Document, ):
        info = DictField()
    BlogPost.drop_collection()
    post = BlogPost()
    post.info = 'my    post'
    self.assertRaises(ValidationError, post.validate)
    post.info = ['test', 'test']
    self.assertRaises(ValidationError, post.validate)
    post.info = {'$title': 'test'}
    self.assertRaises(ValidationError, post.validate)
    post.info = {'nested': {'$title': 'test'}}
    self.assertRaises(ValidationError, post.validate)
    post.info = {'the.title': 'test'}
    self.assertRaises(ValidationError, post.validate)
    post.info = {'nested': {'the.title': 'test'}}
    self.assertRaises(ValidationError, post.validate)
    post.info = {1: 'test'}
    self.assertRaises(ValidationError, post.validate)
    post.info = {'title': 'test'}
    post.save()
    post = BlogPost()
    post.info = {'details': {'test': 'test'}}
    post.save()
    post = BlogPost()
    post.info = {'details': {'test': 3}}
    post.save()
    self.assertEqual(BlogPost.objects.count(), 3)
    self.assertEqual(BlogPost.objects.filter(info__title__exact='test').count(), 1)
    self.assertEqual(BlogPost.objects.filter(info__details__test__exact='test').count(), 1)
    self.assertEqual(BlogPost.objects.filter(info__details__test__exact=5).count(), 0)
    self.assertEqual(BlogPost.objects.filter(info__made_up__test__exact='test').count(), 0)
    post = BlogPost.objects.create(info={'title': 'original'})
    post.info.update({'title': 'updated'})
    post.save()
    post.reload()
    self.assertEqual('updated', post.info['title'])
    post.info.setdefault('authors', [])
    post.save()
    post.reload()
    self.assertEqual([], post.info['authors'])
