Enable Foreign keys for sql backend unit test
Enable the sqlite foreign keys function for unit test. This patch is the first part to solve sql backend test issues. Change-Id: I5d29d05e64b76ff6530c9af5ee39a2df1b26aa03 Partial-Bug: #1744195
This commit is contained in:
parent
50b2d6aa0e
commit
46a28313fc
|
@ -310,6 +310,35 @@ def new_federated_user_ref(idp_id=None, protocol_id=None, **kwargs):
|
|||
return ref
|
||||
|
||||
|
||||
def new_mapping_ref(mapping_id=None, rules=None, **kwargs):
|
||||
ref = {
|
||||
'id': mapping_id or uuid.uuid4().hex,
|
||||
'rules': rules or []
|
||||
}
|
||||
ref.update(kwargs)
|
||||
return ref
|
||||
|
||||
|
||||
def new_protocol_ref(protocol_id=None, idp_id=None, mapping_id=None, **kwargs):
|
||||
ref = {
|
||||
'id': protocol_id or 'saml2',
|
||||
'idp_id': idp_id or 'ORG_IDP',
|
||||
'mapping_id': mapping_id or uuid.uuid4().hex
|
||||
}
|
||||
ref.update(kwargs)
|
||||
return ref
|
||||
|
||||
|
||||
def new_identity_provider_ref(idp_id=None, **kwargs):
|
||||
ref = {
|
||||
'id': idp_id or 'ORG_IDP',
|
||||
'enabled': True,
|
||||
'description': '',
|
||||
}
|
||||
ref.update(kwargs)
|
||||
return ref
|
||||
|
||||
|
||||
def new_group_ref(domain_id, **kwargs):
|
||||
ref = {
|
||||
'id': uuid.uuid4().hex,
|
||||
|
|
|
@ -472,7 +472,26 @@ class IdentityTests(object):
|
|||
comparator='equals')
|
||||
return hints
|
||||
|
||||
def _build_fed_resource(self):
|
||||
# create one test mapping, two idps and two protocols for federation
|
||||
# test.
|
||||
new_mapping = unit.new_mapping_ref()
|
||||
PROVIDERS.federation_api.create_mapping(new_mapping['id'], new_mapping)
|
||||
for idp_id, protocol_id in [('ORG_IDP', 'saml2'),
|
||||
('myidp', 'mapped')]:
|
||||
new_idp = unit.new_identity_provider_ref(idp_id=idp_id,
|
||||
domain_id='default')
|
||||
new_protocol = unit.new_protocol_ref(protocol_id=protocol_id,
|
||||
idp_id=idp_id,
|
||||
mapping_id=new_mapping['id'])
|
||||
|
||||
PROVIDERS.federation_api.create_idp(new_idp['id'], new_idp)
|
||||
PROVIDERS.federation_api.create_protocol(new_idp['id'],
|
||||
new_protocol['id'],
|
||||
new_protocol)
|
||||
|
||||
def _test_list_users_with_attribute(self, filters, fed_dict):
|
||||
self._build_fed_resource()
|
||||
domain = self._get_domain_fixture()
|
||||
# Call list_users while no match exists for the federated user
|
||||
hints = driver_hints.Hints()
|
||||
|
@ -556,6 +575,7 @@ class IdentityTests(object):
|
|||
self._test_list_users_with_attribute(filters, federated_dict)
|
||||
|
||||
def test_list_users_with_name(self):
|
||||
self._build_fed_resource()
|
||||
federated_dict_1 = unit.new_federated_user_ref(
|
||||
display_name='test1@federation.org')
|
||||
federated_dict_2 = unit.new_federated_user_ref(
|
||||
|
@ -1123,10 +1143,6 @@ class IdentityTests(object):
|
|||
domain['id'], {'enabled': False})
|
||||
PROVIDERS.resource_api.delete_domain(domain['id'])
|
||||
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN
|
||||
)
|
||||
|
||||
self.domain_list = []
|
||||
create_domains(6)
|
||||
self.addCleanup(clean_up_domains)
|
||||
|
|
|
@ -33,6 +33,7 @@ class SqlPolicyAssociationTests(
|
|||
test_backend_sql.SqlTests,
|
||||
test_backend_endpoint_policy.PolicyAssociationTests):
|
||||
|
||||
def load_fixtures(self, fixtures):
|
||||
super(SqlPolicyAssociationTests, self).load_fixtures(fixtures)
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
super(SqlPolicyAssociationTests, self).load_fixtures(
|
||||
fixtures, enable_sqlite_foreign_key=enable_sqlite_foreign_key)
|
||||
self.load_sample_data()
|
||||
|
|
|
@ -52,11 +52,11 @@ class SqlTests(unit.SQLDriverOverrides, unit.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
super(SqlTests, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.useFixture(database.Database(enable_sqlite_foreign_key=True))
|
||||
self.load_backends()
|
||||
|
||||
# populate the engine with tables & fixtures
|
||||
self.load_fixtures(default_fixtures)
|
||||
self.load_fixtures(default_fixtures, enable_sqlite_foreign_key=True)
|
||||
# defaulted by the data load
|
||||
self.user_foo['enabled'] = True
|
||||
|
||||
|
@ -684,8 +684,10 @@ class SqlIdentity(SqlTests,
|
|||
ref_id)
|
||||
|
||||
# Deleting list of projects that includes a non-existing project
|
||||
# should be silent
|
||||
driver.delete_projects_from_ids([ref_id])
|
||||
# should be silent. The root domain <<keystone.domain.root>> can't
|
||||
# be deleted.
|
||||
if ref_id != resource.NULL_DOMAIN_ID:
|
||||
driver.delete_projects_from_ids([ref_id])
|
||||
|
||||
_exercise_project_api(uuid.uuid4().hex)
|
||||
_exercise_project_api(resource.NULL_DOMAIN_ID)
|
||||
|
|
Loading…
Reference in New Issue