Fix H404/405 violations in novaclient/tests/*

There is a lot of H404/405 violations in novaclient, and it is better
to fix those to have a better doc string for class/methods.

This patch fixes these violations for files under  novaclient/tests/
folder.

As there are lot of violations and cannot be fixed in single patches,
So separating those in multiple patches for easy review.

Partial-Bug: #1521899
Change-Id: I6e712ece14c745013bfba0bee9d77e7875dd2263
This commit is contained in:
Ghanshyam 2015-12-07 14:17:56 +09:00
parent 06af0bf79b
commit 573bdaa290
12 changed files with 64 additions and 37 deletions

View File

@ -59,7 +59,8 @@ class NoCloudConfigException(Exception):
class ClientTestBase(testtools.TestCase): class ClientTestBase(testtools.TestCase):
""" """Base test class for read only python-novaclient commands.
This is a first pass at a simple read only python-novaclient test. This This is a first pass at a simple read only python-novaclient test. This
only exercises client commands that are read only. only exercises client commands that are read only.

View File

@ -20,8 +20,7 @@ from novaclient.tests.functional.v2 import fake_crypto
class TestKeypairsNovaClient(base.ClientTestBase): class TestKeypairsNovaClient(base.ClientTestBase):
"""Keypairs functional tests. """Keypairs functional tests."""
"""
COMPUTE_API_VERSION = "2.1" COMPUTE_API_VERSION = "2.1"

View File

@ -14,8 +14,7 @@ from novaclient.tests.functional import base
class TestQuotasNovaClient(base.ClientTestBase): class TestQuotasNovaClient(base.ClientTestBase):
"""Nova quotas functional tests. """Nova quotas functional tests."""
"""
COMPUTE_API_VERSION = "2.1" COMPUTE_API_VERSION = "2.1"

View File

@ -18,8 +18,7 @@ from novaclient.tests.functional import base
class SimpleReadOnlyNovaClientTest(base.ClientTestBase): class SimpleReadOnlyNovaClientTest(base.ClientTestBase):
""" """Read only functional python-novaclient tests.
read only functional python-novaclient tests.
This only exercises client commands that are read only. This only exercises client commands that are read only.
""" """

View File

@ -17,8 +17,7 @@ from novaclient.v2 import shell
class TestServersBootNovaClient(base.ClientTestBase): class TestServersBootNovaClient(base.ClientTestBase):
"""Servers boot functional tests. """Servers boot functional tests."""
"""
COMPUTE_API_VERSION = "2.1" COMPUTE_API_VERSION = "2.1"
@ -58,8 +57,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
class TestServersListNovaClient(base.ClientTestBase): class TestServersListNovaClient(base.ClientTestBase):
"""Servers list functional tests. """Servers list functional tests."""
"""
COMPUTE_API_VERSION = "2.1" COMPUTE_API_VERSION = "2.1"

View File

@ -15,8 +15,7 @@ from novaclient.tests.functional.v2.legacy import test_keypairs
class TestKeypairsNovaClientV22(test_keypairs.TestKeypairsNovaClient): class TestKeypairsNovaClientV22(test_keypairs.TestKeypairsNovaClient):
"""Keypairs functional tests for v2.2 nova-api microversion. """Keypairs functional tests for v2.2 nova-api microversion."""
"""
COMPUTE_API_VERSION = "2.2" COMPUTE_API_VERSION = "2.2"

View File

@ -14,8 +14,7 @@ from novaclient.tests.functional.v2.legacy import test_quotas
class TestQuotasNovaClient(test_quotas.TestQuotasNovaClient): class TestQuotasNovaClient(test_quotas.TestQuotasNovaClient):
"""Nova quotas functional tests. """Nova quotas functional tests."""
"""
COMPUTE_API_VERSION = "2.latest" COMPUTE_API_VERSION = "2.latest"

View File

@ -16,8 +16,7 @@ from novaclient.tests.functional.v2.legacy import test_readonly_nova
class SimpleReadOnlyNovaClientTest( class SimpleReadOnlyNovaClientTest(
test_readonly_nova.SimpleReadOnlyNovaClientTest): test_readonly_nova.SimpleReadOnlyNovaClientTest):
""" """Read only functional python-novaclient tests.
read only functional python-novaclient tests.
This only exercises client commands that are read only. This only exercises client commands that are read only.
""" """

View File

@ -17,15 +17,13 @@ from novaclient.tests.functional.v2.legacy import test_servers
class TestServersBootNovaClient(test_servers.TestServersBootNovaClient): class TestServersBootNovaClient(test_servers.TestServersBootNovaClient):
"""Servers boot functional tests. """Servers boot functional tests."""
"""
COMPUTE_API_VERSION = "2.latest" COMPUTE_API_VERSION = "2.latest"
class TestServersListNovaClient(test_servers.TestServersListNovaClient): class TestServersListNovaClient(test_servers.TestServersListNovaClient):
"""Servers list functional tests. """Servers list functional tests."""
"""
COMPUTE_API_VERSION = "2.latest" COMPUTE_API_VERSION = "2.latest"

View File

@ -36,8 +36,40 @@ def assert_has_keys(dict, required=[], optional=[]):
class FakeClient(object): class FakeClient(object):
def assert_called(self, method, url, body=None, pos=-1): def assert_called(self, method, url, body=None, pos=-1):
""" """Assert than an HTTP method was called at given order/position.
Assert than an API method was just called.
:param method: HTTP method name which is expected to be called
:param url: Expected request url to be called with given method
:param body: Expected request body to be called with given method
and url. Default is None.
:param pos: Order of the expected method call. If multiple methods
calls are made in single API request, then, order of each
method call can be checked by passing expected order to
this arg.
Default is -1 which means most recent call.
Usage::
1. self.run_command('flavor-list --extra-specs')
self.assert_called('GET', '/flavors/aa1/os-extra_specs')
2. self.run_command(["boot", "--image", "1",
"--flavor", "512 MB Server",
"--max-count", "3", "server"])
self.assert_called('GET', '/images/1', pos=0)
self.assert_called('GET', '/flavors/512 MB Server', pos=1)
self.assert_called('GET', '/flavors?is_public=None', pos=2)
self.assert_called('GET', '/flavors/2', pos=3)
self.assert_called(
'POST', '/servers',
{
'server': {
'flavorRef': '2',
'name': 'server',
'imageRef': '1',
'min_count': 1,
'max_count': 3,
}
}, pos=4)
""" """
expected = (method, url) expected = (method, url)
called = self.client.callstack[pos][0:2] called = self.client.callstack[pos][0:2]
@ -54,8 +86,15 @@ class FakeClient(object):
(self.client.callstack[pos][2], body)) (self.client.callstack[pos][2], body))
def assert_called_anytime(self, method, url, body=None): def assert_called_anytime(self, method, url, body=None):
""" """Assert than an HTTP method was called anytime in the test.
Assert than an API method was called anytime in the test.
:param method: HTTP method name which is expected to be called
:param url: Expected request url to be called with given method
:param body: Expected request body to be called with given method
and url. Default is None.
Usage::
self.run_command('flavor-list --extra-specs')
self.assert_called_anytime('GET', '/flavors/detail')
""" """
expected = (method, url) expected = (method, url)

View File

@ -104,9 +104,9 @@ class FixturedTestCase(testscenarios.TestWithScenarios, TestCase):
class TestResponse(requests.Response): class TestResponse(requests.Response):
""" """Class used to wrap requests.Response.
Class used to wrap requests.Response and provide some
convenience to initialize with a dict Provide some convenience to initialize with a dict.
""" """
def __init__(self, data): def __init__(self, data):

View File

@ -2613,16 +2613,14 @@ class GetSecgroupTest(utils.TestCase):
class GetFirstEndpointTest(utils.TestCase): class GetFirstEndpointTest(utils.TestCase):
def test_only_one_endpoint(self): def test_only_one_endpoint(self):
"""If there is only one endpoint, it is returned.""" # If there is only one endpoint, it is returned.
endpoint = {"url": "test"} endpoint = {"url": "test"}
result = novaclient.v2.shell._get_first_endpoint([endpoint], "XYZ") result = novaclient.v2.shell._get_first_endpoint([endpoint], "XYZ")
self.assertEqual(endpoint, result) self.assertEqual(endpoint, result)
def test_multiple_endpoints(self): def test_multiple_endpoints(self):
"""If there are multiple endpoints, the first one of the appropriate # If there are multiple endpoints, the first one of the appropriate
region is returned. # region is returned.
"""
endpoints = [ endpoints = [
{"region": "XYZ"}, {"region": "XYZ"},
{"region": "ORD", "number": 1}, {"region": "ORD", "number": 1},
@ -2632,10 +2630,9 @@ class GetFirstEndpointTest(utils.TestCase):
self.assertEqual(endpoints[1], result) self.assertEqual(endpoints[1], result)
def test_multiple_endpoints_but_none_suitable(self): def test_multiple_endpoints_but_none_suitable(self):
"""If there are multiple endpoints but none of them are suitable, an # If there are multiple endpoints but none of them are suitable, an
exception is raised. # exception is raised.
"""
endpoints = [ endpoints = [
{"region": "XYZ"}, {"region": "XYZ"},
{"region": "PQR"}, {"region": "PQR"},
@ -2646,7 +2643,7 @@ class GetFirstEndpointTest(utils.TestCase):
endpoints, "ORD") endpoints, "ORD")
def test_no_endpoints(self): def test_no_endpoints(self):
"""If there are no endpoints available, an exception is raised.""" # If there are no endpoints available, an exception is raised.
self.assertRaises(LookupError, self.assertRaises(LookupError,
novaclient.v2.shell._get_first_endpoint, novaclient.v2.shell._get_first_endpoint,
[], "ORD") [], "ORD")