'Tests loading a squashed migration with a new migration referencing it'

@override_settings(MIGRATION_MODULES={'app1': 'migrations.test_migrations_squashed_ref_squashed.app1', 'app2': 'migrations.test_migrations_squashed_ref_squashed.app2'})
@modify_settings(INSTALLED_APPS={'append': ['migrations.test_migrations_squashed_ref_squashed.app1', 'migrations.test_migrations_squashed_ref_squashed.app2']})
def test_loading_squashed_ref_squashed(self):

    '\n                                The    sample    migrations    are    structured    like    this:\n\n                                app_1                            1    -->    2    ---------------------*-->    3                                *-->    4\n                                                                                    \\                                                                                                        /                                                    /\n                                                                                        *-------------------*----/-->    2_sq_3    --*\n                                                                                            \\                                                                    /                /\n                                ===============    \\    =============    /    ==    /    ======================\n                                app_2                                                *-->    1_sq_2    --*                /\n                                                                                                        \\                                                                /\n                                                                                                            *-->    1    -->    2    --*\n\n                                Where    2_sq_3    is    a    replacing    migration    for    2    and    3    in    app_1,\n                                as    1_sq_2    is    a    replacing    migration    for    1    and    2    in    app_2.\n                                '
    loader = MigrationLoader(connection)
    recorder = MigrationRecorder(connection)
    self.addCleanup(recorder.flush)
    loader.build_graph()
    plan = set(loader.graph.forwards_plan(('app1', '4_auto')))
    plan = (plan - loader.applied_migrations)
    expected_plan = {('app1', '1_auto'), ('app2', '1_squashed_2'), ('app1', '2_squashed_3'), ('app1', '4_auto')}
    self.assertEqual(plan, expected_plan)
    recorder.record_applied('app1', '1_auto')
    recorder.record_applied('app1', '2_auto')
    loader.build_graph()
    plan = set(loader.graph.forwards_plan(('app1', '4_auto')))
    plan = (plan - loader.applied_migrations)
    expected_plan = {('app2', '1_squashed_2'), ('app1', '3_auto'), ('app1', '4_auto')}
    self.assertEqual(plan, expected_plan)
    recorder.record_applied('app2', '1_auto')
    loader.build_graph()
    plan = set(loader.graph.forwards_plan(('app1', '4_auto')))
    plan = (plan - loader.applied_migrations)
    expected_plan = {('app2', '2_auto'), ('app1', '3_auto'), ('app1', '4_auto')}
    self.assertEqual(plan, expected_plan)
