Merge "Support alembic 0.8.9 in test_autogen_process_directives"

This commit is contained in:
Jenkins 2016-12-06 02:06:58 +00:00 committed by Gerrit Code Review
commit 24b5a3b73e
1 changed files with 19 additions and 10 deletions

View File

@ -15,6 +15,7 @@
import copy
import os
import re
import sys
import textwrap
@ -27,6 +28,7 @@ import mock
from oslo_utils import fileutils
import pkg_resources
import sqlalchemy as sa
from testtools import matchers
from neutron.db import migration
from neutron.db.migration import autogen
@ -674,8 +676,13 @@ class TestCli(base.BaseTestCase):
self.assertTrue(expand.downgrade_ops.is_empty())
self.assertTrue(contract.downgrade_ops.is_empty())
self.assertEqual(
textwrap.dedent("""\
def _get_regex(s):
s = textwrap.dedent(s)
s = re.escape(s)
# alembic 0.8.9 added additional leading '# ' before comments
return s.replace('\\#\\#\\#\\ ', '(# )?### ')
expected_regex = ("""\
### commands auto generated by Alembic - please adjust! ###
op.create_table('organization',
sa.Column('id', sa.Integer(), nullable=False),
@ -686,17 +693,19 @@ class TestCli(base.BaseTestCase):
"""sa.Column('organization_id', sa.Integer(), nullable=True))
op.create_foreign_key('org_fk', 'user', """
"""'organization', ['organization_id'], ['id'])
### end Alembic commands ###"""),
alembic_ag_api.render_python_code(expand.upgrade_ops)
)
self.assertEqual(
textwrap.dedent("""\
### end Alembic commands ###""")
self.assertThat(
alembic_ag_api.render_python_code(expand.upgrade_ops),
matchers.MatchesRegex(_get_regex(expected_regex)))
expected_regex = ("""\
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('user', 'uq_user_org', type_=None)
op.drop_column('user', 'organization_name')
### end Alembic commands ###"""),
alembic_ag_api.render_python_code(contract.upgrade_ops)
)
### end Alembic commands ###""")
self.assertThat(
alembic_ag_api.render_python_code(contract.upgrade_ops),
matchers.MatchesRegex(_get_regex(expected_regex)))
@mock.patch('alembic.script.ScriptDirectory.walk_revisions')
def test__find_milestone_revisions_one_branch(self, walk_mock):