def test_add_remove_table(self):
     metadata = sqlalchemy.MetaData()
     sqlalchemy.Table('new_table', metadata)
     self._test_diffs(metadata, {
         SimpleDiff(DiffTypes.ADD_TABLE, 'new_table', None, None),
         SimpleDiff(DiffTypes.REMOVE_TABLE, self.table_name, None, None),
     })
示例#2
0
 def test_filter_by_table(self):
     diffs = {
         SimpleDiff(DiffTypes.ADD_TABLE, 't1', None),
         SimpleDiff(DiffTypes.ADD_TABLE, 't2', None),
         SimpleDiff(DiffTypes.ADD_COLUMN, 't1', None),
     }
     tables = get_tables_to_rebuild(diffs, {'t1'})
     self.assertEqual(tables, {'t1'})
示例#3
0
def test_filter_diffs():
    raw = [('add_table', 't1'), ('remove_table', 't2')]
    formatted = [
        SimpleDiff(DiffTypes.ADD_TABLE, 't1', None),
        SimpleDiff(DiffTypes.REMOVE_TABLE, 't2', None),
    ]
    filtered = TableDiffs(raw=raw, formatted=formatted).filter(['t1'])
    assert_list_equal(filtered.raw, [('add_table', 't1')])
    assert_list_equal(filtered.formatted,
                      [SimpleDiff(DiffTypes.ADD_TABLE, 't1', None)])
def test_flatten_raw_diffs():
    raw_diffs = [
        [('diff1', None)],
        [('diff2', None)],
        ('diff3', None),
    ]
    flattened = reformat_alembic_diffs(raw_diffs)
    assert_list_equal(flattened, [
        SimpleDiff('diff1', None, None, ('diff1', None)),
        SimpleDiff('diff2', None, None, ('diff1', None)),
        SimpleDiff('diff3', None, None, ('diff1', None)),
    ])
 def test_modify_column(self):
     metadata = sqlalchemy.MetaData()
     sqlalchemy.Table(
         self.table_name, metadata,
         sqlalchemy.Column('user_id', sqlalchemy.Integer, primary_key=True),
         sqlalchemy.Column('user_name', sqlalchemy.String(16), nullable=True),
         sqlalchemy.Column('email_address', sqlalchemy.String(60), key='email'),
         sqlalchemy.Column('password', sqlalchemy.Integer, nullable=False)
     )
     self._test_diffs(metadata, {
         SimpleDiff(DiffTypes.MODIFY_TYPE, self.table_name, 'password', None),
         SimpleDiff(DiffTypes.MODIFY_NULLABLE, self.table_name, 'user_name', None),
     })
示例#6
0
 def test_add_remove_column(self):
     metadata = sqlalchemy.MetaData()
     sqlalchemy.Table(
         self.table_name, metadata,
         sqlalchemy.Column('user_id', sqlalchemy.Integer, primary_key=True),
         sqlalchemy.Column('user_name', sqlalchemy.String(16), nullable=False),
         sqlalchemy.Column('email_address', sqlalchemy.String(60), key='email'),
         sqlalchemy.Column('new_password', sqlalchemy.String(20), nullable=False)
     )
     self._test_diffs(metadata, {
         SimpleDiff(DiffTypes.ADD_COLUMN, self.table_name, 'new_password'),
         SimpleDiff(DiffTypes.REMOVE_COLUMN, self.table_name, 'password')
     })
 def test_add_remove_column(self):
     metadata = sqlalchemy.MetaData()
     sqlalchemy.Table(
         self.table_name, metadata,
         sqlalchemy.Column('user_id', sqlalchemy.Integer, primary_key=True),
         sqlalchemy.Column('user_name', sqlalchemy.String(16), nullable=False),
         sqlalchemy.Column('email_address', sqlalchemy.String(60), key='email'),
         sqlalchemy.Column('new_password', sqlalchemy.String(20), nullable=False)
     )
     diffs = self._test_diffs(metadata, {
         SimpleDiff(DiffTypes.ADD_COLUMN, self.table_name, 'new_password', None),
         SimpleDiff(DiffTypes.REMOVE_COLUMN, self.table_name, 'password', None)
     })
     # check that we can get the column via the property
     self.assertIsNotNone(diffs[0].column)
     self.assertIsNotNone(diffs[1].column)
示例#8
0
 def test_filter_by_type(self):
     diffs = {
         SimpleDiff(type_, type_, None, None)
         for type_ in DiffTypes.ALL
     }
     tables = get_tables_to_rebuild(diffs)
     self.assertEqual(tables, set(DiffTypes.TYPES_FOR_REBUILD))