

@mock.patch.object(cli, '_use_separate_migration_branches')
@mock.patch.object(cli, '_get_version_branch_path')
def test_autogen_process_directives(self, get_version_branch_path, use_separate_migration_branches):
    use_separate_migration_branches.return_value = True
    get_version_branch_path.side_effect = (lambda cfg, release, branch: ('/foo/expand' if (branch == 'expand') else '/foo/contract'))
    migration_script = alembic_ops.MigrationScript('eced083f5df', alembic_ops.UpgradeOps(ops=[alembic_ops.CreateTableOp('organization', [sa.Column('id', sa.Integer(), primary_key=True), sa.Column('name', sa.String(50), nullable=False)]), alembic_ops.ModifyTableOps('user', ops=[alembic_ops.AddColumnOp('user', sa.Column('organization_id', sa.Integer())), alembic_ops.CreateForeignKeyOp('org_fk', 'user', 'organization', ['organization_id'], ['id']), alembic_ops.DropConstraintOp('user', 'uq_user_org'), alembic_ops.DropColumnOp('user', 'organization_name')])]), alembic_ops.DowngradeOps(ops=[alembic_ops.AddColumnOp('user', sa.Column('organization_name', sa.String(50), nullable=True)), alembic_ops.CreateUniqueConstraintOp('uq_user_org', 'user', ['user_name', 'organization_name']), alembic_ops.ModifyTableOps('user', ops=[alembic_ops.DropConstraintOp('org_fk', 'user'), alembic_ops.DropColumnOp('user', 'organization_id')]), alembic_ops.DropTableOp('organization')]), message='create the organization table and replace user.organization_name')
    directives = [migration_script]
    autogen.process_revision_directives(mock.Mock(), mock.Mock(), directives)
    expand = directives[0]
    contract = directives[1]
    contract.assertEqual('/foo/expand', expand.version_path)
    self.assertEqual('/foo/contract', contract.version_path)
    self.assertTrue(expand.downgrade_ops.is_empty())
    self.assertTrue(contract.downgrade_ops.is_empty())
    self.assertEqual(textwrap.dedent("            ### commands auto generated by Alembic - please adjust! ###\n                op.create_table('organization',\n                sa.Column('id', sa.Integer(), nullable=False),\n                sa.Column('name', sa.String(length=50), nullable=False),\n                sa.PrimaryKeyConstraint('id')\n                )\n                op.add_column('user', sa.Column('organization_id', sa.Integer(), nullable=True))\n                op.create_foreign_key('org_fk', 'user', 'organization', ['organization_id'], ['id'])\n                ### end Alembic commands ###"), alembic_ag_api.render_python_code(expand.upgrade_ops))
    self.assertEqual(textwrap.dedent("            ### commands auto generated by Alembic - please adjust! ###\n                op.drop_constraint('user', 'uq_user_org', type_=None)\n                op.drop_column('user', 'organization_name')\n                ### end Alembic commands ###"), alembic_ag_api.render_python_code(contract.upgrade_ops))

dataset/ETHPy150Open openstack/neutron/neutron/tests/unit/db/test_migration.py TestCli.test_autogen_process_directives/VarMisuse@327/579 `self`->`contract`