summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--heatclient/common/http.py3
-rw-r--r--heatclient/common/utils.py2
-rw-r--r--heatclient/v1/__init__.py2
-rw-r--r--heatclient/v1/events.py3
-rw-r--r--heatclient/v1/resources.py2
-rw-r--r--heatclient/v1/stacks.py1
-rw-r--r--tests/fakes.py3
-rw-r--r--tests/test_common_http.py100
-rw-r--r--tests/test_shell.py85
-rw-r--r--tests/test_utils.py7
10 files changed, 111 insertions, 97 deletions
diff --git a/heatclient/common/http.py b/heatclient/common/http.py
index 16d1bf6..e759121 100644
--- a/heatclient/common/http.py
+++ b/heatclient/common/http.py
@@ -18,7 +18,6 @@ import httplib
import logging
import os
import socket
-import StringIO
import urlparse
try:
@@ -164,7 +163,7 @@ class HTTPClient(object):
elif resp.status in (301, 302, 305):
# Redirected. Reissue the request to the new location.
location = resp.getheader('location', None)
- if location == None:
+ if location is None:
message = "Location not returned with 302"
raise exc.InvalidEndpoint(message=message)
elif location.startswith(self.endpoint):
diff --git a/heatclient/common/utils.py b/heatclient/common/utils.py
index c0f3439..07e20b8 100644
--- a/heatclient/common/utils.py
+++ b/heatclient/common/utils.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import errno
-import hashlib
import os
import sys
import uuid
diff --git a/heatclient/v1/__init__.py b/heatclient/v1/__init__.py
index d0322d2..9278018 100644
--- a/heatclient/v1/__init__.py
+++ b/heatclient/v1/__init__.py
@@ -13,4 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
+__all__ = ['Client']
+
from heatclient.v1.client import Client
diff --git a/heatclient/v1/events.py b/heatclient/v1/events.py
index 07d9f5c..42a111e 100644
--- a/heatclient/v1/events.py
+++ b/heatclient/v1/events.py
@@ -15,7 +15,6 @@
from heatclient.common import base
from heatclient.v1 import stacks
-import heatclient.exc as exc
DEFAULT_PAGE_SIZE = 20
@@ -43,7 +42,7 @@ class EventManager(stacks.StackChildManager):
:param resource_name: Optional name of resources to filter events by
:rtype: list of :class:`Event`
"""
- if resource_name == None:
+ if resource_name is None:
url = '/stacks/%s/events' % stack_id
else:
stack_id = self._resolve_stack_id(stack_id)
diff --git a/heatclient/v1/resources.py b/heatclient/v1/resources.py
index d692e51..a25fcca 100644
--- a/heatclient/v1/resources.py
+++ b/heatclient/v1/resources.py
@@ -13,10 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
from heatclient.common import base
from heatclient.v1 import stacks
-import heatclient.exc as exc
DEFAULT_PAGE_SIZE = 20
diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py
index f9980a4..27d6466 100644
--- a/heatclient/v1/stacks.py
+++ b/heatclient/v1/stacks.py
@@ -16,7 +16,6 @@
import urllib
from heatclient.common import base
-import heatclient.exc as exc
DEFAULT_PAGE_SIZE = 20
diff --git a/tests/fakes.py b/tests/fakes.py
index 00e1669..96034ea 100644
--- a/tests/fakes.py
+++ b/tests/fakes.py
@@ -1,7 +1,4 @@
-
-import httplib
import json
-import mox
from keystoneclient.v2_0 import client as ksclient
from heatclient.v1 import client as v1client
diff --git a/tests/test_common_http.py b/tests/test_common_http.py
index eb10590..aa26e9e 100644
--- a/tests/test_common_http.py
+++ b/tests/test_common_http.py
@@ -1,16 +1,5 @@
-import StringIO
-import os
-import httplib2
-import httplib
-import sys
-
import mox
import unittest
-try:
- import json
-except ImportError:
- import simplejson as json
-from keystoneclient.v2_0 import client as ksclient
from heatclient import exc
from heatclient.common import http
@@ -36,9 +25,11 @@ class HttpClientTest(unittest.TestCase):
mock_conn.request('GET', '/',
headers={'Content-Type': 'application/octet-stream',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(200, 'OK',
- {'content-type': 'application/octet-stream'},
- ''))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'application/octet-stream'},
+ ''))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -55,9 +46,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(200, 'OK',
- {'content-type': 'application/json'},
- '{}'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'application/json'},
+ '{}'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -74,9 +67,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(200, 'OK',
- {'content-type': 'application/json'},
- '{}'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'application/json'},
+ '{}'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -93,9 +88,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(200, 'OK',
- {'content-type': 'not/json'},
- '{}'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'not/json'},
+ '{}'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -112,9 +109,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(200, 'OK',
- {'content-type': 'application/json'},
- 'invalid-json'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'application/json'},
+ 'invalid-json'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -131,9 +130,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(302, 'Found',
- {'location': 'http://example.com:8004'
- }, ''))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 302, 'Found',
+ {'location': 'http://example.com:8004'},
+ ''))
# Record the following 200
mock_conn = http.httplib.HTTPConnection('example.com', 8004,
'', timeout=600.0)
@@ -141,9 +142,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(200, 'OK',
- {'content-type': 'application/json'},
- '{}'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'application/json'},
+ '{}'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -160,9 +163,11 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(302, 'Found',
- {'location': 'http://prohibited.example.com:8004'
- }, ''))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 302, 'Found',
+ {'location': 'http://prohibited.example.com:8004'},
+ ''))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -177,9 +182,10 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(404, 'OK',
- {'content-type': 'application/json'},
- '{}'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 404, 'OK', {'content-type': 'application/json'},
+ '{}'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -201,9 +207,10 @@ class HttpClientTest(unittest.TestCase):
headers={'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'python-heatclient'})
- mock_conn.getresponse().AndReturn(fakes.FakeHTTPResponse(300, 'OK',
- {'content-type': 'application/json'},
- '{}'))
+ mock_conn.getresponse().AndReturn(
+ fakes.FakeHTTPResponse(
+ 300, 'OK', {'content-type': 'application/json'},
+ '{}'))
# Replay, create client, assert
self.m.ReplayAll()
client = http.HTTPClient('http://example.com:8004')
@@ -230,14 +237,15 @@ class HttpClientTest(unittest.TestCase):
# '{}'))
# # Replay, create client, assert
# self.m.ReplayAll()
- # client = http.HTTPClient('https://example.com:8004', ca_file='dummy',
- # cert_file='dummy',
- # key_file='dummy')
+ # client = http.HTTPClient('https://example.com:8004',
+ # ca_file='dummy',
+ # cert_file='dummy',
+ # key_file='dummy')
# resp, body = client.json_request('GET', '')
# self.assertEqual(resp.status, 200)
# self.assertEqual(body, {})
# self.m.VerifyAll()
def test_fake_json_request(self):
- self.assertRaises(exc.InvalidEndpoint, http.HTTPClient, 'fake://example.com:8004')
-
+ self.assertRaises(exc.InvalidEndpoint, http.HTTPClient,
+ 'fake://example.com:8004')
diff --git a/tests/test_shell.py b/tests/test_shell.py
index 9d0dac9..0fe890e 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -29,8 +29,8 @@ class TestCase(unittest.TestCase):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(text):
msg = msg or "Regexp didn't match"
- msg = '%s: %r not found in %r' % (msg, expected_regexp.pattern,
- text)
+ msg = '%s: %r not found in %r' % (
+ msg, expected_regexp.pattern, text)
raise self.failureException(msg)
@@ -78,8 +78,8 @@ class ShellValidationTest(TestCase):
m.StubOutWithMock(ksclient, 'Client')
m.StubOutWithMock(v1client.Client, 'json_request')
fakes.script_keystone_client()
- v1client.Client.json_request('GET',
- '/stacks?limit=20').AndRaise(exc.Unauthorized)
+ v1client.Client.json_request(
+ 'GET', '/stacks?limit=20').AndRaise(exc.Unauthorized)
m.ReplayAll()
_old_env, os.environ = os.environ, {
@@ -108,7 +108,8 @@ class ShellValidationTest(TestCase):
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where',
}
- self.shell_error('create teststack '
+ self.shell_error(
+ 'create teststack '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17"',
@@ -231,18 +232,18 @@ class ShellTest(TestCase):
def test_describe(self):
fakes.script_keystone_client()
resp_dict = {"stack": {
- "id": "1",
- "stack_name": "teststack",
- "stack_status": 'CREATE_COMPLETE',
- "creation_time": "2012-10-25T01:58:47Z"
- }
- }
- resp = fakes.FakeHTTPResponse(200,
+ "id": "1",
+ "stack_name": "teststack",
+ "stack_status": 'CREATE_COMPLETE',
+ "creation_time": "2012-10-25T01:58:47Z"
+ }}
+ resp = fakes.FakeHTTPResponse(
+ 200,
'OK',
{'content-type': 'application/json'},
json.dumps(resp_dict))
- v1client.Client.json_request('GET',
- '/stacks/teststack/1').AndReturn((resp, resp_dict))
+ v1client.Client.json_request(
+ 'GET', '/stacks/teststack/1').AndReturn((resp, resp_dict))
self.m.ReplayAll()
@@ -264,18 +265,20 @@ class ShellTest(TestCase):
def test_create(self):
fakes.script_keystone_client()
- resp = fakes.FakeHTTPResponse(201,
+ resp = fakes.FakeHTTPResponse(
+ 201,
'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
- v1client.Client.json_request('POST', '/stacks',
- body=mox.IgnoreArg()).AndReturn((resp, None))
+ v1client.Client.json_request(
+ 'POST', '/stacks', body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
- create_text = self.shell('create teststack '
+ create_text = self.shell(
+ 'create teststack '
'--template-file=%s '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
@@ -296,17 +299,19 @@ class ShellTest(TestCase):
def test_create_url(self):
fakes.script_keystone_client()
- resp = fakes.FakeHTTPResponse(201,
+ resp = fakes.FakeHTTPResponse(
+ 201,
'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
- v1client.Client.json_request('POST', '/stacks',
- body=mox.IgnoreArg()).AndReturn((resp, None))
+ v1client.Client.json_request(
+ 'POST', '/stacks', body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
- create_text = self.shell('create teststack '
+ create_text = self.shell(
+ 'create teststack '
'--template-url=http://no.where/minimal.template '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
@@ -328,22 +333,25 @@ class ShellTest(TestCase):
fakes.script_keystone_client()
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
template_data = open(template_file).read()
- v1client.Client.raw_request('GET',
- 'http://no.where/container/minimal.template',
- ).AndReturn(template_data)
+ v1client.Client.raw_request(
+ 'GET',
+ 'http://no.where/container/minimal.template',
+ ).AndReturn(template_data)
- resp = fakes.FakeHTTPResponse(201,
+ resp = fakes.FakeHTTPResponse(
+ 201,
'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
- v1client.Client.json_request('POST', '/stacks',
- body=mox.IgnoreArg()).AndReturn((resp, None))
+ v1client.Client.json_request(
+ 'POST', '/stacks', body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
- create_text = self.shell('create teststack2 '
+ create_text = self.shell(
+ 'create teststack2 '
'--template-object=http://no.where/container/minimal.template '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
@@ -362,18 +370,21 @@ class ShellTest(TestCase):
def test_update(self):
fakes.script_keystone_client()
- resp = fakes.FakeHTTPResponse(202,
+ resp = fakes.FakeHTTPResponse(
+ 202,
'Accepted',
{},
'The request is accepted for processing.')
- v1client.Client.json_request('PUT', '/stacks/teststack2/2',
- body=mox.IgnoreArg()).AndReturn((resp, None))
+ v1client.Client.json_request(
+ 'PUT', '/stacks/teststack2/2',
+ body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
- create_text = self.shell('update teststack2/2 '
+ create_text = self.shell(
+ 'update teststack2/2 '
'--template-file=%s '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
@@ -392,12 +403,14 @@ class ShellTest(TestCase):
def test_delete(self):
fakes.script_keystone_client()
- resp = fakes.FakeHTTPResponse(204,
+ resp = fakes.FakeHTTPResponse(
+ 204,
'No Content',
{},
None)
- v1client.Client.raw_request('DELETE', '/stacks/teststack2/2',
- ).AndReturn((resp, None))
+ v1client.Client.raw_request(
+ 'DELETE', '/stacks/teststack2/2',
+ ).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 57262b6..4aff609 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -19,9 +19,10 @@ from heatclient.common import utils
class shellTest(unittest.TestCase):
def test_format_parameters(self):
- p = utils.format_parameters('InstanceType=m1.large;DBUsername=wp;'
- 'DBPassword=verybadpassword;KeyName=heat_key;'
- 'LinuxDistribution=F17')
+ p = utils.format_parameters(
+ 'InstanceType=m1.large;DBUsername=wp;'
+ 'DBPassword=verybadpassword;KeyName=heat_key;'
+ 'LinuxDistribution=F17')
self.assertEqual({'InstanceType': 'm1.large',
'DBUsername': 'wp',
'DBPassword': 'verybadpassword',