'Tests detection of initial migrations already having been applied.'

@override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations'})
def test_soft_apply(self):

    state = {'faked': None}
    def fake_storer(phase, migration=None, fake=None):
        state['faked'] = fake
    executor = MigrationExecutor(connection, progress_callback=fake_storer)
    self.assertTableNotExists('migrations_author')
    self.assertTableNotExists('migrations_tribble')
    self.assertEqual(executor.migration_plan([('migrations', '0001_initial')]), [(executor.loader.graph.nodes[('migrations', '0001_initial')], False)])
    executor.migrate([('migrations', '0001_initial')])
    self.assertTableExists('migrations_author')
    self.assertTableExists('migrations_tribble')
    self.assertIs(state['faked'], False)
    executor.loader.build_graph()
    executor.migrate([('migrations', None)], fake=True)
    self.assertTableExists('migrations_author')
    self.assertTableExists('migrations_tribble')
    self.assertIs(state['faked'], True)
    executor.loader.build_graph()
    self.assertEqual(executor.migration_plan([('migrations', '0001_initial')]), [(executor.loader.graph.nodes[('migrations', '0001_initial')], False)])
    with self.assertRaises(DatabaseError):
        executor.migrate([('migrations', '0001_initial')])
    state = {'faked': None}
    executor.migrate([('migrations', '0001_initial')], fake_initial=True)
    self.assertIs(state['faked'], True)
    executor.loader.build_graph()
    executor.migrate([('migrations', None)])
    self.assertTableNotExists('migrations_author')
    self.assertTableNotExists('migrations_tribble')
