From edda62ab351bbcf25bd33c23bd8cd25f40a1aedf Mon Sep 17 00:00:00 2001 From: Roman Dobosz Date: Tue, 1 Dec 2020 14:40:45 +0100 Subject: [PATCH] Fix indentation for the example code in documentation. Change-Id: I454c22aaf1ffa56c37c0105ab76aa70d28983f43 --- doc/source/microversion_testing.rst | 18 ++-- doc/source/plugins/plugin.rst | 12 +-- doc/source/write_tests.rst | 132 ++++++++++++++-------------- 3 files changed, 81 insertions(+), 81 deletions(-) diff --git a/doc/source/microversion_testing.rst b/doc/source/microversion_testing.rst index c7004dd8a5..c1981f98f1 100644 --- a/doc/source/microversion_testing.rst +++ b/doc/source/microversion_testing.rst @@ -126,16 +126,16 @@ For example: .. code-block:: python - class BaseTestCase1(api_version_utils.BaseMicroversionTest): + class BaseTestCase1(api_version_utils.BaseMicroversionTest): - [..] - @classmethod - def skip_checks(cls): - super(BaseTestCase1, cls).skip_checks() - api_version_utils.check_skip_with_microversion(cls.min_microversion, - cls.max_microversion, - CONF.compute.min_microversion, - CONF.compute.max_microversion) + [..] + @classmethod + def skip_checks(cls): + super(BaseTestCase1, cls).skip_checks() + api_version_utils.check_skip_with_microversion(cls.min_microversion, + cls.max_microversion, + CONF.compute.min_microversion, + CONF.compute.max_microversion) Skip logic can be added in tests base class or any specific test class depends on tests class structure. diff --git a/doc/source/plugins/plugin.rst b/doc/source/plugins/plugin.rst index ab1b0b1f0a..6726def2e0 100644 --- a/doc/source/plugins/plugin.rst +++ b/doc/source/plugins/plugin.rst @@ -268,12 +268,12 @@ instance: class MyAPIClient(rest_client.RestClient): - def __init__(self, auth_provider, service, region, - my_arg, my_arg2=True, **kwargs): - super(MyAPIClient, self).__init__( - auth_provider, service, region, **kwargs) - self.my_arg = my_arg - self.my_args2 = my_arg + def __init__(self, auth_provider, service, region, + my_arg, my_arg2=True, **kwargs): + super(MyAPIClient, self).__init__( + auth_provider, service, region, **kwargs) + self.my_arg = my_arg + self.my_args2 = my_arg Finally the service client should be structured in a python module, so that all service client classes are importable from it. Each major API version should diff --git a/doc/source/write_tests.rst b/doc/source/write_tests.rst index 0a29b7b3b8..34df089570 100644 --- a/doc/source/write_tests.rst +++ b/doc/source/write_tests.rst @@ -76,54 +76,54 @@ of these would be:: class TestExampleCase(test.BaseTestCase): - @classmethod - def skip_checks(cls): - """This section is used to evaluate config early and skip all test - methods based on these checks - """ - super(TestExampleCase, cls).skip_checks() - if not CONF.section.foo - cls.skip('A helpful message') + @classmethod + def skip_checks(cls): + """This section is used to evaluate config early and skip all test + methods based on these checks + """ + super(TestExampleCase, cls).skip_checks() + if not CONF.section.foo + cls.skip('A helpful message') - @classmethod - def setup_credentials(cls): - """This section is used to do any manual credential allocation and also - in the case of dynamic credentials to override the default network - resource creation/auto allocation - """ - # This call is used to tell the credential allocator to not create any - # network resources for this test case. It also enables selective - # creation of other neutron resources. NOTE: it must go before the - # super call - cls.set_network_resources() - super(TestExampleCase, cls).setup_credentials() + @classmethod + def setup_credentials(cls): + """This section is used to do any manual credential allocation and also + in the case of dynamic credentials to override the default network + resource creation/auto allocation + """ + # This call is used to tell the credential allocator to not create any + # network resources for this test case. It also enables selective + # creation of other neutron resources. NOTE: it must go before the + # super call + cls.set_network_resources() + super(TestExampleCase, cls).setup_credentials() - @classmethod - def setup_clients(cls): - """This section is used to setup client aliases from the manager object - or to initialize any additional clients. Except in a few very - specific situations you should not need to use this. - """ - super(TestExampleCase, cls).setup_clients() - cls.servers_client = cls.os_primary.servers_client + @classmethod + def setup_clients(cls): + """This section is used to setup client aliases from the manager object + or to initialize any additional clients. Except in a few very + specific situations you should not need to use this. + """ + super(TestExampleCase, cls).setup_clients() + cls.servers_client = cls.os_primary.servers_client - @classmethod - def resource_setup(cls): - """This section is used to create any resources or objects which are - going to be used and shared by **all** test methods in the - TestCase. Note then anything created in this section must also be - destroyed in the corresponding resource_cleanup() method (which will - be run during tearDownClass()) - """ - super(TestExampleCase, cls).resource_setup() - cls.shared_server = cls.servers_client.create_server(...) - cls.addClassResourceCleanup(waiters.wait_for_server_termination, - cls.servers_client, - cls.shared_server['id']) - cls.addClassResourceCleanup( - test_utils.call_and_ignore_notfound_exc( - cls.servers_client.delete_server, - cls.shared_server['id'])) + @classmethod + def resource_setup(cls): + """This section is used to create any resources or objects which are + going to be used and shared by **all** test methods in the + TestCase. Note then anything created in this section must also be + destroyed in the corresponding resource_cleanup() method (which will + be run during tearDownClass()) + """ + super(TestExampleCase, cls).resource_setup() + cls.shared_server = cls.servers_client.create_server(...) + cls.addClassResourceCleanup(waiters.wait_for_server_termination, + cls.servers_client, + cls.shared_server['id']) + cls.addClassResourceCleanup( + test_utils.call_and_ignore_notfound_exc( + cls.servers_client.delete_server, + cls.shared_server['id'])) .. _credentials: @@ -150,9 +150,9 @@ to set a class variable ``credentials`` on the TestCase directly. For example:: credentials = ['primary', 'admin'] - @classmethod - def skip_checks(cls): - ... + @classmethod + def skip_checks(cls): + ... In this example the ``TestExampleAdmin`` TestCase will allocate 2 sets of credentials, one regular user and one admin user. The corresponding manager @@ -225,10 +225,10 @@ in the `setup_credentials()` method before the `super()`. For example:: class TestExampleCase(test.BaseTestCase): - @classmethod - def setup_credentials(cls): - cls.set_network_resources(network=True, subnet=True, router=False) - super(TestExampleCase, cls).setup_credentials() + @classmethod + def setup_credentials(cls): + cls.set_network_resources(network=True, subnet=True, router=False) + super(TestExampleCase, cls).setup_credentials() There are 2 quirks with the usage here. First for the set_network_resources function to work properly it **must be called before super()**. This is so @@ -242,10 +242,10 @@ any arguments. For example:: class TestExampleCase(test.BaseTestCase): - @classmethod - def setup_credentials(cls): - cls.set_network_resources() - super(TestExampleCase, cls).setup_credentials() + @classmethod + def setup_credentials(cls): + cls.set_network_resources() + super(TestExampleCase, cls).setup_credentials() This will not allocate any networking resources. This is because by default all the arguments default to False. @@ -282,8 +282,8 @@ call to create a server in Nova:: class TestExampleCase(test.BaseTestCase): - def test_example_create_server(self): - self.os_primary.servers_client.create_server(...) + def test_example_create_server(self): + self.os_primary.servers_client.create_server(...) is all you need to do. As described previously, in the above example the ``self.os_primary`` is created automatically because the base test class sets the @@ -305,8 +305,8 @@ object via the manager's ``credentials`` attribute. For example:: class TestExampleCase(test.BaseTestCase): - def test_example_create_server(self): - credentials = self.os_primary.credentials + def test_example_create_server(self): + credentials = self.os_primary.credentials The credentials object provides access to all of the credential information you would need to make API requests. For example, building off the previous @@ -316,9 +316,9 @@ example:: class TestExampleCase(test.BaseTestCase): - def test_example_create_server(self): - credentials = self.os_primary.credentials - username = credentials.username - user_id = credentials.user_id - password = credentials.password - tenant_id = credentials.tenant_id + def test_example_create_server(self): + credentials = self.os_primary.credentials + username = credentials.username + user_id = credentials.user_id + password = credentials.password + tenant_id = credentials.tenant_id