def test_registry(self):
        option = resource_options.ResourceOption(uuid.uuid4().hex[:4],
                                                 uuid.uuid4().hex)
        option2 = resource_options.ResourceOption(uuid.uuid4().hex[:4],
                                                  uuid.uuid4().hex)
        registry = resource_options.ResourceOptionRegistry('TEST')

        registry.register_option(option)
        self.assertIn(option.option_name, registry.option_names)
        self.assertIs(1, len(registry.options))
        self.assertIn(option.option_id, registry.option_ids)
        registry.register_option(option2)
        self.assertIn(option2.option_name, registry.option_names)
        self.assertIs(2, len(registry.options))
        self.assertIn(option2.option_id, registry.option_ids)
        self.assertIs(option, registry.get_option_by_id(option.option_id))
        self.assertIs(option2, registry.get_option_by_id(option2.option_id))
        self.assertIs(option, registry.get_option_by_name(option.option_name))
        self.assertIs(option2,
                      registry.get_option_by_name(option2.option_name))
    def test_duplicate_option_cases(self):
        option_id_str_valid = 'test'
        registry = resource_options.ResourceOptionRegistry(option_id_str_valid)
        option_name_unique = uuid.uuid4().hex

        option = resource_options.ResourceOption(option_id_str_valid,
                                                 option_name_unique)
        option_dup_id = resource_options.ResourceOption(
            option_id_str_valid,
            uuid.uuid4().hex)
        option_dup_name = resource_options.ResourceOption(
            uuid.uuid4().hex[:4], option_name_unique)

        registry.register_option(option)

        self.assertRaises(ValueError, registry.register_option, option_dup_id)
        self.assertRaises(ValueError, registry.register_option,
                          option_dup_name)
        self.assertIs(1, len(registry.options))
        registry.register_option(option)
        self.assertIs(1, len(registry.options))
Esempio n. 3
0
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from keystone.common import resource_options
from keystone.common.resource_options import options as ro_opt


PROJECT_OPTIONS_REGISTRY = resource_options.ResourceOptionRegistry('PROJECT')


# NOTE(morgan): wrap this in a function for testing purposes.
# This is called on import by design.
def register_role_options():
    for opt in [
        ro_opt.IMMUTABLE_OPT,
    ]:
        PROJECT_OPTIONS_REGISTRY.register_option(opt)


register_role_options()
Esempio n. 4
0
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from keystone.common import resource_options
from keystone.common.resource_options import options as ro_opt


ROLE_OPTIONS_REGISTRY = resource_options.ResourceOptionRegistry('ROLE')


# NOTE(morgan): wrap this in a function for testing purposes.
# This is called on import by design.
def register_role_options():
    for opt in [
        ro_opt.IMMUTABLE_OPT,
    ]:
        ROLE_OPTIONS_REGISTRY.register_option(opt)


register_role_options()
            # Sublist is duplicated, ValueError
            raise ValueError(msg)
        # Add the sublist to the tracker
        sublists.append(sublist)
        for element in sublist:
            if not isinstance(element, six.string_types):
                # Element of sublist is not a string, TypeError
                raise TypeError(msg)
            if element in string_set:
                # Element of sublist is duplicated, ValueError
                raise ValueError(msg)
            # add element to the sublist element tracker
            string_set.add(element)


USER_OPTIONS_REGISTRY = resource_options.ResourceOptionRegistry('USER')
IGNORE_CHANGE_PASSWORD_OPT = (resource_options.ResourceOption(
    option_id='1000',
    option_name='ignore_change_password_upon_first_use',
    validator=resource_options.boolean_validator,
    json_schema_validation=parameter_types.boolean))
IGNORE_PASSWORD_EXPIRY_OPT = (resource_options.ResourceOption(
    option_id='1001',
    option_name='ignore_password_expiry',
    validator=resource_options.boolean_validator,
    json_schema_validation=parameter_types.boolean))
IGNORE_LOCKOUT_ATTEMPT_OPT = (resource_options.ResourceOption(
    option_id='1002',
    option_name='ignore_lockout_failure_attempts',
    validator=resource_options.boolean_validator,
    json_schema_validation=parameter_types.boolean))