Merge "Enable foreign keys for unit test"
This commit is contained in:
commit
8e33c78232
@ -102,7 +102,8 @@ class Manager(manager.Manager):
|
||||
was not satisfied.
|
||||
"""
|
||||
if (not PROVIDERS.identity_api.multiple_domains_supported and
|
||||
project_ref['id'] != CONF.identity.default_domain_id):
|
||||
project_ref['id'] != CONF.identity.default_domain_id and
|
||||
project_ref['id'] != base.NULL_DOMAIN_ID):
|
||||
raise exception.ValidationError(
|
||||
message=_('Multiple domains are not supported'))
|
||||
|
||||
|
@ -15,7 +15,9 @@ from oslo_config import fixture as config_fixture
|
||||
from keystone.cmd import bootstrap
|
||||
from keystone.common import provider_api
|
||||
import keystone.conf
|
||||
from keystone import exception
|
||||
from keystone.tests.unit import core
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit import ksfixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
|
||||
@ -56,6 +58,14 @@ class TestCaseWithBootstrap(core.BaseTestCase):
|
||||
self.bootstrapper.admin_role_name = 'admin'
|
||||
self.bootstrapper.service_name = 'keystone'
|
||||
self.bootstrapper.public_url = 'http://localhost/identity/'
|
||||
|
||||
try:
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'],
|
||||
default_fixtures.ROOT_DOMAIN)
|
||||
except exception.Conflict:
|
||||
pass
|
||||
|
||||
self.bootstrapper.bootstrap()
|
||||
|
||||
def clean_default_domain(self):
|
||||
|
@ -821,7 +821,7 @@ class TestCase(BaseTestCase):
|
||||
provider_api.ProviderAPIs._clear_registry_instances()
|
||||
self.useFixture(ksfixtures.BackendLoader(self))
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
"""Hacky basic and naive fixture loading based on a python module.
|
||||
|
||||
Expects that the various APIs into the various services are already
|
||||
@ -837,12 +837,12 @@ class TestCase(BaseTestCase):
|
||||
if (hasattr(self, 'identity_api') and
|
||||
hasattr(self, 'assignment_api') and
|
||||
hasattr(self, 'resource_api')):
|
||||
# TODO(wxy): Once all test enable FKs, remove
|
||||
# ``enable_sqlite_foreign_key`` and create the root domain by
|
||||
# default.
|
||||
if enable_sqlite_foreign_key:
|
||||
self.resource_api.create_domain(resource_base.NULL_DOMAIN_ID,
|
||||
fixtures.ROOT_DOMAIN)
|
||||
try:
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
resource_base.NULL_DOMAIN_ID, fixtures.ROOT_DOMAIN)
|
||||
except exception.Conflict:
|
||||
# the root domain already exists, skip now.
|
||||
pass
|
||||
for domain in fixtures.DOMAINS:
|
||||
rv = PROVIDERS.resource_api.create_domain(domain['id'], domain)
|
||||
attrname = 'domain_%s' % domain['id']
|
||||
|
@ -15,6 +15,7 @@ import uuid
|
||||
from keystone.common import provider_api
|
||||
from keystone import exception
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
from keystone.tests.unit import mapping_fixtures
|
||||
|
||||
@ -27,6 +28,8 @@ class TestFederationProtocol(unit.TestCase):
|
||||
super(TestFederationProtocol, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
self.idp = {
|
||||
'id': uuid.uuid4().hex,
|
||||
'enabled': True,
|
||||
|
@ -24,6 +24,7 @@ import keystone.conf
|
||||
from keystone import exception
|
||||
from keystone import identity
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
|
||||
|
||||
@ -133,6 +134,8 @@ class TestDatabaseDomainConfigs(unit.TestCase):
|
||||
super(TestDatabaseDomainConfigs, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
def test_domain_config_in_database_disabled_by_default(self):
|
||||
self.assertFalse(CONF.identity.domain_configurations_from_database)
|
||||
|
@ -103,12 +103,11 @@ def _load_sqlalchemy_models():
|
||||
class Database(fixtures.Fixture):
|
||||
"""A fixture for setting up and tearing down a database."""
|
||||
|
||||
def __init__(self, enable_sqlite_foreign_key=False):
|
||||
def __init__(self):
|
||||
super(Database, self).__init__()
|
||||
initialize_sql_session()
|
||||
_load_sqlalchemy_models()
|
||||
if enable_sqlite_foreign_key:
|
||||
sql.enable_sqlite_foreign_key()
|
||||
sql.enable_sqlite_foreign_key()
|
||||
|
||||
def setUp(self):
|
||||
super(Database, self).setUp()
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
from keystone.resource.backends import sql
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
from keystone.tests.unit.resource import test_backends
|
||||
|
||||
@ -22,3 +23,8 @@ class TestSqlResourceDriver(unit.BaseTestCase,
|
||||
super(TestSqlResourceDriver, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.driver = sql.Resource()
|
||||
root_domain = default_fixtures.ROOT_DOMAIN
|
||||
root_domain['domain_id'] = root_domain['id']
|
||||
root_domain['is_domain'] = True
|
||||
self.driver.create_project(root_domain['id'],
|
||||
root_domain)
|
||||
|
@ -1731,7 +1731,7 @@ class ResourceDriverTests(object):
|
||||
project = {
|
||||
'name': uuid.uuid4().hex,
|
||||
'id': project_id,
|
||||
'domain_id': uuid.uuid4().hex,
|
||||
'domain_id': default_fixtures.ROOT_DOMAIN['id'],
|
||||
}
|
||||
self.driver.create_project(project_id, project)
|
||||
|
||||
@ -1740,10 +1740,18 @@ class ResourceDriverTests(object):
|
||||
project = {
|
||||
'name': uuid.uuid4().hex,
|
||||
'id': project_id,
|
||||
'domain_id': uuid.uuid4().hex,
|
||||
'domain_id': default_fixtures.ROOT_DOMAIN['id'],
|
||||
}
|
||||
parent_project = self.driver.create_project(project_id, project)
|
||||
|
||||
project_id = uuid.uuid4().hex
|
||||
project = {
|
||||
'name': uuid.uuid4().hex,
|
||||
'id': project_id,
|
||||
'domain_id': default_fixtures.ROOT_DOMAIN['id'],
|
||||
'description': uuid.uuid4().hex,
|
||||
'enabled': True,
|
||||
'parent_id': uuid.uuid4().hex,
|
||||
'parent_id': parent_project['id'],
|
||||
'is_domain': True,
|
||||
}
|
||||
self.driver.create_project(project_id, project)
|
||||
@ -1759,7 +1767,7 @@ class ResourceDriverTests(object):
|
||||
|
||||
def test_create_project_same_name_same_domain_conflict(self):
|
||||
name = uuid.uuid4().hex
|
||||
domain_id = uuid.uuid4().hex
|
||||
domain_id = default_fixtures.ROOT_DOMAIN['id']
|
||||
|
||||
project_id = uuid.uuid4().hex
|
||||
project = {
|
||||
@ -1784,14 +1792,14 @@ class ResourceDriverTests(object):
|
||||
project = {
|
||||
'name': uuid.uuid4().hex,
|
||||
'id': project_id,
|
||||
'domain_id': uuid.uuid4().hex,
|
||||
'domain_id': default_fixtures.ROOT_DOMAIN['id'],
|
||||
}
|
||||
self.driver.create_project(project_id, project)
|
||||
|
||||
project = {
|
||||
'name': uuid.uuid4().hex,
|
||||
'id': project_id,
|
||||
'domain_id': uuid.uuid4().hex,
|
||||
'domain_id': default_fixtures.ROOT_DOMAIN['id'],
|
||||
}
|
||||
self.assertRaises(exception.Conflict, self.driver.create_project,
|
||||
project_id, project)
|
||||
|
@ -21,6 +21,7 @@ from keystone.common import provider_api
|
||||
import keystone.conf
|
||||
from keystone import exception
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
|
||||
|
||||
@ -34,6 +35,8 @@ class TestResourceManagerNoFixtures(unit.SQLDriverOverrides, unit.TestCase):
|
||||
super(TestResourceManagerNoFixtures, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
def test_update_project_name_conflict(self):
|
||||
name = uuid.uuid4().hex
|
||||
|
@ -52,16 +52,14 @@ class RestfulTestCase(unit.TestCase):
|
||||
# default content type to test
|
||||
content_type = 'json'
|
||||
|
||||
def setUp(self, enable_sqlite_foreign_key=False):
|
||||
def setUp(self):
|
||||
super(RestfulTestCase, self).setUp()
|
||||
|
||||
self.auth_plugin_config_override()
|
||||
|
||||
self.useFixture(database.Database(
|
||||
enable_sqlite_foreign_key=enable_sqlite_foreign_key))
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
self.load_fixtures(default_fixtures,
|
||||
enable_sqlite_foreign_key=enable_sqlite_foreign_key)
|
||||
self.load_fixtures(default_fixtures)
|
||||
|
||||
self.public_app = webtest.TestApp(
|
||||
self.loadapp(name='public'))
|
||||
|
@ -33,7 +33,6 @@ class SqlPolicyAssociationTests(
|
||||
test_backend_sql.SqlTests,
|
||||
test_backend_endpoint_policy.PolicyAssociationTests):
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
super(SqlPolicyAssociationTests, self).load_fixtures(
|
||||
fixtures, enable_sqlite_foreign_key=enable_sqlite_foreign_key)
|
||||
def load_fixtures(self, fixtures):
|
||||
super(SqlPolicyAssociationTests, self).load_fixtures(fixtures)
|
||||
self.load_sample_data()
|
||||
|
@ -1941,7 +1941,7 @@ class LDAPIdentityEnabledEmulation(LDAPIdentity, unit.TestCase):
|
||||
super(LDAPIdentityEnabledEmulation, self).setUp()
|
||||
_assert_backends(self, identity='ldap')
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
# Override super impl since need to create group container.
|
||||
super(LDAPIdentity, self).load_fixtures(fixtures)
|
||||
for obj in [self.tenant_bar, self.tenant_baz, self.user_foo,
|
||||
@ -2360,9 +2360,11 @@ class MultiLDAPandSQLIdentity(BaseLDAPIdentity, unit.SQLDriverOverrides,
|
||||
|
||||
"""
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
self.domain_count = 5
|
||||
self.domain_specific_count = 3
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
self.setup_initial_domains()
|
||||
|
||||
# All initial test data setup complete, time to switch on support
|
||||
@ -2934,7 +2936,9 @@ class DomainSpecificLDAPandSQLIdentity(
|
||||
|
||||
super(DomainSpecificLDAPandSQLIdentity, self).setUp()
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
self.setup_initial_domains()
|
||||
super(DomainSpecificLDAPandSQLIdentity, self).load_fixtures(fixtures)
|
||||
|
||||
|
@ -52,11 +52,11 @@ class SqlTests(unit.SQLDriverOverrides, unit.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SqlTests, self).setUp()
|
||||
self.useFixture(database.Database(enable_sqlite_foreign_key=True))
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
|
||||
# populate the engine with tables & fixtures
|
||||
self.load_fixtures(default_fixtures, enable_sqlite_foreign_key=True)
|
||||
self.load_fixtures(default_fixtures)
|
||||
# defaulted by the data load
|
||||
self.user_foo['enabled'] = True
|
||||
|
||||
|
@ -99,6 +99,7 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
def setUp(self):
|
||||
self.useFixture(database.Database())
|
||||
super(CliBootStrapTestCase, self).setUp()
|
||||
self.bootstrap = cli.BootStrap()
|
||||
|
||||
def config_files(self):
|
||||
self.config_fixture.register_cli_opt(cli.command_opt)
|
||||
@ -112,10 +113,16 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
default_config_files=config_files)
|
||||
|
||||
def test_bootstrap(self):
|
||||
bootstrap = cli.BootStrap()
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
def _do_test_bootstrap(self, bootstrap):
|
||||
try:
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'],
|
||||
default_fixtures.ROOT_DOMAIN)
|
||||
except exception.Conflict:
|
||||
pass
|
||||
|
||||
bootstrap.do_bootstrap()
|
||||
project = PROVIDERS.resource_api.get_project_by_name(
|
||||
bootstrap.project_name,
|
||||
@ -175,8 +182,7 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
def test_bootstrap_is_idempotent_when_password_does_not_change(self):
|
||||
# NOTE(morganfainberg): Ensure we can run bootstrap with the same
|
||||
# configuration multiple times without erroring.
|
||||
bootstrap = cli.BootStrap()
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
app = self.loadapp()
|
||||
v3_password_data = {
|
||||
'auth': {
|
||||
@ -184,8 +190,8 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
"methods": ["password"],
|
||||
"password": {
|
||||
"user": {
|
||||
"name": bootstrap.username,
|
||||
"password": bootstrap.password,
|
||||
"name": self.bootstrap.username,
|
||||
"password": self.bootstrap.password,
|
||||
"domain": {
|
||||
"id": CONF.identity.default_domain_id
|
||||
}
|
||||
@ -198,7 +204,7 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
auth_response = c.post('/v3/auth/tokens',
|
||||
json=v3_password_data)
|
||||
token = auth_response.headers['X-Subject-Token']
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
# build validation request
|
||||
with app.test_client() as c:
|
||||
# Get a new X-Auth-Token
|
||||
@ -214,8 +220,7 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
def test_bootstrap_is_not_idempotent_when_password_does_change(self):
|
||||
# NOTE(lbragstad): Ensure bootstrap isn't idempotent when run with
|
||||
# different arguments or configuration values.
|
||||
bootstrap = cli.BootStrap()
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
app = self.loadapp()
|
||||
v3_password_data = {
|
||||
'auth': {
|
||||
@ -223,8 +228,8 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
"methods": ["password"],
|
||||
"password": {
|
||||
"user": {
|
||||
"name": bootstrap.username,
|
||||
"password": bootstrap.password,
|
||||
"name": self.bootstrap.username,
|
||||
"password": self.bootstrap.password,
|
||||
"domain": {
|
||||
"id": CONF.identity.default_domain_id
|
||||
}
|
||||
@ -241,7 +246,7 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
token = auth_response.headers['X-Subject-Token']
|
||||
new_passwd = uuid.uuid4().hex
|
||||
os.environ['OS_BOOTSTRAP_PASSWORD'] = new_passwd
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
v3_password_data['auth']['identity']['password']['user'][
|
||||
'password'] = new_passwd
|
||||
# Move time forward a second to avoid rev. event capturing the new
|
||||
@ -264,12 +269,11 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
expected_status_code=http_client.NOT_FOUND)
|
||||
|
||||
def test_bootstrap_recovers_user(self):
|
||||
bootstrap = cli.BootStrap()
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
# Completely lock the user out.
|
||||
user_id = PROVIDERS.identity_api.get_user_by_name(
|
||||
bootstrap.username,
|
||||
self.bootstrap.username,
|
||||
'default')['id']
|
||||
PROVIDERS.identity_api.update_user(
|
||||
user_id,
|
||||
@ -277,13 +281,13 @@ class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
'password': uuid.uuid4().hex})
|
||||
|
||||
# The second bootstrap run will recover the account.
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
# Sanity check that the original password works again.
|
||||
PROVIDERS.identity_api.authenticate(
|
||||
self.make_request(),
|
||||
user_id,
|
||||
bootstrap.password)
|
||||
self.bootstrap.password)
|
||||
|
||||
|
||||
class CliBootStrapTestCaseWithEnvironment(CliBootStrapTestCase):
|
||||
@ -335,9 +339,11 @@ class CliBootStrapTestCaseWithEnvironment(CliBootStrapTestCase):
|
||||
fixtures.EnvironmentVariable('OS_BOOTSTRAP_REGION_ID',
|
||||
newvalue=self.region_id))
|
||||
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
def test_assignment_created_with_user_exists(self):
|
||||
# test assignment can be created if user already exists.
|
||||
bootstrap = cli.BootStrap()
|
||||
PROVIDERS.resource_api.create_domain(self.default_domain['id'],
|
||||
self.default_domain)
|
||||
user_ref = unit.new_user_ref(self.default_domain['id'],
|
||||
@ -345,47 +351,42 @@ class CliBootStrapTestCaseWithEnvironment(CliBootStrapTestCase):
|
||||
password=self.password)
|
||||
PROVIDERS.identity_api.create_user(user_ref)
|
||||
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
def test_assignment_created_with_project_exists(self):
|
||||
# test assignment can be created if project already exists.
|
||||
bootstrap = cli.BootStrap()
|
||||
PROVIDERS.resource_api.create_domain(self.default_domain['id'],
|
||||
self.default_domain)
|
||||
project_ref = unit.new_project_ref(self.default_domain['id'],
|
||||
name=self.project_name)
|
||||
PROVIDERS.resource_api.create_project(project_ref['id'], project_ref)
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
def test_assignment_created_with_role_exists(self):
|
||||
# test assignment can be created if role already exists.
|
||||
bootstrap = cli.BootStrap()
|
||||
PROVIDERS.resource_api.create_domain(self.default_domain['id'],
|
||||
self.default_domain)
|
||||
role = unit.new_role_ref(name=self.role_name)
|
||||
PROVIDERS.role_api.create_role(role['id'], role)
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
def test_assignment_created_with_region_exists(self):
|
||||
# test assignment can be created if region already exists.
|
||||
bootstrap = cli.BootStrap()
|
||||
PROVIDERS.resource_api.create_domain(self.default_domain['id'],
|
||||
self.default_domain)
|
||||
region = unit.new_region_ref(id=self.region_id)
|
||||
PROVIDERS.catalog_api.create_region(region)
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
def test_endpoints_created_with_service_exists(self):
|
||||
# test assignment can be created if service already exists.
|
||||
bootstrap = cli.BootStrap()
|
||||
PROVIDERS.resource_api.create_domain(self.default_domain['id'],
|
||||
self.default_domain)
|
||||
service = unit.new_service_ref(name=self.service_name)
|
||||
PROVIDERS.catalog_api.create_service(service['id'], service)
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
def test_endpoints_created_with_endpoint_exists(self):
|
||||
bootstrap = cli.BootStrap()
|
||||
# test assignment can be created if endpoint already exists.
|
||||
PROVIDERS.resource_api.create_domain(self.default_domain['id'],
|
||||
self.default_domain)
|
||||
@ -401,7 +402,7 @@ class CliBootStrapTestCaseWithEnvironment(CliBootStrapTestCase):
|
||||
region_id=self.region_id)
|
||||
PROVIDERS.catalog_api.create_endpoint(endpoint['id'], endpoint)
|
||||
|
||||
self._do_test_bootstrap(bootstrap)
|
||||
self._do_test_bootstrap(self.bootstrap)
|
||||
|
||||
|
||||
class CliDomainConfigAllTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
@ -449,6 +450,9 @@ class CliDomainConfigAllTestCase(unit.SQLDriverOverrides, unit.TestCase):
|
||||
def create_domain(domain):
|
||||
return PROVIDERS.resource_api.create_domain(domain['id'], domain)
|
||||
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
self.domains = {}
|
||||
self.addCleanup(self.cleanup_domains)
|
||||
for x in range(1, self.domain_count):
|
||||
|
@ -14,6 +14,7 @@ import uuid
|
||||
|
||||
from keystone.common import provider_api
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit.identity.shadow_users import test_backend
|
||||
from keystone.tests.unit.identity.shadow_users import test_core
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
@ -28,6 +29,8 @@ class ShadowUsersTests(unit.TestCase,
|
||||
super(ShadowUsersTests, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
self.idp = {
|
||||
'id': uuid.uuid4().hex,
|
||||
'enabled': True,
|
||||
|
@ -197,10 +197,9 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase,
|
||||
config_files.append(unit.dirs.tests_conf('backend_sql.conf'))
|
||||
return config_files
|
||||
|
||||
def setUp(self, enable_sqlite_foreign_key=False):
|
||||
def setUp(self):
|
||||
"""Setup for v3 Restful Test Cases."""
|
||||
super(RestfulTestCase, self).setUp(
|
||||
enable_sqlite_foreign_key=enable_sqlite_foreign_key)
|
||||
super(RestfulTestCase, self).setUp()
|
||||
|
||||
self.empty_context = {'environment': {}}
|
||||
|
||||
@ -210,37 +209,27 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase,
|
||||
|
||||
super(RestfulTestCase, self).load_backends()
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
self.load_sample_data(
|
||||
enable_sqlite_foreign_key=enable_sqlite_foreign_key)
|
||||
def load_fixtures(self, fixtures):
|
||||
self.load_sample_data()
|
||||
|
||||
def _populate_default_domain(self, enable_sqlite_foreign_key=False):
|
||||
def _populate_default_domain(self):
|
||||
try:
|
||||
PROVIDERS.resource_api.get_domain(DEFAULT_DOMAIN_ID)
|
||||
except exception.DomainNotFound:
|
||||
# TODO(wxy): when FK is enabled in sqlite, a lot of tests will fail
|
||||
# due to the root domain is missing. So we should open FKs for the
|
||||
# tests one by one. If the FKs is enabled for one test,
|
||||
# `enable_sqlite_foreign_key` should be `true` here to ensure the
|
||||
# root domain is created. Once all tests enable FKs, the
|
||||
# ``enable_sqlite_foreign_key`` can be removed.
|
||||
if enable_sqlite_foreign_key:
|
||||
root_domain = unit.new_domain_ref(
|
||||
id=resource_base.NULL_DOMAIN_ID,
|
||||
name=resource_base.NULL_DOMAIN_ID
|
||||
)
|
||||
self.resource_api.create_domain(resource_base.NULL_DOMAIN_ID,
|
||||
root_domain)
|
||||
root_domain = unit.new_domain_ref(
|
||||
id=resource_base.NULL_DOMAIN_ID,
|
||||
name=resource_base.NULL_DOMAIN_ID
|
||||
)
|
||||
PROVIDERS.resource_api.create_domain(resource_base.NULL_DOMAIN_ID,
|
||||
root_domain)
|
||||
domain = unit.new_domain_ref(
|
||||
description=(u'The default domain'),
|
||||
id=DEFAULT_DOMAIN_ID,
|
||||
name=u'Default')
|
||||
PROVIDERS.resource_api.create_domain(DEFAULT_DOMAIN_ID, domain)
|
||||
|
||||
def load_sample_data(self, create_region_and_endpoints=True,
|
||||
enable_sqlite_foreign_key=False):
|
||||
self._populate_default_domain(
|
||||
enable_sqlite_foreign_key=enable_sqlite_foreign_key)
|
||||
def load_sample_data(self, create_region_and_endpoints=True):
|
||||
self._populate_default_domain()
|
||||
self.domain = unit.new_domain_ref()
|
||||
self.domain_id = self.domain['id']
|
||||
PROVIDERS.resource_api.create_domain(self.domain_id, self.domain)
|
||||
|
@ -22,6 +22,7 @@ from testtools import matchers
|
||||
from keystone.common import provider_api
|
||||
import keystone.conf
|
||||
from keystone import exception
|
||||
from keystone.resource.backends import base as resource_base
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import test_v3
|
||||
from keystone.tests.unit import utils as test_utils
|
||||
@ -1174,7 +1175,7 @@ class RoleAssignmentBaseTestCase(test_v3.RestfulTestCase,
|
||||
MAX_HIERARCHY_BREADTH = 3
|
||||
MAX_HIERARCHY_DEPTH = CONF.max_project_tree_depth - 1
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
"""Create sample data to be used on tests.
|
||||
|
||||
Created data are i) a role and ii) a domain containing: a project
|
||||
@ -3294,7 +3295,7 @@ class DomainSpecificRoleTests(test_v3.RestfulTestCase, unit.TestCase):
|
||||
class ListUserProjectsTestCase(test_v3.RestfulTestCase):
|
||||
"""Test for /users/<user>/projects."""
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
# do not load base class's data, keep it focused on the tests
|
||||
|
||||
self.auths = []
|
||||
@ -3303,6 +3304,13 @@ class ListUserProjectsTestCase(test_v3.RestfulTestCase):
|
||||
self.roles = []
|
||||
self.users = []
|
||||
|
||||
root_domain = unit.new_domain_ref(
|
||||
id=resource_base.NULL_DOMAIN_ID,
|
||||
name=resource_base.NULL_DOMAIN_ID
|
||||
)
|
||||
self.resource_api.create_domain(resource_base.NULL_DOMAIN_ID,
|
||||
root_domain)
|
||||
|
||||
# Create 3 sets of domain, roles, projects, and users to demonstrate
|
||||
# the right user's data is loaded and only projects they can access
|
||||
# are returned.
|
||||
|
@ -2575,7 +2575,7 @@ class TestFernetTokenAPIs(test_v3.RestfulTestCase, TokenAPITests,
|
||||
class TestTokenRevokeSelfAndAdmin(test_v3.RestfulTestCase):
|
||||
"""Test token revoke using v3 Identity API by token owner and admin."""
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
"""Load Sample Data for Test Cases.
|
||||
|
||||
Two domains, domainA and domainB
|
||||
|
@ -20,6 +20,7 @@ from testtools import matchers
|
||||
|
||||
from keystone.common import provider_api
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
from keystone.tests.unit import test_v3
|
||||
|
||||
@ -832,6 +833,9 @@ class TestCatalogAPISQL(unit.TestCase):
|
||||
|
||||
self.create_endpoint(service_id=self.service_id)
|
||||
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
def create_endpoint(self, service_id, **kwargs):
|
||||
endpoint = unit.new_endpoint_ref(service_id=service_id,
|
||||
region_id=None, **kwargs)
|
||||
@ -929,6 +933,8 @@ class TestCatalogAPISQLRegions(unit.TestCase):
|
||||
super(TestCatalogAPISQLRegions, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
def config_overrides(self):
|
||||
super(TestCatalogAPISQLRegions, self).config_overrides()
|
||||
@ -998,7 +1004,7 @@ class TestCatalogAPITemplatedProject(test_v3.RestfulTestCase):
|
||||
super(TestCatalogAPITemplatedProject, self).config_overrides()
|
||||
self.config_fixture.config(group='catalog', driver='templated')
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
self.load_sample_data(create_region_and_endpoints=False)
|
||||
|
||||
def test_project_delete(self):
|
||||
|
@ -1892,7 +1892,7 @@ class FederatedTokenTests(test_v3.RestfulTestCase, FederatedSetupMixin):
|
||||
self.assertEqual(note['protocol'], protocol)
|
||||
self.assertTrue(note['send_notification_called'])
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
super(FederatedTokenTests, self).load_fixtures(fixtures)
|
||||
self.load_federation_sample_data()
|
||||
|
||||
@ -2856,7 +2856,7 @@ class FederatedTokenTests(test_v3.RestfulTestCase, FederatedSetupMixin):
|
||||
class FernetFederatedTokenTests(test_v3.RestfulTestCase, FederatedSetupMixin):
|
||||
AUTH_METHOD = 'token'
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
super(FernetFederatedTokenTests, self).load_fixtures(fixtures)
|
||||
self.load_federation_sample_data()
|
||||
|
||||
@ -2972,7 +2972,7 @@ class FederatedUserTests(test_v3.RestfulTestCase, FederatedSetupMixin):
|
||||
methods = ['saml2', 'token']
|
||||
super(FederatedUserTests, self).auth_plugin_config_override(methods)
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
super(FederatedUserTests, self).load_fixtures(fixtures)
|
||||
self.load_federation_sample_data()
|
||||
|
||||
@ -3341,7 +3341,7 @@ class ShadowMappingTests(test_v3.RestfulTestCase, FederatedSetupMixin):
|
||||
methods = ['saml2', 'token']
|
||||
super(ShadowMappingTests, self).auth_plugin_config_override(methods)
|
||||
|
||||
def load_fixtures(self, fixtures, enable_sqlite_foreign_key=False):
|
||||
def load_fixtures(self, fixtures):
|
||||
super(ShadowMappingTests, self).load_fixtures(fixtures)
|
||||
self.load_federation_sample_data()
|
||||
|
||||
|
@ -47,7 +47,7 @@ class IdentityTestFilteredCase(filtering.FilterTests,
|
||||
self.tmpfilename = self.tempfile.file_name
|
||||
super(IdentityTestFilteredCase, self).setUp()
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
"""Create sample data for these tests.
|
||||
|
||||
As well as the usual housekeeping, create a set of domains,
|
||||
@ -341,7 +341,7 @@ class IdentityPasswordExpiryFilteredTestCase(filtering.FilterTests,
|
||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||
super(IdentityPasswordExpiryFilteredTestCase, self).setUp()
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
"""Create sample data for password expiry tests.
|
||||
|
||||
The test environment will consist of a single domain, containing
|
||||
|
@ -64,7 +64,7 @@ class IdentityTestProtectedCase(test_v3.RestfulTestCase):
|
||||
user_id=self.user1['id'],
|
||||
password=self.user1['password'])
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
self._populate_default_domain()
|
||||
|
||||
# Start by creating a couple of domains
|
||||
@ -395,7 +395,7 @@ class IdentityTestProtectedCase(test_v3.RestfulTestCase):
|
||||
class IdentityTestPolicySample(test_v3.RestfulTestCase):
|
||||
"""Test policy enforcement of the policy.json file."""
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
self._populate_default_domain()
|
||||
|
||||
self.just_a_user = unit.create_user(
|
||||
@ -687,7 +687,7 @@ class IdentityTestv3CloudPolicySample(test_v3.RestfulTestCase,
|
||||
)
|
||||
)
|
||||
|
||||
def load_sample_data(self, enable_sqlite_foreign_key=False):
|
||||
def load_sample_data(self):
|
||||
# Start by creating a couple of domains
|
||||
self._populate_default_domain()
|
||||
self.domainA = unit.new_domain_ref()
|
||||
|
@ -35,7 +35,7 @@ class ResourceTestCase(test_v3.RestfulTestCase,
|
||||
"""Test domains and projects."""
|
||||
|
||||
def setUp(self):
|
||||
super(ResourceTestCase, self).setUp(enable_sqlite_foreign_key=True)
|
||||
super(ResourceTestCase, self).setUp()
|
||||
self.useFixture(
|
||||
ksfixtures.KeyRepository(
|
||||
self.config_fixture,
|
||||
|
@ -28,6 +28,7 @@ import keystone.conf
|
||||
from keystone import exception
|
||||
from keystone.federation import constants as federation_constants
|
||||
from keystone.tests import unit
|
||||
from keystone.tests.unit import default_fixtures
|
||||
from keystone.tests.unit import ksfixtures
|
||||
from keystone.tests.unit.ksfixtures import database
|
||||
from keystone.token import provider
|
||||
@ -57,6 +58,8 @@ class TestValidate(unit.TestCase):
|
||||
super(TestValidate, self).setUp()
|
||||
self.useFixture(database.Database())
|
||||
self.load_backends()
|
||||
PROVIDERS.resource_api.create_domain(
|
||||
default_fixtures.ROOT_DOMAIN['id'], default_fixtures.ROOT_DOMAIN)
|
||||
|
||||
def config_overrides(self):
|
||||
super(TestValidate, self).config_overrides()
|
||||
|
7
releasenotes/notes/bug-1744195-a7154ac2e8556efc.yaml
Normal file
7
releasenotes/notes/bug-1744195-a7154ac2e8556efc.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
[`bug 1744195 <https://bugs.launchpad.net/keystone/+bug/1744195>`_]
|
||||
The SQL Foreign Key is enabled for Keystone unit tests now. This is not an
|
||||
end user impact fixed. But for the downstream teams, please take care of
|
||||
it for your private test code changes.
|
Loading…
Reference in New Issue
Block a user