Fix unittests on Python 3.x
Change-Id: Id9ba3d56006adc8e440c87971d033b217c2589bd
This commit is contained in:
parent
b019452af0
commit
349a9035d7
@ -346,7 +346,7 @@ class Resource(model.Model):
|
||||
|
||||
def _load_models(self):
|
||||
models = globals().copy()
|
||||
for _, model_cls in models.iteritems():
|
||||
for _, model_cls in models.items():
|
||||
endpoint = getattr(model_cls, "_endpoint", None)
|
||||
if endpoint is not None:
|
||||
regexp = endpoint.format(
|
||||
@ -365,7 +365,7 @@ class Resource(model.Model):
|
||||
"""Return the associated resource."""
|
||||
references = {"resource_id": None, "parent_id": None,
|
||||
"grandparent_id": None}
|
||||
for model_cls, regexp in self._regexp.iteritems():
|
||||
for model_cls, regexp in self._regexp.items():
|
||||
match = regexp.search(self.resource_ref)
|
||||
if match is not None:
|
||||
references.update(match.groupdict())
|
||||
|
@ -208,3 +208,15 @@ def run_once(function, state={}, errors={}):
|
||||
def get_client(url, username, password, allow_insecure, ca_bundle):
|
||||
"""Create a new client for the HNV REST API."""
|
||||
return _HNVClient(url, username, password, allow_insecure, ca_bundle)
|
||||
|
||||
|
||||
def get_as_string(value):
|
||||
if value is None or isinstance(value, six.text_type):
|
||||
return value
|
||||
else:
|
||||
try:
|
||||
return value.decode()
|
||||
except Exception:
|
||||
# This is important, because None will be returned,
|
||||
# but not that serious to raise an exception.
|
||||
LOG.error("Couldn't decode: %r", value)
|
||||
|
@ -17,6 +17,8 @@
|
||||
import json
|
||||
import pkg_resources
|
||||
|
||||
from hnv.common import utils
|
||||
|
||||
|
||||
class FakeResponse(object):
|
||||
|
||||
@ -29,9 +31,10 @@ class FakeResponse(object):
|
||||
def _load_resource(self, resource):
|
||||
"""Load the json response for the required resource."""
|
||||
if resource not in self._cache:
|
||||
json_response = pkg_resources.resource_stream(
|
||||
resource_stream = pkg_resources.resource_stream(
|
||||
self._resources, resource)
|
||||
self._cache[resource] = json.load(json_response)
|
||||
json_response = utils.get_as_string(resource_stream.read())
|
||||
self._cache[resource] = json.loads(json_response)
|
||||
return self._cache[resource]
|
||||
|
||||
def logical_networks(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user