'Test to ensure that indexes are re-created on a collection even
after the database has been dropped.
Issue #812'

def test_indexes_after_database_drop(self):

    connection = connect(db='tempdatabase', alias='test_indexes_after_database_drop')
    class BlogPost(Document, ):
        title = StringField()
        slug = StringField(unique=True)
        meta = {'db_alias': 'test_indexes_after_database_drop'}
    try:
        BlogPost.drop_collection()
        post1 = BlogPost(title='test1', slug='test')
        post1.save()
        connection.drop_database('tempdatabase')
        post1 = BlogPost(title='test1', slug='test')
        post1.save()
        post2 = BlogPost(title='test2', slug='test')
        self.assertRaises(NotUniqueError, post2.save)
    finally:
        connection.drop_database('tempdatabase')
