Merge "Use is_enabled() in folsom->grizzly upgrade (bug 1167421)"
This commit is contained in:
commit
f14928e6bb
@ -37,7 +37,7 @@ def downgrade_user_table(meta, migrate_engine, session):
|
||||
for user in session.query(user_table).all():
|
||||
extra = json.loads(user.extra)
|
||||
extra['password'] = user.password
|
||||
extra['enabled'] = '%r' % user.enabled
|
||||
extra['enabled'] = '%r' % is_enabled(user.enabled)
|
||||
values = {'extra': json.dumps(extra)}
|
||||
update = user_table.update().\
|
||||
where(user_table.c.id == user.id).\
|
||||
@ -50,7 +50,7 @@ def downgrade_tenant_table(meta, migrate_engine, session):
|
||||
for tenant in session.query(tenant_table).all():
|
||||
extra = json.loads(tenant.extra)
|
||||
extra['description'] = tenant.description
|
||||
extra['enabled'] = '%r' % tenant.enabled
|
||||
extra['enabled'] = '%r' % is_enabled(tenant.enabled)
|
||||
values = {'extra': json.dumps(extra)}
|
||||
update = tenant_table.update().\
|
||||
where(tenant_table.c.id == tenant.id).\
|
||||
@ -63,7 +63,7 @@ def upgrade_user_table(meta, migrate_engine, session):
|
||||
for user in session.query(user_table).all():
|
||||
extra = json.loads(user.extra)
|
||||
values = {'password': extra.pop('password', None),
|
||||
'enabled': extra.pop('enabled', True),
|
||||
'enabled': is_enabled(extra.pop('enabled', True)),
|
||||
'extra': json.dumps(extra)}
|
||||
update = user_table.update().\
|
||||
where(user_table.c.id == user.id).\
|
||||
@ -76,7 +76,7 @@ def upgrade_tenant_table(meta, migrate_engine, session):
|
||||
for tenant in session.query(tenant_table):
|
||||
extra = json.loads(tenant.extra)
|
||||
values = {'description': extra.pop('description', None),
|
||||
'enabled': extra.pop('enabled', True),
|
||||
'enabled': is_enabled(extra.pop('enabled', True)),
|
||||
'extra': json.dumps(extra)}
|
||||
update = tenant_table.update().\
|
||||
where(tenant_table.c.id == tenant.id).\
|
||||
|
@ -155,6 +155,86 @@ class SqlUpgradeTests(test.TestCase):
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
def test_normalized_enabled_states(self):
|
||||
self.upgrade(8)
|
||||
|
||||
users = {
|
||||
'bool_enabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': True})},
|
||||
'bool_disabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': False})},
|
||||
'str_enabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': 'True'})},
|
||||
'str_disabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': 'False'})},
|
||||
'int_enabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': 1})},
|
||||
'int_disabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': 0})},
|
||||
'null_enabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({'enabled': None})},
|
||||
'unset_enabled_user': {
|
||||
'id': uuid.uuid4().hex,
|
||||
'name': uuid.uuid4().hex,
|
||||
'password': uuid.uuid4().hex,
|
||||
'extra': json.dumps({})}}
|
||||
|
||||
session = self.Session()
|
||||
for user in users.values():
|
||||
self.insert_dict(session, 'user', user)
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
self.upgrade(10)
|
||||
|
||||
user_table = sqlalchemy.Table('user', self.metadata, autoload=True)
|
||||
q = self.Session().query(user_table, 'enabled')
|
||||
|
||||
user = q.filter_by(id=users['bool_enabled_user']['id']).one()
|
||||
self.assertTrue(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['bool_disabled_user']['id']).one()
|
||||
self.assertFalse(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['str_enabled_user']['id']).one()
|
||||
self.assertTrue(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['str_disabled_user']['id']).one()
|
||||
self.assertFalse(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['int_enabled_user']['id']).one()
|
||||
self.assertTrue(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['int_disabled_user']['id']).one()
|
||||
self.assertFalse(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['null_enabled_user']['id']).one()
|
||||
self.assertTrue(user.enabled)
|
||||
|
||||
user = q.filter_by(id=users['unset_enabled_user']['id']).one()
|
||||
self.assertTrue(user.enabled)
|
||||
|
||||
def test_downgrade_10_to_8(self):
|
||||
self.upgrade(10)
|
||||
self.populate_user_table(with_pass_enab=True)
|
||||
|
Loading…
Reference in New Issue
Block a user