Run hacking in a right way
All pep8 issues are resolved Change-Id: Ie6dbd68e17e69cfe7b974831ab5f532310c8c9f9
This commit is contained in:
parent
b71e3fc138
commit
ae3802108c
|
@ -29,9 +29,8 @@ except NameError:
|
|||
|
||||
|
||||
def getid(obj):
|
||||
"""
|
||||
Abstracts the common pattern of allowing both an object or an object's ID
|
||||
(UUID) as a parameter when dealing with relationships.
|
||||
"""Abstracts the common pattern of allowing both an object or
|
||||
an object's ID (UUID) as a parameter when dealing with relationships.
|
||||
"""
|
||||
try:
|
||||
return obj.id
|
||||
|
@ -40,9 +39,8 @@ def getid(obj):
|
|||
|
||||
|
||||
class Manager(object):
|
||||
"""
|
||||
Managers interact with a particular type of API (servers, flavors, images,
|
||||
etc.) and provide CRUD operations for them.
|
||||
"""Managers interact with a particular type of API (servers, flavors,
|
||||
images, etc.) and provide CRUD operations for them.
|
||||
"""
|
||||
resource_class = None
|
||||
|
||||
|
@ -58,7 +56,7 @@ class Manager(object):
|
|||
obj_class = self.resource_class
|
||||
|
||||
if response_key:
|
||||
if not response_key in body:
|
||||
if response_key not in body:
|
||||
body[response_key] = []
|
||||
data = body[response_key]
|
||||
else:
|
||||
|
@ -105,8 +103,7 @@ class Manager(object):
|
|||
|
||||
|
||||
class Resource(object):
|
||||
"""
|
||||
A resource represents a particular instance of an object (tenant, user,
|
||||
"""A resource represents a particular instance of an object (tenant, user,
|
||||
etc). This is pretty much just a bag for attributes.
|
||||
|
||||
:param manager: Manager object
|
||||
|
|
|
@ -20,11 +20,12 @@ import httplib
|
|||
import logging
|
||||
import os
|
||||
import posixpath
|
||||
from six.moves.urllib import parse
|
||||
import socket
|
||||
import StringIO
|
||||
import struct
|
||||
import urlparse
|
||||
from six.moves.urllib import parse
|
||||
|
||||
|
||||
try:
|
||||
import json
|
||||
|
@ -46,16 +47,16 @@ try:
|
|||
from eventlet import patcher
|
||||
# Handle case where we are running in a monkey patched environment
|
||||
if patcher.is_monkey_patched('socket'):
|
||||
from eventlet.green.httplib import HTTPSConnection
|
||||
from eventlet.green.OpenSSL.SSL import GreenConnection as Connection
|
||||
from eventlet.greenio import GreenSocket
|
||||
from eventlet.green.httplib import HTTPSConnection # noqa
|
||||
from eventlet.green.OpenSSL.SSL import GreenConnection as Connection # noqa
|
||||
from eventlet.greenio import GreenSocket # noqa
|
||||
# TODO(mclaren): A getsockopt workaround: see 'getsockopt' doc string
|
||||
GreenSocket.getsockopt = utils.getsockopt
|
||||
else:
|
||||
raise ImportError
|
||||
except ImportError:
|
||||
from httplib import HTTPSConnection
|
||||
from OpenSSL.SSL import Connection as Connection
|
||||
from httplib import HTTPSConnection # noqa
|
||||
from OpenSSL.SSL import Connection as Connection # noqa
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -227,7 +228,7 @@ class HTTPClient(object):
|
|||
raise exc.InvalidEndpoint(message=message)
|
||||
except (socket.error, socket.timeout) as e:
|
||||
endpoint = self.endpoint
|
||||
message = "Error communicating with %(endpoint)s %(e)s" % locals()
|
||||
message = "Error communicating with %s %s" % (endpoint, e)
|
||||
raise exc.CommunicationError(message=message)
|
||||
|
||||
body_iter = ResponseBodyIterator(resp)
|
||||
|
@ -305,8 +306,7 @@ class HTTPClient(object):
|
|||
|
||||
|
||||
class OpenSSLConnectionDelegator(object):
|
||||
"""
|
||||
An OpenSSL.SSL.Connection delegator.
|
||||
"""An OpenSSL.SSL.Connection delegator.
|
||||
|
||||
Supplies an additional 'makefile' method which httplib requires
|
||||
and is not present in OpenSSL.SSL.Connection.
|
||||
|
@ -330,8 +330,7 @@ class OpenSSLConnectionDelegator(object):
|
|||
|
||||
|
||||
class VerifiedHTTPSConnection(HTTPSConnection):
|
||||
"""
|
||||
Extended HTTPSConnection which uses the OpenSSL library
|
||||
"""Extended HTTPSConnection which uses the OpenSSL library
|
||||
for enhanced SSL support.
|
||||
Note: Much of this functionality can eventually be replaced
|
||||
with native Python 3.3 code.
|
||||
|
@ -352,8 +351,7 @@ class VerifiedHTTPSConnection(HTTPSConnection):
|
|||
|
||||
@staticmethod
|
||||
def host_matches_cert(host, x509):
|
||||
"""
|
||||
Verify that the the x509 certificate we have received
|
||||
"""Verify that the the x509 certificate we have received
|
||||
from 'host' correctly identifies the server we are
|
||||
connecting to, ie that the certificate's Common Name
|
||||
or a Subject Alternative Name matches 'host'.
|
||||
|
@ -403,9 +401,7 @@ class VerifiedHTTPSConnection(HTTPSConnection):
|
|||
return preverify_ok
|
||||
|
||||
def setcontext(self):
|
||||
"""
|
||||
Set up the OpenSSL context.
|
||||
"""
|
||||
"""Set up the OpenSSL context."""
|
||||
self.context = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD)
|
||||
|
||||
if self.ssl_compression is False:
|
||||
|
@ -450,8 +446,7 @@ class VerifiedHTTPSConnection(HTTPSConnection):
|
|||
self.context.set_default_verify_paths()
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
Connect to an SSL port using the OpenSSL library and apply
|
||||
"""Connect to an SSL port using the OpenSSL library and apply
|
||||
per-connection parameters.
|
||||
"""
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -475,8 +470,7 @@ class VerifiedHTTPSConnection(HTTPSConnection):
|
|||
|
||||
|
||||
class ResponseBodyIterator(object):
|
||||
"""
|
||||
A class that acts as an iterator over an HTTP response.
|
||||
"""A class that acts as an iterator over an HTTP response.
|
||||
|
||||
This class will also check response body integrity when iterating over
|
||||
the instance and if a checksum was supplied using `set_checksum` method,
|
||||
|
@ -490,8 +484,7 @@ class ResponseBodyIterator(object):
|
|||
self._end_reached = False
|
||||
|
||||
def set_checksum(self, checksum):
|
||||
"""
|
||||
Set checksum to check against when iterating over this instance.
|
||||
"""Set checksum to check against when iterating over this instance.
|
||||
|
||||
:raise: AttributeError if iterator is already consumed.
|
||||
"""
|
||||
|
|
|
@ -13,13 +13,16 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import prettytable
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import os
|
||||
from muranoclient.common import exceptions
|
||||
import prettytable
|
||||
from muranoclient.openstack.common import importutils
|
||||
from muranoclient.openstack.common import strutils
|
||||
|
||||
|
||||
# Decorator for cli-args
|
||||
|
@ -49,7 +52,7 @@ def print_list(objs, fields, field_labels, formatters={}, sortby=0):
|
|||
data = getattr(o, field, None) or ''
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
print pt.get_string(sortby=field_labels[sortby])
|
||||
print(strutils.safe_encode(pt.get_string()))
|
||||
|
||||
|
||||
def print_dict(d, formatters={}):
|
||||
|
@ -61,7 +64,7 @@ def print_dict(d, formatters={}):
|
|||
pt.add_row([field, formatters[field](d[field])])
|
||||
else:
|
||||
pt.add_row([field, d[field]])
|
||||
print pt.get_string(sortby='Property')
|
||||
print(strutils.safe_encode(pt.get_string(sortby='Property')))
|
||||
|
||||
|
||||
def find_resource(manager, name_or_id):
|
||||
|
@ -115,13 +118,12 @@ def import_versioned_module(version, submodule=None):
|
|||
|
||||
def exit(msg=''):
|
||||
if msg:
|
||||
print >> sys.stderr, msg
|
||||
print(strutils.safe_encode(msg), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def getsockopt(self, *args, **kwargs):
|
||||
"""
|
||||
A function which allows us to monkey patch eventlet's
|
||||
"""A function which allows us to monkey patch eventlet's
|
||||
GreenSocket, adding a required 'getsockopt' method.
|
||||
TODO: (mclaren) we can remove this once the eventlet fix
|
||||
(https://bitbucket.org/eventlet/eventlet/commits/609f230)
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
Command-line interface to the Murano Project.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
|
@ -23,8 +25,8 @@ import sys
|
|||
import httplib2
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
from muranoclient import client as apiclient
|
||||
from muranoclient.common import utils, exceptions
|
||||
|
||||
from muranoclient.common import exceptions
|
||||
from muranoclient.common import utils
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -281,8 +283,7 @@ class MuranoShell(object):
|
|||
@utils.arg('command', metavar='<subcommand>', nargs='?',
|
||||
help='Display help for <subcommand>')
|
||||
def do_help(self, args):
|
||||
"""
|
||||
Display help about this program or one of its subcommands.
|
||||
"""Display help about this program or one of its subcommands.
|
||||
"""
|
||||
if getattr(args, 'command', None):
|
||||
if args.command in self.subcommands:
|
||||
|
@ -305,8 +306,11 @@ def main():
|
|||
try:
|
||||
MuranoShell().main(sys.argv[1:])
|
||||
|
||||
except Exception, e:
|
||||
print >> sys.stderr, e
|
||||
except KeyboardInterrupt:
|
||||
print('... terminating murano client', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(utils.exception_to_str(e), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from muranoclient.v1.client import Client
|
|
@ -33,7 +33,7 @@ class Client(http.HTTPClient):
|
|||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
""" Initialize a new client for the Murano v1 API. """
|
||||
"""Initialize a new client for the Murano v1 API."""
|
||||
super(Client, self).__init__(*args, **kwargs)
|
||||
self.environments = environments.EnvironmentManager(self)
|
||||
self.sessions = sessions.SessionManager(self)
|
||||
|
|
|
@ -11,16 +11,16 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import types
|
||||
|
||||
import functools
|
||||
import posixpath
|
||||
from functools import wraps
|
||||
import types
|
||||
|
||||
from muranoclient.common import base
|
||||
|
||||
|
||||
def normalize_path(f):
|
||||
@wraps(f)
|
||||
@functools.wraps(f)
|
||||
def f_normalize_path(*args, **kwargs):
|
||||
path = args[2] if len(args) >= 3 else kwargs['path']
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ from muranoclient.common import utils
|
|||
|
||||
|
||||
def do_environment_list(mc, args={}):
|
||||
"""List the environments"""
|
||||
"""List the environments."""
|
||||
environments = mc.environments.list()
|
||||
field_labels = ['ID', 'Name', 'Created', 'Updated']
|
||||
fields = ['id', 'name', 'created', 'updated']
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
hacking>=0.8.0,<0.9
|
||||
|
||||
mock>=1.0
|
||||
anyjson>=0.3.3
|
||||
|
@ -7,7 +8,6 @@ nose-exclude
|
|||
nosexcover
|
||||
openstack.nose_plugin>=0.7
|
||||
nosehtmloutput>=0.0.3
|
||||
pep8==1.3.3
|
||||
sphinx>=1.1.2,<1.2
|
||||
unittest2
|
||||
httpretty>=0.6.3
|
||||
|
|
|
@ -12,10 +12,12 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import unittest2 as unittest
|
||||
import logging
|
||||
from httpretty import HTTPretty, httprettified
|
||||
from muranoclient.client import Client
|
||||
|
||||
import httpretty as http
|
||||
import unittest2 as unittest
|
||||
|
||||
from muranoclient import client
|
||||
|
||||
|
||||
LOG = logging.getLogger('Unit tests')
|
||||
|
@ -23,20 +25,21 @@ LOG = logging.getLogger('Unit tests')
|
|||
|
||||
@unittest.skip
|
||||
class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_env_list_with_empty_list(self):
|
||||
HTTPretty.register_uri(HTTPretty.GET,
|
||||
"http://no-resolved-host:8001/environments",
|
||||
body='{"environments": []}',
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET,
|
||||
"http://no-resolved-host:8001/environments",
|
||||
body='{"environments": []}',
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.environments.list()
|
||||
assert result == []
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_env_list_with_elements(self):
|
||||
body = ('{"environments":['
|
||||
'{"id": "0ce373a477f211e187a55404a662f968",'
|
||||
|
@ -50,37 +53,39 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'"updated": "2010-11-30T03:23:44Z",'
|
||||
'"tenant-id": "0849006f7ce94961b3aab4e4626f229a"}'
|
||||
']}')
|
||||
HTTPretty.register_uri(HTTPretty.GET,
|
||||
"http://no-resolved-host:8001/environments",
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET,
|
||||
"http://no-resolved-host:8001/environments",
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.environments.list()
|
||||
assert result[0].name == 'dc1'
|
||||
assert result[-1].name == 'dc2'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_env_create(self):
|
||||
body = ('{"id": "0ce373a477f211e187a55404a662f968",'
|
||||
'"name": "test",'
|
||||
'"created": "2010-11-30T03:23:42Z",'
|
||||
'"updated": "2010-11-30T03:23:44Z",'
|
||||
'"tenant-id": "0849006f7ce94961b3aab4e46d6f229a"}')
|
||||
HTTPretty.register_uri(HTTPretty.POST,
|
||||
"http://no-resolved-host:8001/environments",
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.POST,
|
||||
"http://no-resolved-host:8001/environments",
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.environments.create('test')
|
||||
assert result.name == 'test'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_ad_list(self):
|
||||
body = ('{"activeDirectories": [{'
|
||||
'"id": "1",'
|
||||
|
@ -94,17 +99,18 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'"location": "test"}]}]}')
|
||||
url = ("http://no-resolved-host:8001/environments"
|
||||
"/1/activeDirectories")
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.activeDirectories.list('1', 'test')
|
||||
assert result[0].name == 'dc1'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_ad_create(self):
|
||||
body = ('{'
|
||||
'"id": "1",'
|
||||
|
@ -118,32 +124,34 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'"location": "test"}]}')
|
||||
url = ("http://no-resolved-host:8001/environments"
|
||||
"/1/activeDirectories")
|
||||
HTTPretty.register_uri(HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.services.post('1', 'test', 'ad1')
|
||||
assert result.name == 'ad1'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_ad_list_without_elements(self):
|
||||
body = '{"activeDirectories": []}'
|
||||
url = ("http://no-resolved-host:8001/environments"
|
||||
"/1/activeDirectories")
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.activeDirectories.list('1', 'test')
|
||||
assert result == []
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_iis_list(self):
|
||||
body = ('{"webServers": [{'
|
||||
'"id": "1",'
|
||||
|
@ -157,17 +165,18 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'"location": "test"}]}]}')
|
||||
url = ("http://no-resolved-host:8001/environments"
|
||||
"/1/webServers")
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.webServers.list('1', 'test')
|
||||
assert result[0].name == 'iis11'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_iis_create(self):
|
||||
body = ('{'
|
||||
'"id": "1",'
|
||||
|
@ -181,32 +190,34 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'"location": "test"}]}')
|
||||
url = ("http://no-resolved-host:8001/environments"
|
||||
"/1/webServers")
|
||||
HTTPretty.register_uri(HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.webServers.create('1', 'test', 'iis12')
|
||||
assert result.name == 'iis12'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_iis_list_without_elements(self):
|
||||
body = '{"webServers": []}'
|
||||
url = ("http://no-resolved-host:8001/environments"
|
||||
"/1/webServers")
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.webServers.list('1', 'test')
|
||||
assert result == []
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_aspapp_list(self):
|
||||
body = '''
|
||||
{
|
||||
|
@ -244,17 +255,18 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'''
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/aspNetApps'
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.aspNetApps.list('1', 'test')
|
||||
result = test_client.Client.aspNetApps.list('1', 'test')
|
||||
assert result[0].name == 'frontend'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_aspapp_create(self):
|
||||
body = '''
|
||||
{
|
||||
|
@ -274,32 +286,34 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'''
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/aspNetApps'
|
||||
HTTPretty.register_uri(HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.aspNetApps.create('1', 'test', 'test')
|
||||
assert result.name == 'frontend'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_aspapp_list_without_elements(self):
|
||||
body = '{"aspNetApps": []}'
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/aspNetApps'
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.aspNetApps.list('1', 'test')
|
||||
assert result == []
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_webfarm_list(self):
|
||||
body = '''
|
||||
{
|
||||
|
@ -332,17 +346,18 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'''
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/webServerFarms'
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.webServerFarms.list('1', 'test')
|
||||
assert result[0].name == 'frontend'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_webfarm_create(self):
|
||||
body = '''
|
||||
{
|
||||
|
@ -359,32 +374,34 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'''
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/webServerFarms'
|
||||
HTTPretty.register_uri(HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.webServerFarms.create('1', 'test', 'test')
|
||||
assert result.name == 'frontend'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_webfarm_list_without_elements(self):
|
||||
body = '{"webServerFarms": []}'
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/webServerFarms'
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.webServerFarms.list('1', 'test')
|
||||
assert result == []
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_aspappfarm_list(self):
|
||||
body = '''
|
||||
{
|
||||
|
@ -417,17 +434,18 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'''
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/aspNetAppFarms'
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.aspNetAppFarms.list('1', 'test')
|
||||
assert result[0].name == 'frontend'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_aspappfarm_create(self):
|
||||
body = '''
|
||||
{
|
||||
|
@ -443,27 +461,29 @@ class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
|||
'''
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/aspNetAppFarms'
|
||||
HTTPretty.register_uri(HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.POST, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.aspNetAppFarms.create('1', 'test', 'test')
|
||||
assert result.name == 'frontend'
|
||||
|
||||
@httprettified
|
||||
@http.httprettified
|
||||
def test_client_aspappfarm_list_without_elements(self):
|
||||
body = '{"aspNetAppFarms": []}'
|
||||
url = 'http://no-resolved-host:8001/environments' \
|
||||
'/1/aspNetAppFarms'
|
||||
HTTPretty.register_uri(HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={
|
||||
'Content-Type': 'application/json', })
|
||||
http.HTTPretty.register_uri(
|
||||
http.HTTPretty.GET, url,
|
||||
body=body,
|
||||
adding_headers={'Content-Type': 'application/json', })
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
result = test_client.aspNetAppFarms.list('1', 'test')
|
||||
assert result == []
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import unittest2 as unittest
|
||||
import logging
|
||||
from mock import MagicMock
|
||||
|
||||
from muranoclient.client import Client
|
||||
import mock
|
||||
import unittest2 as unittest
|
||||
|
||||
from muranoclient import client
|
||||
import muranoclient.v1.environments as environments
|
||||
import muranoclient.v1.services as services
|
||||
import muranoclient.v1.sessions as sessions
|
||||
|
||||
|
||||
|
@ -27,14 +27,15 @@ def my_mock(*a, **b):
|
|||
|
||||
|
||||
LOG = logging.getLogger('Unit tests')
|
||||
api = MagicMock(json_request=my_mock)
|
||||
api = mock.MagicMock(json_request=my_mock)
|
||||
|
||||
|
||||
class UnitTestsForClassesAndFunctions(unittest.TestCase):
|
||||
def test_create_client_instance(self):
|
||||
|
||||
endpoint = 'http://no-resolved-host:8001'
|
||||
test_client = Client('1', endpoint=endpoint, token='1', timeout=10)
|
||||
test_client = client.Client('1', endpoint=endpoint,
|
||||
token='1', timeout=10)
|
||||
|
||||
assert test_client.environments is not None
|
||||
assert test_client.sessions is not None
|
||||
|
|
17
tox.ini
17
tox.ini
|
@ -1,7 +1,11 @@
|
|||
[tox]
|
||||
envlist = py27,pep8,pep8,pyflakes
|
||||
envlist = py26,py27,pep8
|
||||
minversion = 1.6
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
usedevelop = True
|
||||
install_command = pip install -U {opts} {packages}
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
NOSE_WITH_OPENSTACK=1
|
||||
NOSE_OPENSTACK_COLOR=1
|
||||
|
@ -10,11 +14,11 @@ setenv = VIRTUAL_ENV={envdir}
|
|||
NOSE_OPENSTACK_SHOW_ELAPSED=1
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
commands = nosetests
|
||||
commands = nosetests -w tests
|
||||
|
||||
[testenv:pep8]
|
||||
deps = pep8==1.3.3
|
||||
commands = pep8 --repeat --show-source muranoclient setup.py
|
||||
commands =
|
||||
flake8 {posargs}
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
||||
|
@ -50,9 +54,8 @@ deps = flake8
|
|||
commands = flake8
|
||||
|
||||
[flake8]
|
||||
# H301 one import per line
|
||||
# H302 import only modules
|
||||
ignore = H301,H302,F401,F812
|
||||
# F812 list comprehension redefines
|
||||
ignore = F812
|
||||
show-source = true
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools
|
||||
|
|
Loading…
Reference in New Issue