keystone.tests.unit.ksfixtures package¶
Submodules¶
keystone.tests.unit.ksfixtures.auth_plugins module¶
-
class
keystone.tests.unit.ksfixtures.auth_plugins.
ConfigAuthPlugins
(config_fixture, methods, **method_classes)[source]¶ Bases:
fixtures.fixture.Fixture
A fixture for setting up and tearing down a auth plugins.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
-
class
keystone.tests.unit.ksfixtures.auth_plugins.
LoadAuthPlugins
(*method_names)[source]¶ Bases:
fixtures.fixture.Fixture
-
cleanUp
()[source]¶ Cleanup the fixture.
This function will free all resources managed by the Fixture, restoring it (and any external facilities such as databases, temporary directories and so forth_ to their original state.
This should not typically be overridden, see addCleanup instead.
cleanUp may be called once and only once after setUp() has been called. The base implementation of setUp will automatically call cleanUp if an exception occurs within setUp itself.
- Parameters
raise_first – Deprecated parameter from before testtools gained MultipleExceptions. raise_first defaults to True. When True if a single exception is raised, it is reraised after all the cleanUps have run. If multiple exceptions are raised, they are all wrapped into a MultipleExceptions object, and that is reraised. Thus, to catch a specific exception from cleanUp, you need to catch both the exception and MultipleExceptions, and then check within a MultipleExceptions instance for the type you’re catching.
- Returns
A list of the exc_info() for each exception that occured if raise_first was False
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.backendloader module¶
-
class
keystone.tests.unit.ksfixtures.backendloader.
BackendLoader
(testcase)[source]¶ Bases:
fixtures.fixture.Fixture
Initialize each manager and assigns them to an attribute.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.cache module¶
-
class
keystone.tests.unit.ksfixtures.cache.
Cache
[source]¶ Bases:
fixtures.fixture.Fixture
A fixture for setting up the cache between test cases.
This will also tear down an existing cache if one is already configured.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.database module¶
-
class
keystone.tests.unit.ksfixtures.database.
Database
[source]¶ Bases:
fixtures.fixture.Fixture
A fixture for setting up and tearing down a database.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.hacking module¶
-
class
keystone.tests.unit.ksfixtures.hacking.
HackingCode
[source]¶ Bases:
fixtures.fixture.Fixture
A fixture to house the various code examples for the keystone hacking style checks.
-
asserting_none_equality
= {'code': "\n class Test(object):\n\n def test(self):\n self.assertEqual('', '')\n self.assertEqual('', None)\n self.assertEqual(None, '')\n self.assertNotEqual('', None)\n self.assertNotEqual(None, '')\n self.assertNotEqual('', None) # noqa\n self.assertNotEqual(None, '') # noqa\n ", 'expected_errors': [(5, 8, 'K003'), (6, 8, 'K003'), (7, 8, 'K004'), (8, 8, 'K004')]}¶
-
comments_begin_with_space
= {'code': "\n # This is a good comment\n\n #This is a bad one\n\n # This is alright and can\n # be continued with extra indentation\n # if that's what the developer wants.\n ", 'expected_errors': [(3, 0, 'K002')]}¶
-
dict_constructor
= {'code': "\n lower_res = {k.lower(): v for k, v in res[1].items()}\n fool = dict(a='a', b='b')\n lower_res = dict((k.lower(), v) for k, v in res[1].items())\n attrs = dict([(k, _from_json(v))])\n dict([[i,i] for i in range(3)])\n dict(({1:2}))\n ", 'expected_errors': [(3, 0, 'K008'), (4, 0, 'K008'), (5, 0, 'K008')]}¶
-
mutable_default_args
= {'code': '\n def f():\n pass\n\n def f(a, b=\'\', c=None):\n pass\n\n def f(bad=[]):\n pass\n\n def f(foo, bad=[], more_bad=[x for x in range(3)]):\n pass\n\n def f(foo, bad={}):\n pass\n\n def f(foo, bad={}, another_bad=[], fine=None):\n pass\n\n def f(bad=[]): # noqa\n pass\n\n def funcs(bad=dict(), more_bad=list(), even_more_bad=set()):\n "creating mutables through builtins"\n\n def funcs(bad=something(), more_bad=some_object.something()):\n "defaults from any functions"\n\n def f(bad=set(), more_bad={x for x in range(3)},\n even_more_bad={1, 2, 3}):\n "set and set comprehession"\n\n def f(bad={x: x for x in range(3)}):\n "dict comprehension"\n ', 'expected_errors': [(7, 10, 'K001'), (10, 15, 'K001'), (10, 28, 'K001'), (13, 15, 'K001'), (16, 15, 'K001'), (16, 31, 'K001'), (22, 14, 'K001'), (22, 31, 'K001'), (22, 53, 'K001'), (25, 14, 'K001'), (25, 36, 'K001'), (28, 10, 'K001'), (28, 26, 'K001'), (29, 21, 'K001'), (32, 10, 'K001')]}¶
-
-
class
keystone.tests.unit.ksfixtures.hacking.
HackingTranslations
[source]¶ Bases:
fixtures.fixture.Fixture
Fixtures for checking translation rules.
Exception messages should be translated
Logging messages should not be translated
If a message is used for both an exception and logging it should be translated
-
examples
= [{'code': "\n # stdlib logging\n LOG = logging.getLogger()\n LOG.info(_('text'))\n class C:\n def __init__(self):\n LOG.warning(oslo_i18n('text', {}))\n ", 'expected_errors': [(3, 9, 'K005'), (6, 20, 'K005')]}, {'code': "\n # stdlib logging w/ alias and specifying a logger\n class C:\n def __init__(self):\n self.L = logging.getLogger(__name__)\n def m(self):\n self.L.warning(\n _('text'), {}\n )\n ", 'expected_errors': [(7, 12, 'K005')]}, {'code': "\n # oslo logging and specifying a logger\n L = log.getLogger(__name__)\n L.error(oslo_i18n('text'))\n ", 'expected_errors': [(3, 8, 'K005')]}, {'code': "\n # oslo logging w/ alias\n class C:\n def __init__(self):\n self.LOG = oslo_logging.getLogger()\n self.LOG.critical(_('text'))\n ", 'expected_errors': [(5, 26, 'K005')]}, {'code': "\n LOG = log.getLogger(__name__)\n # translation on a separate line\n msg = _('text')\n LOG.exception(msg)\n ", 'expected_errors': [(4, 14, 'K005')]}, {'code': "\n # this should be an error even if it'll be raised later.\n L = log.getLogger(__name__)\n msg = _('text')\n L.warning(msg)\n raise Exception(msg)\n ", 'expected_errors': [(4, 10, 'K005')]}, {'code': "\n L = log.getLogger(__name__)\n def f():\n msg = _('text')\n L.warning(msg)\n something = True # add an extra statement here\n raise Exception(msg)\n ", 'expected_errors': [(4, 14, 'K005')]}, {'code': "\n LOG = log.getLogger(__name__)\n def func():\n msg = _('text')\n LOG.warning(msg)\n raise Exception('some other message')\n ", 'expected_errors': [(4, 16, 'K005')]}, {'code': "\n LOG = log.getLogger(__name__)\n if True:\n msg = _('text')\n else:\n msg = _('text')\n LOG.warning(msg)\n raise Exception(msg)\n ", 'expected_errors': [(6, 12, 'K005')]}, {'code': "\n LOG = log.getLogger(__name__)\n if True:\n msg = _('text')\n else:\n msg = _('text')\n LOG.warning(msg)\n ", 'expected_errors': [(6, 12, 'K005')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('text')\n LOG.warning(msg)\n msg = _('something else')\n raise Exception(msg)\n ", 'expected_errors': []}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _('hello %s') % 'world'\n LOG.warning(msg)\n ", 'expected_errors': [(3, 12, 'K005')]}, {'code': '\n # this should not be an error\n LOG = log.getLogger(__name__)\n try:\n something = True\n except AssertionError as e:\n LOG.warning(e)\n raise exception.Unauthorized(e)\n ', 'expected_errors': []}, {'code': "\n # this should not be an error\n LOG = log.getLogger(__name__)\n try:\n pass\n except AssertionError as e:\n msg = _('some message')\n LOG.warning(msg)\n raise exception.Unauthorized(message=msg)\n ", 'expected_errors': [(7, 16, 'K005')]}]¶
keystone.tests.unit.ksfixtures.jws_key_repository module¶
-
class
keystone.tests.unit.ksfixtures.jws_key_repository.
JWSKeyRepository
(config_fixture)[source]¶ Bases:
fixtures.fixture.Fixture
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.key_repository module¶
-
class
keystone.tests.unit.ksfixtures.key_repository.
KeyRepository
(config_fixture, key_group, max_active_keys)[source]¶ Bases:
fixtures.fixture.Fixture
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.ldapdb module¶
-
class
keystone.tests.unit.ksfixtures.ldapdb.
LDAPDatabase
(dbclass=<class 'keystone.tests.unit.fakeldap.FakeLdap'>)[source]¶ Bases:
fixtures.fixture.Fixture
A fixture for setting up and tearing down an LDAP database.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.policy module¶
-
class
keystone.tests.unit.ksfixtures.policy.
Policy
(config_fixture, policy_file=None)[source]¶ Bases:
fixtures.fixture.Fixture
A fixture for working with policy configuration.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
keystone.tests.unit.ksfixtures.temporaryfile module¶
-
class
keystone.tests.unit.ksfixtures.temporaryfile.
SecureTempFile
[source]¶ Bases:
fixtures.fixture.Fixture
A fixture for creating a secure temp file.
-
setUp
()[source]¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-