summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Guzev <aguzev@mirantis.com>2015-06-09 20:37:10 +0300
committerAleksei Guzev <aguzev@mirantis.com>2015-06-19 12:58:16 +0300
commit868a116f178b5d3f2749f4b5b0c736b73d60e439 (patch)
tree4a427d490e1a5933c285fe482358a12a9c308aab
parent4b193e11712847e9b5a80a507124f5d22749ae8d (diff)
downloadpython-heatclient-868a116f178b5d3f2749f4b5b0c736b73d60e439.tar.gz
Fixed VerifyAll() when test case does ReplayAll()
- VerifyAll() methods moved to setUp into addCleanup method for some tests - redundant VerifyAll() methods were removed - removed ResetAll() methods - fixed some broken tests Change-Id: If3a47e610264fe65d76b34c088a1ab3199d72438 Closes-Bug: #1419469
-rw-r--r--heatclient/tests/unit/test_common_http.py30
-rw-r--r--heatclient/tests/unit/test_events.py2
-rw-r--r--heatclient/tests/unit/test_resources.py32
-rw-r--r--heatclient/tests/unit/test_shell.py2
-rw-r--r--heatclient/tests/unit/test_template_utils.py3
-rw-r--r--heatclient/tests/unit/test_utils.py1
6 files changed, 24 insertions, 46 deletions
diff --git a/heatclient/tests/unit/test_common_http.py b/heatclient/tests/unit/test_common_http.py
index 0dd106d..6a04516 100644
--- a/heatclient/tests/unit/test_common_http.py
+++ b/heatclient/tests/unit/test_common_http.py
@@ -35,8 +35,8 @@ class HttpClientTest(testtools.TestCase):
super(HttpClientTest, self).setUp()
self.m = mox.Mox()
self.m.StubOutWithMock(requests, 'request')
+ self.addCleanup(self.m.VerifyAll)
self.addCleanup(self.m.UnsetStubs)
- self.addCleanup(self.m.ResetAll)
def test_http_raw_request(self):
headers = {'Content-Type': 'application/octet-stream',
@@ -57,7 +57,6 @@ class HttpClientTest(testtools.TestCase):
resp = client.raw_request('GET', '')
self.assertEqual(200, resp.status_code)
self.assertEqual('', ''.join([x for x in resp.content]))
- self.m.VerifyAll()
def test_token_or_credentials(self):
# Record a 200
@@ -107,7 +106,6 @@ class HttpClientTest(testtools.TestCase):
client.auth_token = 'abcd1234'
resp = client.raw_request('GET', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_include_pass(self):
# Record a 200
@@ -160,7 +158,6 @@ class HttpClientTest(testtools.TestCase):
client.auth_token = 'abcd1234'
resp = client.raw_request('GET', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_not_include_pass(self):
# Record a 200
@@ -206,7 +203,6 @@ class HttpClientTest(testtools.TestCase):
client.region_name = 'RegionOne'
resp = client.raw_request('GET', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_http_json_request(self):
# Record a 200
@@ -227,7 +223,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '')
self.assertEqual(200, resp.status_code)
self.assertEqual({}, body)
- self.m.VerifyAll()
def test_http_json_request_argument_passed_to_requests(self):
"""Check that we have sent the proper arguments to requests."""
@@ -257,7 +252,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '', data='text')
self.assertEqual(200, resp.status_code)
self.assertEqual({}, body)
- self.m.VerifyAll()
def test_http_json_request_w_req_body(self):
# Record a 200
@@ -279,7 +273,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '', body='test-body')
self.assertEqual(200, resp.status_code)
self.assertEqual({}, body)
- self.m.VerifyAll()
def test_http_json_request_non_json_resp_cont_type(self):
# Record a 200
@@ -300,7 +293,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '', body='test-body')
self.assertEqual(200, resp.status_code)
self.assertIsNone(body)
- self.m.VerifyAll()
def test_http_json_request_invalid_json(self):
# Record a 200
@@ -321,7 +313,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '')
self.assertEqual(200, resp.status_code)
self.assertEqual('invalid-json', body)
- self.m.VerifyAll()
def test_http_manual_redirect_delete(self):
mock_conn = http.requests.request(
@@ -353,7 +344,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('DELETE', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_http_manual_redirect_post(self):
mock_conn = http.requests.request(
@@ -385,7 +375,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('POST', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_http_manual_redirect_put(self):
mock_conn = http.requests.request(
@@ -417,7 +406,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('PUT', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_http_manual_redirect_put_uppercase(self):
mock_conn = http.requests.request(
@@ -449,7 +437,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('PUT', '')
self.assertEqual(200, resp.status_code)
- self.m.VerifyAll()
def test_http_manual_redirect_prohibited(self):
mock_conn = http.requests.request(
@@ -467,7 +454,6 @@ class HttpClientTest(testtools.TestCase):
client = http.HTTPClient('http://example.com:8004/foo')
self.assertRaises(exc.InvalidEndpoint,
client.json_request, 'DELETE', '')
- self.m.VerifyAll()
def test_http_manual_redirect_error_without_location(self):
mock_conn = http.requests.request(
@@ -485,7 +471,6 @@ class HttpClientTest(testtools.TestCase):
client = http.HTTPClient('http://example.com:8004/foo')
self.assertRaises(exc.InvalidEndpoint,
client.json_request, 'DELETE', '')
- self.m.VerifyAll()
def test_http_json_request_redirect(self):
# Record the 302
@@ -518,7 +503,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '')
self.assertEqual(200, resp.status_code)
self.assertEqual({}, body)
- self.m.VerifyAll()
def test_http_404_json_request(self):
# Record a 404
@@ -538,7 +522,6 @@ class HttpClientTest(testtools.TestCase):
e = self.assertRaises(exc.HTTPNotFound, client.json_request, 'GET', '')
# Assert that the raised exception can be converted to string
self.assertIsNotNone(str(e))
- self.m.VerifyAll()
def test_http_300_json_request(self):
# Record a 300
@@ -559,7 +542,6 @@ class HttpClientTest(testtools.TestCase):
exc.HTTPMultipleChoices, client.json_request, 'GET', '')
# Assert that the raised exception can be converted to string
self.assertIsNotNone(str(e))
- self.m.VerifyAll()
def test_fake_json_request(self):
headers = {'User-Agent': 'python-heatclient'}
@@ -572,7 +554,6 @@ class HttpClientTest(testtools.TestCase):
client = http.HTTPClient('fake://example.com:8004')
self.assertRaises(exc.InvalidEndpoint,
client._http_request, "/", "GET")
- self.m.VerifyAll()
def test_debug_curl_command(self):
self.m.StubOutWithMock(logging.Logger, 'debug')
@@ -597,8 +578,6 @@ class HttpClientTest(testtools.TestCase):
client.log_curl_request('GET', '/bar', {'headers': headers,
'data': 'text'})
- self.m.VerifyAll()
-
def test_http_request_socket_error(self):
headers = {'User-Agent': 'python-heatclient'}
mock_conn = http.requests.request('GET', 'http://example.com:8004/',
@@ -610,7 +589,6 @@ class HttpClientTest(testtools.TestCase):
client = http.HTTPClient('http://example.com:8004')
self.assertRaises(exc.CommunicationError,
client._http_request, "/", "GET")
- self.m.VerifyAll()
def test_http_request_socket_timeout(self):
headers = {'User-Agent': 'python-heatclient'}
@@ -623,7 +601,6 @@ class HttpClientTest(testtools.TestCase):
client = http.HTTPClient('http://example.com:8004')
self.assertRaises(exc.CommunicationError,
client._http_request, "/", "GET")
- self.m.VerifyAll()
def test_http_request_specify_timeout(self):
mock_conn = http.requests.request(
@@ -644,7 +621,6 @@ class HttpClientTest(testtools.TestCase):
resp, body = client.json_request('GET', '')
self.assertEqual(200, resp.status_code)
self.assertEqual({}, body)
- self.m.VerifyAll()
def test_get_system_ca_file(self):
chosen = '/etc/ssl/certs/ca-certificates.crt'
@@ -655,8 +631,6 @@ class HttpClientTest(testtools.TestCase):
ca = http.get_system_ca_file()
self.assertEqual(chosen, ca)
- self.m.VerifyAll()
-
def test_insecure_verify_cert_None(self):
client = http.HTTPClient('https://foo', insecure=True)
self.assertFalse(client.verify_cert)
@@ -685,8 +659,6 @@ class HttpClientTest(testtools.TestCase):
client = http.HTTPClient('http://somewhere')
client.log_curl_request("GET", '', kwargs=kwargs)
- self.m.VerifyAll()
-
class SessionClientTest(test_shell.TestCase, testtools.TestCase):
def setUp(self):
diff --git a/heatclient/tests/unit/test_events.py b/heatclient/tests/unit/test_events.py
index ec8e2d2..82e0bb8 100644
--- a/heatclient/tests/unit/test_events.py
+++ b/heatclient/tests/unit/test_events.py
@@ -25,8 +25,8 @@ class EventManagerTest(testtools.TestCase):
def setUp(self):
super(EventManagerTest, self).setUp()
self.m = mox.Mox()
+ self.addCleanup(self.m.VerifyAll)
self.addCleanup(self.m.UnsetStubs)
- self.addCleanup(self.m.ResetAll)
def test_list_event(self):
stack_id = 'teststack',
diff --git a/heatclient/tests/unit/test_resources.py b/heatclient/tests/unit/test_resources.py
index 7c139b9..c3ce71d 100644
--- a/heatclient/tests/unit/test_resources.py
+++ b/heatclient/tests/unit/test_resources.py
@@ -25,7 +25,6 @@ class ResourceManagerTest(testtools.TestCase):
super(ResourceManagerTest, self).setUp()
self.m = mox.Mox()
self.addCleanup(self.m.UnsetStubs)
- self.addCleanup(self.m.ResetAll)
def _base_test(self, expect, key):
@@ -79,6 +78,7 @@ class ResourceManagerTest(testtools.TestCase):
manager = self._base_test(expect, key)
manager.get(**fields)
+ self.m.VerifyAll()
def test_get_with_unicode_resource_name(self):
fields = {'stack_id': 'teststack',
@@ -90,6 +90,7 @@ class ResourceManagerTest(testtools.TestCase):
manager = self._base_test(expect, key)
manager.get(**fields)
+ self.m.VerifyAll()
def test_list(self):
fields = {'stack_id': 'teststack'}
@@ -106,10 +107,6 @@ class ResourceManagerTest(testtools.TestCase):
return FakeResponse()
manager = resources.ResourceManager(FakeClient())
- self.m.StubOutWithMock(manager, '_resolve_stack_id')
- manager._resolve_stack_id('teststack').AndReturn('teststack/abcd1234')
- self.m.ReplayAll()
-
manager.list(**fields)
def test_list_nested(self):
@@ -127,10 +124,6 @@ class ResourceManagerTest(testtools.TestCase):
return FakeResponse()
manager = resources.ResourceManager(FakeClient())
- self.m.StubOutWithMock(manager, '_resolve_stack_id')
- manager._resolve_stack_id('teststack').AndReturn('teststack/abcd1234')
- self.m.ReplayAll()
-
manager.list(**fields)
def test_metadata(self):
@@ -143,14 +136,32 @@ class ResourceManagerTest(testtools.TestCase):
manager = self._base_test(expect, key)
manager.metadata(**fields)
+ self.m.VerifyAll()
def test_generate_template(self):
fields = {'resource_name': 'testresource'}
expect = ('GET', '/resource_types/testresource/template')
key = None
- manager = self._base_test(expect, key)
+ class FakeAPI(object):
+ """Fake API and ensure request url is correct."""
+
+ def get(self, *args, **kwargs):
+ assert ('GET', args[0]) == expect
+
+ def json_request(self, *args, **kwargs):
+ assert args == expect
+ ret = key and {key: []} or {}
+ return {}, {key: ret}
+
+ manager = resources.ResourceManager(FakeAPI())
+ self.m.StubOutWithMock(utils, 'get_response_body')
+ utils.get_response_body(mox.IgnoreArg()).AndReturn(
+ {key: key and {key: []} or {}})
+ self.m.ReplayAll()
+
manager.generate_template(**fields)
+ self.m.VerifyAll()
def test_signal(self):
fields = {'stack_id': 'teststack',
@@ -163,3 +174,4 @@ class ResourceManagerTest(testtools.TestCase):
manager = self._base_test(expect, key)
manager.signal(**fields)
+ self.m.VerifyAll()
diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py
index a4230f0..c27b907 100644
--- a/heatclient/tests/unit/test_shell.py
+++ b/heatclient/tests/unit/test_shell.py
@@ -3782,7 +3782,6 @@ class ShellTestManageService(ShellBase):
self.m.ReplayAll()
e = self.assertRaises(exc.HTTPException,
self.shell, "service-list")
- self.m.VerifyAll()
self.assertIn(message, str(e))
def test_service_list(self):
@@ -3808,7 +3807,6 @@ class ShellTestManageService(ShellBase):
self.m.ReplayAll()
services_text = self.shell('service-list')
- self.m.VerifyAll()
required = [
'hostname', 'binary', 'engine_id', 'host',
diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py
index dbd0b8f..9f917b3 100644
--- a/heatclient/tests/unit/test_template_utils.py
+++ b/heatclient/tests/unit/test_template_utils.py
@@ -508,7 +508,6 @@ class TestGetTemplateContents(testtools.TestCase):
template_utils.resolve_template_get_files(
template, files, base_url)
self.assertEqual({url: content}, files)
- self.m.VerifyAll()
def test_get_zip_content(self):
filename = 'heat.zip'
@@ -1016,5 +1015,3 @@ parameters:
json.loads(files.get(two_url)))
self.assertEqual(b'three contents',
files.get(three_url))
-
- self.m.VerifyAll()
diff --git a/heatclient/tests/unit/test_utils.py b/heatclient/tests/unit/test_utils.py
index 9c1b216..10946eb 100644
--- a/heatclient/tests/unit/test_utils.py
+++ b/heatclient/tests/unit/test_utils.py
@@ -210,7 +210,6 @@ class TestURLFunctions(testtools.TestCase):
super(TestURLFunctions, self).setUp()
self.m = mock.MagicMock()
- self.addCleanup(self.m.VerifyAll)
self.addCleanup(self.m.UnsetStubs)
def test_normalise_file_path_to_url_relative(self):