diff --git a/novaclient/tests/functional/base.py b/novaclient/tests/functional/base.py index 86d652322..27ce9ef08 100644 --- a/novaclient/tests/functional/base.py +++ b/novaclient/tests/functional/base.py @@ -59,7 +59,8 @@ class NoCloudConfigException(Exception): 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 only exercises client commands that are read only. diff --git a/novaclient/tests/functional/v2/legacy/test_keypairs.py b/novaclient/tests/functional/v2/legacy/test_keypairs.py index 3b7efefcf..9828df02e 100644 --- a/novaclient/tests/functional/v2/legacy/test_keypairs.py +++ b/novaclient/tests/functional/v2/legacy/test_keypairs.py @@ -20,8 +20,7 @@ from novaclient.tests.functional.v2 import fake_crypto class TestKeypairsNovaClient(base.ClientTestBase): - """Keypairs functional tests. - """ + """Keypairs functional tests.""" COMPUTE_API_VERSION = "2.1" diff --git a/novaclient/tests/functional/v2/legacy/test_quotas.py b/novaclient/tests/functional/v2/legacy/test_quotas.py index d0ee710a2..1cd8ac889 100644 --- a/novaclient/tests/functional/v2/legacy/test_quotas.py +++ b/novaclient/tests/functional/v2/legacy/test_quotas.py @@ -14,8 +14,7 @@ from novaclient.tests.functional import base class TestQuotasNovaClient(base.ClientTestBase): - """Nova quotas functional tests. - """ + """Nova quotas functional tests.""" COMPUTE_API_VERSION = "2.1" diff --git a/novaclient/tests/functional/v2/legacy/test_readonly_nova.py b/novaclient/tests/functional/v2/legacy/test_readonly_nova.py index 7abbeee3f..47e5844c3 100644 --- a/novaclient/tests/functional/v2/legacy/test_readonly_nova.py +++ b/novaclient/tests/functional/v2/legacy/test_readonly_nova.py @@ -18,8 +18,7 @@ from novaclient.tests.functional import base 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. """ diff --git a/novaclient/tests/functional/v2/legacy/test_servers.py b/novaclient/tests/functional/v2/legacy/test_servers.py index 0e968562a..746d556c8 100644 --- a/novaclient/tests/functional/v2/legacy/test_servers.py +++ b/novaclient/tests/functional/v2/legacy/test_servers.py @@ -17,8 +17,7 @@ from novaclient.v2 import shell class TestServersBootNovaClient(base.ClientTestBase): - """Servers boot functional tests. - """ + """Servers boot functional tests.""" COMPUTE_API_VERSION = "2.1" @@ -58,8 +57,7 @@ class TestServersBootNovaClient(base.ClientTestBase): class TestServersListNovaClient(base.ClientTestBase): - """Servers list functional tests. - """ + """Servers list functional tests.""" COMPUTE_API_VERSION = "2.1" diff --git a/novaclient/tests/functional/v2/test_keypairs.py b/novaclient/tests/functional/v2/test_keypairs.py index 35768de7b..c02c2cac5 100644 --- a/novaclient/tests/functional/v2/test_keypairs.py +++ b/novaclient/tests/functional/v2/test_keypairs.py @@ -15,8 +15,7 @@ from novaclient.tests.functional.v2.legacy import test_keypairs 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" diff --git a/novaclient/tests/functional/v2/test_quotas.py b/novaclient/tests/functional/v2/test_quotas.py index 14b5bdfef..5d836e2c4 100644 --- a/novaclient/tests/functional/v2/test_quotas.py +++ b/novaclient/tests/functional/v2/test_quotas.py @@ -14,8 +14,7 @@ from novaclient.tests.functional.v2.legacy import test_quotas class TestQuotasNovaClient(test_quotas.TestQuotasNovaClient): - """Nova quotas functional tests. - """ + """Nova quotas functional tests.""" COMPUTE_API_VERSION = "2.latest" diff --git a/novaclient/tests/functional/v2/test_readonly_nova.py b/novaclient/tests/functional/v2/test_readonly_nova.py index cfe91635a..7ef948eea 100644 --- a/novaclient/tests/functional/v2/test_readonly_nova.py +++ b/novaclient/tests/functional/v2/test_readonly_nova.py @@ -16,8 +16,7 @@ from novaclient.tests.functional.v2.legacy import test_readonly_nova class 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. """ diff --git a/novaclient/tests/functional/v2/test_servers.py b/novaclient/tests/functional/v2/test_servers.py index 9cb034b47..590e543bf 100644 --- a/novaclient/tests/functional/v2/test_servers.py +++ b/novaclient/tests/functional/v2/test_servers.py @@ -17,15 +17,13 @@ from novaclient.tests.functional.v2.legacy import test_servers class TestServersBootNovaClient(test_servers.TestServersBootNovaClient): - """Servers boot functional tests. - """ + """Servers boot functional tests.""" COMPUTE_API_VERSION = "2.latest" class TestServersListNovaClient(test_servers.TestServersListNovaClient): - """Servers list functional tests. - """ + """Servers list functional tests.""" COMPUTE_API_VERSION = "2.latest" diff --git a/novaclient/tests/unit/fakes.py b/novaclient/tests/unit/fakes.py index ef6b59b52..78e10f04f 100644 --- a/novaclient/tests/unit/fakes.py +++ b/novaclient/tests/unit/fakes.py @@ -36,8 +36,40 @@ def assert_has_keys(dict, required=[], optional=[]): class FakeClient(object): def assert_called(self, method, url, body=None, pos=-1): - """ - Assert than an API method was just called. + """Assert than an HTTP method was called at given order/position. + + :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) called = self.client.callstack[pos][0:2] @@ -54,8 +86,15 @@ class FakeClient(object): (self.client.callstack[pos][2], body)) def assert_called_anytime(self, method, url, body=None): - """ - Assert than an API method was called anytime in the test. + """Assert than an HTTP 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) diff --git a/novaclient/tests/unit/utils.py b/novaclient/tests/unit/utils.py index 6aaf0ed20..4c5ec4932 100644 --- a/novaclient/tests/unit/utils.py +++ b/novaclient/tests/unit/utils.py @@ -104,9 +104,9 @@ class FixturedTestCase(testscenarios.TestWithScenarios, TestCase): class TestResponse(requests.Response): - """ - Class used to wrap requests.Response and provide some - convenience to initialize with a dict + """Class used to wrap requests.Response. + + Provide some convenience to initialize with a dict. """ def __init__(self, data): diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 7a6a8e2cc..58d05edae 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -2613,16 +2613,14 @@ class GetSecgroupTest(utils.TestCase): class GetFirstEndpointTest(utils.TestCase): 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"} result = novaclient.v2.shell._get_first_endpoint([endpoint], "XYZ") self.assertEqual(endpoint, result) def test_multiple_endpoints(self): - """If there are multiple endpoints, the first one of the appropriate - region is returned. - - """ + # If there are multiple endpoints, the first one of the appropriate + # region is returned. endpoints = [ {"region": "XYZ"}, {"region": "ORD", "number": 1}, @@ -2632,10 +2630,9 @@ class GetFirstEndpointTest(utils.TestCase): self.assertEqual(endpoints[1], result) def test_multiple_endpoints_but_none_suitable(self): - """If there are multiple endpoints but none of them are suitable, an - exception is raised. + # If there are multiple endpoints but none of them are suitable, an + # exception is raised. - """ endpoints = [ {"region": "XYZ"}, {"region": "PQR"}, @@ -2646,7 +2643,7 @@ class GetFirstEndpointTest(utils.TestCase): endpoints, "ORD") 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, novaclient.v2.shell._get_first_endpoint, [], "ORD")