remove usage of six library from unit tests

Replace six with Python 3 style code.

Change-Id: I5077e71663f6b60bd774f30fcf64b36d4078cf8e
This commit is contained in:
haixin 2020-10-09 18:20:15 +08:00
parent 42b709e446
commit 3831e5500f
35 changed files with 181 additions and 227 deletions

View File

@ -14,7 +14,6 @@
# under the License.
from oslo_serialization import jsonutils
import six
import webob
import webob.dec
import webob.exc
@ -92,7 +91,7 @@ class TestFaults(test.TestCase):
resp = req.get_response(raiser)
self.assertEqual("application/json", resp.content_type)
self.assertEqual(404, resp.status_int)
self.assertIn(six.b('whut?'), resp.body)
self.assertIn('whut?'.encode("utf-8"), resp.body)
def test_raise_403(self):
"""Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
@ -104,8 +103,8 @@ class TestFaults(test.TestCase):
resp = req.get_response(raiser)
self.assertEqual("application/json", resp.content_type)
self.assertEqual(403, resp.status_int)
self.assertNotIn(six.b('resizeNotAllowed'), resp.body)
self.assertIn(six.b('forbidden'), resp.body)
self.assertNotIn('resizeNotAllowed'.encode("utf-8"), resp.body)
self.assertIn('forbidden'.encode("utf-8"), resp.body)
def test_fault_has_status_int(self):
"""Ensure the status_int is set correctly on faults."""
@ -128,11 +127,11 @@ class ExceptionTest(test.TestCase):
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertIn('{"computeFault', six.text_type(resp.body), resp.body)
self.assertIn('{"computeFault', str(resp.body), resp.body)
expected = ('ExceptionWithSafety: some explanation' if expose else
'The server has either erred or is incapable '
'of performing the requested operation.')
self.assertIn(expected, six.text_type(resp.body), resp.body)
self.assertIn(expected, str(resp.body), resp.body)
self.assertEqual(500, resp.status_int, resp.body)
def test_safe_exceptions_are_described_in_faults(self):
@ -148,7 +147,7 @@ class ExceptionTest(test.TestCase):
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertIn(msg, six.text_type(resp.body), resp.body)
self.assertIn(msg, str(resp.body), resp.body)
self.assertEqual(exception_type.code, resp.status_int, resp.body)
if hasattr(exception_type, 'headers'):

View File

@ -15,7 +15,6 @@
# under the License.
import ddt
import six
from manila.api.openstack import api_version_request
from manila.api.openstack import versioned_method
@ -192,7 +191,7 @@ class APIVersionRequestTests(test.TestCase):
request_input = '%s.%s' % (major, minor)
request = api_version_request.APIVersionRequest(
request_input, experimental=experimental)
request_string = six.text_type(request)
request_string = str(request)
self.assertEqual('API Version Request '
'Major: %s, Minor: %s, Experimental: %s' %

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from manila.api.openstack import versioned_method
from manila import test
@ -24,7 +22,7 @@ class VersionedMethodTestCase(test.TestCase):
def test_str(self):
args = ('fake_name', 'fake_min', 'fake_max')
method = versioned_method.VersionedMethod(*(args + (False, None)))
method_string = six.text_type(method)
method_string = str(method)
self.assertEqual('Version Method %s: min: %s, max: %s' % args,
method_string)

View File

@ -14,7 +14,6 @@ import inspect
from unittest import mock
import ddt
import six
import webob
from manila.api.openstack import api_version_request as api_version
@ -30,13 +29,13 @@ from manila.tests.api import fakes
class RequestTest(test.TestCase):
def test_content_type_missing(self):
request = wsgi.Request.blank('/tests/123', method='POST')
request.body = six.b("<body />")
request.body = "<body />".encode("utf-8")
self.assertIsNone(request.get_content_type())
def test_content_type_unsupported(self):
request = wsgi.Request.blank('/tests/123', method='POST')
request.headers["Content-Type"] = "text/html"
request.body = six.b("asdf<br />")
request.body = "asdf<br />".encode("utf-8")
self.assertRaises(exception.InvalidContentType,
request.get_content_type)
@ -257,11 +256,12 @@ class DictSerializerTest(test.TestCase):
class JSONDictSerializerTest(test.TestCase):
def test_json(self):
input_dict = dict(servers=dict(a=(2, 3)))
expected_json = six.b('{"servers":{"a":[2,3]}}')
expected_json = '{"servers":{"a":[2,3]}}'.encode("utf-8")
serializer = wsgi.JSONDictSerializer()
result = serializer.serialize(input_dict)
result = result.replace(six.b('\n'),
six.b('')).replace(six.b(' '), six.b(''))
result = result.replace(
'\n'.encode("utf-8"), ''.encode("utf-8")).replace(
' '.encode("utf-8"), ''.encode("utf-8"))
self.assertEqual(expected_json, result)
@ -303,7 +303,7 @@ class ResourceTest(test.TestCase):
req = webob.Request.blank('/tests')
app = fakes.TestRouter(Controller())
response = req.get_response(app)
self.assertEqual(six.b('off'), response.body)
self.assertEqual('off'.encode("utf-8"), response.body)
self.assertEqual(200, response.status_int)
def test_resource_not_authorized(self):
@ -417,7 +417,7 @@ class ResourceTest(test.TestCase):
request = wsgi.Request.blank('/', method='POST')
request.headers['Content-Type'] = 'application/none'
request.body = six.b('foo')
request.body = 'foo'.encode("utf-8")
content_type, body = resource.get_body(request)
self.assertIsNone(content_type)
@ -432,7 +432,7 @@ class ResourceTest(test.TestCase):
resource = wsgi.Resource(controller)
request = wsgi.Request.blank('/', method='POST')
request.body = six.b('foo')
request.body = 'foo'.encode("utf-8")
content_type, body = resource.get_body(request)
self.assertIsNone(content_type)
@ -448,7 +448,7 @@ class ResourceTest(test.TestCase):
request = wsgi.Request.blank('/', method='POST')
request.headers['Content-Type'] = 'application/json'
request.body = six.b('')
request.body = ''.encode("utf-8")
content_type, body = resource.get_body(request)
self.assertIsNone(content_type)
@ -464,11 +464,11 @@ class ResourceTest(test.TestCase):
request = wsgi.Request.blank('/', method='POST')
request.headers['Content-Type'] = 'application/json'
request.body = six.b('foo')
request.body = 'foo'.encode("utf-8")
content_type, body = resource.get_body(request)
self.assertEqual('application/json', content_type)
self.assertEqual(six.b('foo'), body)
self.assertEqual('foo'.encode("utf-8"), body)
def test_deserialize_badtype(self):
class Controller(object):
@ -923,15 +923,15 @@ class ResponseObjectTest(test.TestCase):
def test_serialize(self):
class JSONSerializer(object):
def serialize(self, obj):
return six.b('json')
return 'json'.encode("utf-8")
class XMLSerializer(object):
def serialize(self, obj):
return six.b('xml')
return 'xml'.encode("utf-8")
class AtomSerializer(object):
def serialize(self, obj):
return six.b('atom')
return 'atom'.encode("utf-8")
robj = wsgi.ResponseObject({}, code=202,
json=JSONSerializer,
@ -948,7 +948,7 @@ class ResponseObjectTest(test.TestCase):
self.assertEqual('header1', response.headers['X-header1'])
self.assertEqual('header2', response.headers['X-header2'])
self.assertEqual(202, response.status_int)
self.assertEqual(six.b(mtype), response.body)
self.assertEqual(mtype.encode("utf-8"), response.body)
class ValidBodyTest(test.TestCase):

View File

@ -17,11 +17,10 @@
Tests dealing with HTTP rate-limiting.
"""
import ddt
import http.client as http_client
import io
from oslo_serialization import jsonutils
import six
from six import moves
from six.moves import http_client
import webob
from manila.api.openstack import api_version_request as api_version
@ -395,7 +394,7 @@ class ParseLimitsTest(BaseLimitTestSuite):
'(POST, /bar*, /bar.*, 5, second);'
'(Say, /derp*, /derp.*, 1, day)')
except ValueError as e:
assert False, six.text_type(e)
assert False, str(e)
# Make sure the number of returned limits are correct
self.assertEqual(4, len(lim))
@ -433,7 +432,7 @@ class LimiterTest(BaseLimitTestSuite):
def _check(self, num, verb, url, username=None):
"""Check and yield results from checks."""
for x in moves.range(num):
for x in range(num):
yield self.limiter.check_for_delay(verb, url, username)[0]
def _check_sum(self, num, verb, url, username=None):
@ -582,7 +581,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
def _request_data(self, verb, path):
"""Get data describing a limit request verb/path."""
return six.b(jsonutils.dumps({"verb": verb, "path": path}))
return jsonutils.dumps({"verb": verb, "path": path}).encode("utf-8")
def _request(self, verb, url, username=None):
"""Send request.
@ -648,7 +647,7 @@ class FakeHttplibSocket(object):
def __init__(self, response_string):
"""Initialize new `FakeHttplibSocket`."""
self._buffer = six.BytesIO(six.b(response_string))
self._buffer = io.BytesIO(response_string.encode("utf-8"))
def makefile(self, _mode, _other=None):
"""Returns the socket's internal buffer."""
@ -677,7 +676,7 @@ class FakeHttplibConnection(object):
req.method = method
req.headers = headers
req.host = self.host
req.body = six.b(body)
req.body = body.encode("utf-8")
resp = str(req.get_response(self.app))
resp = "HTTP/1.0 %s" % resp
@ -761,8 +760,9 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
delay, error = self.proxy.check_for_delay("GET", "/delayed")
error = error.strip()
expected = ("60.00", six.b("403 Forbidden\n\nOnly 1 GET request(s) "
"can be made to /delayed every minute."))
expected = ("60.00", (
"403 Forbidden\n\nOnly 1 GET request(s) can be made to /delayed "
"every minute.").encode("utf-8"))
self.assertEqual(expected, (delay, error))

View File

@ -14,9 +14,9 @@
# under the License.
from unittest import mock
from urllib import parse
import ddt
from six.moves.urllib import parse
import webob
from manila.api.v1 import security_service

View File

@ -16,7 +16,6 @@
import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
import six
import webob
from manila.api.v1 import share_metadata
@ -122,7 +121,7 @@ class ShareMetaDataTest(test.TestCase):
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
res_dict = self.controller.create(req, self.share_id, body)
expected = self.origin_metadata
expected.update(body['metadata'])
@ -140,7 +139,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -150,7 +149,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -162,7 +161,7 @@ class ShareMetaDataTest(test.TestCase):
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
self.assertRaises(
webob.exc.HTTPNotFound,
self.controller.create,
@ -178,7 +177,7 @@ class ShareMetaDataTest(test.TestCase):
'key99': 'value99',
},
}
req.body = six.b(jsonutils.dumps(expected))
req.body = jsonutils.dumps(expected).encode("utf-8")
res_dict = self.controller.update_all(req, self.share_id, expected)
self.assertEqual(expected, res_dict)
@ -188,7 +187,7 @@ class ShareMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': {}}
req.body = six.b(jsonutils.dumps(expected))
req.body = jsonutils.dumps(expected).encode("utf-8")
res_dict = self.controller.update_all(req, self.share_id, expected)
self.assertEqual(expected, res_dict)
@ -198,7 +197,7 @@ class ShareMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
expected = {'meta': {}}
req.body = six.b(jsonutils.dumps(expected))
req.body = jsonutils.dumps(expected).encode("utf-8")
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.share_id,
@ -213,7 +212,7 @@ class ShareMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': metadata}
req.body = six.b(jsonutils.dumps(expected))
req.body = jsonutils.dumps(expected).encode("utf-8")
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.share_id,
@ -224,7 +223,7 @@ class ShareMetaDataTest(test.TestCase):
req.method = 'PUT'
req.content_type = "application/json"
body = {'metadata': {'key10': 'value10'}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.update_all, req, '100', body)
@ -233,7 +232,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
res_dict = self.controller.update(req, self.share_id, 'key1', body)
expected = {'meta': {'key1': 'value1'}}
@ -243,7 +242,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v1.1/fake/shares/asdf/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(
@ -264,7 +263,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -274,7 +273,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -285,7 +284,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": ("a" * 1025)}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -296,7 +295,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -307,7 +306,7 @@ class ShareMetaDataTest(test.TestCase):
req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
@ -321,18 +320,18 @@ class ShareMetaDataTest(test.TestCase):
# test for long key
data = {"metadata": {"a" * 260: "value1"}}
req.body = six.b(jsonutils.dumps(data))
req.body = jsonutils.dumps(data).encode("utf-8")
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.share_id, data)
# test for long value
data = {"metadata": {"key": "v" * 1025}}
req.body = six.b(jsonutils.dumps(data))
req.body = jsonutils.dumps(data).encode("utf-8")
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.share_id, data)
# test for empty key.
data = {"metadata": {"": "value1"}}
req.body = six.b(jsonutils.dumps(data))
req.body = jsonutils.dumps(data).encode("utf-8")
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.share_id, data)

View File

@ -17,7 +17,6 @@ from unittest import mock
import ddt
from oslo_serialization import jsonutils
import six
import webob
from manila.api.v1 import share_snapshots
@ -378,7 +377,7 @@ class ShareSnapshotAdminActionsAPITest(test.TestCase):
body = {action_name: {'status': constants.STATUS_ERROR}}
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())
@ -414,7 +413,7 @@ class ShareSnapshotAdminActionsAPITest(test.TestCase):
action_name = 'os-force_delete'
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.body = six.b(jsonutils.dumps({action_name: {}}))
req.body = jsonutils.dumps({action_name: {}}).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())

View File

@ -20,7 +20,6 @@ from unittest import mock
import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
import six
import webob
from manila.api import common
@ -1114,7 +1113,7 @@ class ShareAdminActionsAPITest(test.TestCase):
body = {'os-reset_status': {'status': constants.STATUS_ERROR}}
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())
@ -1172,7 +1171,7 @@ class ShareAdminActionsAPITest(test.TestCase):
check_model_in_db=False):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.body = six.b(jsonutils.dumps({'os-force_delete': {}}))
req.body = jsonutils.dumps({'os-force_delete': {}}).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())

View File

@ -21,7 +21,6 @@ import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import six
import webob
from manila.api.openstack import wsgi
@ -139,7 +138,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
@ddt.unpack
def test_create(self, microversion, experimental):
fake_snap, expected_snap = self._get_fake_share_group_snapshot()
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
body = {"share_group_snapshot": {"share_group_id": fake_id}}
mock_create = self.mock_object(
self.controller.share_group_api, 'create_share_group_snapshot',
@ -158,12 +157,12 @@ class ShareGroupSnapshotAPITest(test.TestCase):
self.assertEqual(expected_snap, res_dict['share_group_snapshot'])
def test_create_group_does_not_exist(self):
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
body = {"share_group_snapshot": {"share_group_id": fake_id}}
self.mock_object(
self.controller.share_group_api, 'create_share_group_snapshot',
mock.Mock(side_effect=exception.ShareGroupNotFound(
share_group_id=six.text_type(uuidutils.generate_uuid()))))
share_group_id=uuidutils.generate_uuid())))
self.assertRaises(
webob.exc.HTTPBadRequest,
@ -188,7 +187,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_create_invalid_share_group(self):
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
body = {"share_group_snapshot": {"share_group_id": fake_id}}
self.mock_object(
self.controller.share_group_api, 'create_share_group_snapshot',
@ -205,7 +204,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
fake_name = 'fake_name'
fake_snap, expected_snap = self._get_fake_share_group_snapshot(
name=fake_name)
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
mock_create = self.mock_object(
self.controller.share_group_api, 'create_share_group_snapshot',
mock.Mock(return_value=fake_snap))
@ -229,7 +228,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
fake_description = 'fake_description'
fake_snap, expected_snap = self._get_fake_share_group_snapshot(
description=fake_description)
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
mock_create = self.mock_object(
self.controller.share_group_api, 'create_share_group_snapshot',
mock.Mock(return_value=fake_snap))
@ -253,7 +252,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
def test_create_with_name_and_description(self):
fake_name = 'fake_name'
fake_description = 'fake_description'
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
fake_snap, expected_snap = self._get_fake_share_group_snapshot(
description=fake_description, name=fake_name)
mock_create = self.mock_object(
@ -285,7 +284,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
experimental):
fake_name = 'fake_name'
fake_description = 'fake_description'
fake_id = six.text_type(uuidutils.generate_uuid())
fake_id = uuidutils.generate_uuid()
fake_snap, expected_snap = self._get_fake_share_group_snapshot(
description=fake_description, name=fake_name)
self.mock_object(
@ -340,7 +339,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
exc = self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update,
self.request, 'fake_id', body)
self.assertIn('unknown_field', six.text_type(exc))
self.assertIn('unknown_field', str(exc))
self.mock_policy_check.assert_called_once_with(
self.context, self.resource_name, 'update')
@ -349,7 +348,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
exc = self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update,
self.request, 'fake_id', body)
self.assertIn('created_at', six.text_type(exc))
self.assertIn('created_at', str(exc))
self.mock_policy_check.assert_called_once_with(
self.context, self.resource_name, 'update')
@ -603,7 +602,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
req.headers['content-type'] = 'application/json'
action_name = 'force_delete'
body = {action_name: {'status': constants.STATUS_ERROR}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers['X-Openstack-Manila-Api-Version'] = self.api_version
req.headers['X-Openstack-Manila-Api-Experimental'] = True
req.environ['manila.context'] = ctxt
@ -638,7 +637,7 @@ class ShareGroupSnapshotAPITest(test.TestCase):
body = {action_name: {'status': constants.STATUS_ERROR}}
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers['X-Openstack-Manila-Api-Version'] = self.api_version
req.headers['X-Openstack-Manila-Api-Experimental'] = True
req.environ['manila.context'] = ctxt

View File

@ -21,7 +21,6 @@ import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import six
import webob
from manila.api.openstack import wsgi
@ -51,9 +50,9 @@ class ShareGroupAPITest(test.TestCase):
super(ShareGroupAPITest, self).setUp()
self.controller = share_groups.ShareGroupController()
self.resource_name = self.controller.resource_name
self.fake_share_type = {'id': six.text_type(uuidutils.generate_uuid())}
self.fake_share_type = {'id': uuidutils.generate_uuid()}
self.fake_share_group_type = {
'id': six.text_type(uuidutils.generate_uuid())}
'id': uuidutils.generate_uuid()}
self.api_version = '2.34'
self.request = fakes.HTTPRequest.blank(
'/share-groups', version=self.api_version, experimental=True)
@ -167,7 +166,7 @@ class ShareGroupAPITest(test.TestCase):
req_context, self.resource_name, 'create')
def test_group_create_invalid_group_snapshot_state(self):
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_snap_id = uuidutils.generate_uuid()
self.mock_object(
self.controller.share_group_api, 'create',
mock.Mock(side_effect=exception.InvalidShareGroupSnapshot(
@ -399,8 +398,8 @@ class ShareGroupAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_sg_create_with_source_sg_snapshot_id_and_share_network(self):
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_net_id = six.text_type(uuidutils.generate_uuid())
fake_snap_id = uuidutils.generate_uuid()
fake_net_id = uuidutils.generate_uuid()
self.mock_object(share_types, 'get_default_share_type',
mock.Mock(return_value=self.fake_share_type))
mock_api_call = self.mock_object(
@ -421,7 +420,7 @@ class ShareGroupAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_share_group_create_with_source_sg_snapshot_id(self):
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_snap_id = uuidutils.generate_uuid()
fake_share_group, expected_group = self._get_fake_share_group(
source_share_group_snapshot_id=fake_snap_id)
self.mock_object(share_types, 'get_default_share_type',
@ -445,7 +444,7 @@ class ShareGroupAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_share_group_create_with_share_network_id(self):
fake_net_id = six.text_type(uuidutils.generate_uuid())
fake_net_id = uuidutils.generate_uuid()
fake_group, expected_group = self._get_fake_share_group(
share_network_id=fake_net_id)
@ -470,7 +469,7 @@ class ShareGroupAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_sg_create_no_default_share_type_with_share_group_snapshot(self):
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_snap_id = uuidutils.generate_uuid()
fake, expected = self._get_fake_share_group()
self.mock_object(share_types, 'get_default_share_type',
mock.Mock(return_value=None))
@ -540,7 +539,7 @@ class ShareGroupAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_share_group_create_source_group_snapshot_not_in_available(self):
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_snap_id = uuidutils.generate_uuid()
body = {
"share_group": {
"source_share_group_snapshot_id": fake_snap_id,
@ -556,7 +555,7 @@ class ShareGroupAPITest(test.TestCase):
self.context, self.resource_name, 'create')
def test_share_group_create_source_group_snapshot_does_not_exist(self):
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_snap_id = uuidutils.generate_uuid()
body = {
"share_group": {"source_share_group_snapshot_id": fake_snap_id}
}
@ -612,7 +611,7 @@ class ShareGroupAPITest(test.TestCase):
self.controller.create,
self.request, body)
self.assertIn('unknown_field', six.text_type(exc))
self.assertIn('unknown_field', str(exc))
self.mock_policy_check.assert_called_once_with(
self.context, self.resource_name, 'create')
@ -694,7 +693,7 @@ class ShareGroupAPITest(test.TestCase):
self.controller.update,
self.request, 'fake_id', body)
self.assertIn('unknown_field', six.text_type(exc))
self.assertIn('unknown_field', str(exc))
self.mock_policy_check.assert_called_once_with(
self.context, self.resource_name, 'update')
@ -705,7 +704,7 @@ class ShareGroupAPITest(test.TestCase):
self.controller.update,
self.request, 'fake_id', body)
self.assertIn('share_types', six.text_type(exc))
self.assertIn('share_types', str(exc))
self.mock_policy_check.assert_called_once_with(
self.context, self.resource_name, 'update')
@ -973,7 +972,7 @@ class ShareGroupAPITest(test.TestCase):
body = {action_name: {'status': constants.STATUS_ERROR}}
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers['X-Openstack-Manila-Api-Version'] = self.api_version
req.environ['manila.context'] = ctxt
@ -997,7 +996,7 @@ class ShareGroupAPITest(test.TestCase):
req.headers['content-type'] = 'application/json'
action_name = 'force_delete'
body = {action_name: {}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.headers['X-Openstack-Manila-Api-Version'] = self.api_version
req.environ['manila.context'] = ctxt

View File

@ -15,7 +15,6 @@ from unittest import mock
import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
import six
from webob import exc as webob_exc
from manila.api.openstack import api_version_request
@ -246,7 +245,7 @@ class ShareInstancesAPITest(test.TestCase):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.headers['X-Openstack-Manila-Api-Version'] = version
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = ctxt
with mock.patch.object(
@ -310,7 +309,7 @@ class ShareInstancesAPITest(test.TestCase):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.headers['X-Openstack-Manila-Api-Version'] = version
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = ctxt
with mock.patch.object(

View File

@ -15,11 +15,11 @@
import copy
from unittest import mock
from urllib import parse
import ddt
from oslo_db import exception as db_exception
from oslo_utils import timeutils
from six.moves.urllib import parse
from webob import exc as webob_exc
from manila.api import common

View File

@ -18,7 +18,6 @@ from unittest import mock
import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
import six
from webob import exc
from manila.api.openstack import api_version_request as api_version
@ -574,7 +573,7 @@ class ShareReplicasApiTest(test.TestCase):
if method_name in ('index', 'detail'):
arguments.clear()
noauthexc = exception.PolicyNotAuthorized(action=six.text_type(method))
noauthexc = exception.PolicyNotAuthorized(action=method_name)
with mock.patch.object(
policy, 'check_policy', mock.Mock(side_effect=noauthexc)):
@ -615,7 +614,7 @@ class ShareReplicasApiTest(test.TestCase):
action_name: {'replica_state': constants.STATUS_ERROR},
}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = context
with mock.patch.object(
@ -683,7 +682,7 @@ class ShareReplicasApiTest(test.TestCase):
def _force_delete(self, context, req, valid_code=202):
body = {'force_delete': {}}
req.environ['manila.context'] = context
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
with mock.patch.object(
policy, 'check_policy', fakes.mock_fake_admin_check):
@ -725,7 +724,7 @@ class ShareReplicasApiTest(test.TestCase):
share_api_call = self.mock_object(self.controller.share_api,
'update_share_replica')
body = {'resync': {}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = self.admin_context
with mock.patch.object(
@ -746,7 +745,7 @@ class ShareReplicasApiTest(test.TestCase):
side_effect=exception.InvalidHost(reason='')))
body = {'resync': None}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = self.admin_context
with mock.patch.object(
@ -769,7 +768,7 @@ class ShareReplicasApiTest(test.TestCase):
share_api_call = self.mock_object(
share.API, 'update_share_replica', mock.Mock(return_value=None))
body = {'resync': {}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = self.admin_context
with mock.patch.object(

View File

@ -17,7 +17,6 @@ from unittest import mock
import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
import six
from webob import exc
from manila.api.v2 import share_snapshot_instances
@ -193,7 +192,7 @@ class ShareSnapshotInstancesApiTest(test.TestCase):
'body': {'FAKE_KEY': 'FAKE_VAL'},
}
noauthexc = exception.PolicyNotAuthorized(action=six.text_type(method))
noauthexc = exception.PolicyNotAuthorized(action=method_name)
with mock.patch.object(
policy, 'check_policy', mock.Mock(side_effect=noauthexc)):
@ -223,7 +222,7 @@ class ShareSnapshotInstancesApiTest(test.TestCase):
if body is None:
body = {'reset_status': {'status': constants.STATUS_ERROR}}
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = context
with mock.patch.object(

View File

@ -17,7 +17,6 @@ from unittest import mock
import ddt
from oslo_serialization import jsonutils
import six
import webob
from manila.api.openstack import api_version_request as api_version
@ -619,7 +618,7 @@ class ShareSnapshotAdminActionsAPITest(test.TestCase):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.headers['X-Openstack-Manila-Api-Version'] = version
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())
@ -663,7 +662,7 @@ class ShareSnapshotAdminActionsAPITest(test.TestCase):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.headers['X-Openstack-Manila-Api-Version'] = version
req.body = six.b(jsonutils.dumps({action_name: {}}))
req.body = jsonutils.dumps({action_name: {}}).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())

View File

@ -22,7 +22,6 @@ import ddt
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import six
import webob
import webob.exc
@ -2458,7 +2457,7 @@ class ShareAdminActionsAPITest(test.TestCase):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.headers['X-Openstack-Manila-Api-Version'] = version
req.body = six.b(jsonutils.dumps(body))
req.body = jsonutils.dumps(body).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())
@ -2511,7 +2510,7 @@ class ShareAdminActionsAPITest(test.TestCase):
req.method = 'POST'
req.headers['content-type'] = 'application/json'
req.headers['X-Openstack-Manila-Api-Version'] = version
req.body = six.b(jsonutils.dumps({action_name: {}}))
req.body = jsonutils.dumps({action_name: {}}).encode("utf-8")
req.environ['manila.context'] = ctxt
resp = req.get_response(fakes.app())

View File

@ -14,13 +14,13 @@
# under the License.
import code
import io
import readline
import sys
from unittest import mock
import ddt
from oslo_config import cfg
import six
from manila.cmd import manage as manila_manage
from manila import context
@ -68,7 +68,7 @@ class ManilaCmdManageTestCase(test.TestCase):
try:
import bpython
except ImportError as e:
self.skipTest(six.text_type(e))
self.skipTest(str(e))
self.mock_object(bpython, 'embed')
self.shell_commands.run(**kwargs)
bpython.embed.assert_called_once_with()
@ -78,7 +78,7 @@ class ManilaCmdManageTestCase(test.TestCase):
import bpython
import IPython
except ImportError as e:
self.skipTest(six.text_type(e))
self.skipTest(str(e))
self.mock_object(bpython, 'embed',
mock.Mock(side_effect=ImportError()))
self.mock_object(IPython, 'embed')
@ -91,7 +91,7 @@ class ManilaCmdManageTestCase(test.TestCase):
try:
import bpython
except ImportError as e:
self.skipTest(six.text_type(e))
self.skipTest(str(e))
self.mock_object(bpython, 'embed')
self.shell_commands.run()
@ -102,7 +102,7 @@ class ManilaCmdManageTestCase(test.TestCase):
try:
import IPython
except ImportError as e:
self.skipTest(six.text_type(e))
self.skipTest(str(e))
self.mock_object(IPython, 'embed')
self.shell_commands.run(shell='ipython')
@ -117,7 +117,7 @@ class ManilaCmdManageTestCase(test.TestCase):
setattr(IPython.Shell, 'IPShell',
mock.Mock(side_effect=ImportError()))
except ImportError as e:
self.skipTest(six.text_type(e))
self.skipTest(str(e))
self.mock_object(IPython, 'embed',
mock.Mock(side_effect=ImportError()))
self.mock_object(readline, 'parse_and_bind')
@ -148,7 +148,7 @@ class ManilaCmdManageTestCase(test.TestCase):
readline.parse_and_bind.assert_called_once_with("tab:complete")
code.interact.assert_called_once_with()
@mock.patch('six.moves.builtins.print')
@mock.patch('builtins.print')
def test_list(self, print_mock):
serv_1 = {
'host': 'fake_host1',
@ -170,7 +170,7 @@ class ManilaCmdManageTestCase(test.TestCase):
mock.call(u'host \tzone '),
mock.call('fake_host1 \tavail_zone1 ')])
@mock.patch('six.moves.builtins.print')
@mock.patch('builtins.print')
def test_list_zone_is_none(self, print_mock):
serv_1 = {
'host': 'fake_host1',
@ -221,7 +221,7 @@ class ManilaCmdManageTestCase(test.TestCase):
def test_version_commands_list(self):
self.mock_object(version, 'version_string',
mock.Mock(return_value='123'))
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
self.version_commands.list()
version.version_string.assert_called_once_with()
self.assertEqual('123\n', fake_out.getvalue())
@ -229,13 +229,13 @@ class ManilaCmdManageTestCase(test.TestCase):
def test_version_commands_call(self):
self.mock_object(version, 'version_string',
mock.Mock(return_value='123'))
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
self.version_commands()
version.version_string.assert_called_once_with()
self.assertEqual('123\n', fake_out.getvalue())
def test_get_log_commands_no_errors(self):
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
CONF.set_override('log_dir', None)
expected_out = 'No errors in logfiles!\n'
@ -243,14 +243,14 @@ class ManilaCmdManageTestCase(test.TestCase):
self.assertEqual(expected_out, fake_out.getvalue())
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('os.listdir')
def test_get_log_commands_errors(self, listdir, open):
CONF.set_override('log_dir', 'fake-dir')
listdir.return_value = ['fake-error.log']
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
open.return_value = six.StringIO(
with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
open.return_value = io.StringIO(
'[ ERROR ] fake-error-message')
expected_out = ('fake-dir/fake-error.log:-\n'
'Line 1 : [ ERROR ] fake-error-message\n')
@ -260,7 +260,7 @@ class ManilaCmdManageTestCase(test.TestCase):
open.assert_called_once_with('fake-dir/fake-error.log', 'r')
listdir.assert_called_once_with(CONF.log_dir)
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('os.path.exists')
def test_get_log_commands_syslog_no_log_file(self, path_exists, open):
path_exists.return_value = False
@ -283,7 +283,7 @@ class ManilaCmdManageTestCase(test.TestCase):
'disabled': False}
service_get_all.return_value = [service]
service_is_up.return_value = True
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
format = "%-16s %-36s %-16s %-10s %-5s %-10s"
print_format = format % ('Binary',
'Host',
@ -321,7 +321,7 @@ class ManilaCmdManageTestCase(test.TestCase):
self.mock_object(utils, 'service_is_up',
mock.Mock(return_value=service_is_up))
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:
if not service_is_up:
expected_out = "Cleaned up service %s" % service['host']
else:
@ -428,7 +428,7 @@ class ManilaCmdManageTestCase(test.TestCase):
self.mock_object(db, 'share_resources_host_update',
mock.Mock(return_value=db_op))
with mock.patch('sys.stdout', new=six.StringIO()) as intercepted_op:
with mock.patch('sys.stdout', new=io.StringIO()) as intercepted_op:
self.share_cmds.update_host(current_host, new_host, force)
expected_op = ("Updated host of 3 share instances, 4 share groups and "

View File

@ -39,7 +39,6 @@ import datetime
from oslo_db import exception as oslo_db_exc
from oslo_utils import uuidutils
import six
from sqlalchemy import exc as sa_exc
from manila.common import constants
@ -84,9 +83,7 @@ def map_to_migration(revision):
return decorator
class BaseMigrationChecks(object):
six.add_metaclass(abc.ABCMeta)
class BaseMigrationChecks(metaclass=abc.ABCMeta):
def __init__(self):
self.test_case = None

View File

@ -26,7 +26,6 @@ import ddt
from oslo_db import exception as db_exception
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from manila.common import constants
from manila import context
@ -2049,7 +2048,7 @@ class DriverPrivateDataDatabaseAPITestCase(test.TestCase):
@ddt.data({"details": {"foo": "bar", "tee": "too"},
"valid": {"foo": "bar", "tee": "too"}},
{"details": {"foo": "bar", "tee": ["test"]},
"valid": {"foo": "bar", "tee": six.text_type(["test"])}})
"valid": {"foo": "bar", "tee": str(["test"])}})
@ddt.unpack
def test_update(self, details, valid):
test_id = self._get_driver_test_data()

View File

@ -14,7 +14,6 @@
# under the License.
from oslo_log import log
import six
from manila.common import constants
from manila.share import driver
@ -51,7 +50,7 @@ class FakeShareDriver(driver.ShareDriver):
def manage_existing(self, share, driver_options, share_server=None):
LOG.debug("Fake share driver: manage")
LOG.debug("Fake share driver: driver options: %s",
six.text_type(driver_options))
str(driver_options))
return {'size': 1}
def unmanage(self, share, share_server=None):

View File

@ -19,7 +19,6 @@ from unittest import mock
from eventlet import greenthread
from oslo_log import log
import six
from manila import exception
from manila import utils
@ -80,7 +79,7 @@ def fake_execute(*cmd_parts, **kwargs):
LOG.debug('Faked command matched %s', fake_replier[0])
break
if isinstance(reply_handler, six.string_types):
if isinstance(reply_handler, str):
# If the reply handler is a string, return it as stdout
reply = reply_handler, ''
else:

View File

@ -15,7 +15,6 @@
import ast
import re
import six
from hacking import core
import pycodestyle
@ -140,7 +139,7 @@ class CheckLoggingFormatArgs(BaseASTChecker):
if obj_name is None:
return None
return obj_name + '.' + method_name
elif isinstance(node, six.string_types):
elif isinstance(node, str):
return node
else: # could be Subscript, Call or many more
return None

View File

@ -12,10 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import http.client as http_client
from urllib import parse
from oslo_log import log
from oslo_serialization import jsonutils
from six.moves import http_client
from six.moves.urllib import parse
LOG = log.getLogger(__name__)

View File

@ -15,7 +15,6 @@
from oslo_config import cfg
from oslo_log import log
import six
from manila.tests.integrated import integrated_helpers
@ -36,4 +35,5 @@ class ExtensionsTest(integrated_helpers._IntegratedTestBase):
response = self.api.api_request('/foxnsocks')
foxnsocks = response.read()
LOG.debug("foxnsocks: %s.", foxnsocks)
self.assertEqual(six.b('Try to say this Mr. Knox, sir...'), foxnsocks)
self.assertEqual('Try to say this Mr. Knox, sir...'.encode("utf-8"),
foxnsocks)

View File

@ -15,8 +15,6 @@
from unittest import mock
import six
from manila.network.linux import interface
from manila.network.linux import ip_lib
from manila import test
@ -81,7 +79,7 @@ class TestABCDriver(TestBase):
except TypeError:
pass
except Exception as e:
self.fail("Unexpected exception thrown: '%s'" % six.text_type(e))
self.fail("Unexpected exception thrown: '%s'" % e)
else:
self.fail("ExpectedException 'TypeError' not thrown.")

View File

@ -18,7 +18,6 @@ from unittest import mock
import ddt
import netaddr
from oslo_config import cfg
import six
from manila.common import constants
from manila import context
@ -317,8 +316,8 @@ class StandaloneNetworkPluginTest(test.TestCase):
instance.db.share_network_subnet_update.assert_called_once_with(
fake_context, fake_share_network_subnet['id'],
dict(network_type=None, segmentation_id=None,
cidr=six.text_type(instance.net.cidr),
gateway=six.text_type(instance.gateway),
cidr=str(instance.net.cidr),
gateway=str(instance.gateway),
ip_version=4,
mtu=1500))
@ -342,8 +341,8 @@ class StandaloneNetworkPluginTest(test.TestCase):
instance.db.share_network_subnet_update.assert_called_once_with(
fake_context, fake_share_network_subnet['id'],
dict(network_type=None, segmentation_id=None,
cidr=six.text_type(instance.net.cidr),
gateway=six.text_type(instance.gateway),
cidr=str(instance.net.cidr),
gateway=str(instance.gateway),
ip_version=6,
mtu=1500))
@ -419,8 +418,8 @@ class StandaloneNetworkPluginTest(test.TestCase):
na_data = {
'network_type': None,
'segmentation_id': None,
'cidr': six.text_type(instance.net.cidr),
'gateway': six.text_type(instance.gateway),
'cidr': str(instance.net.cidr),
'gateway': str(instance.gateway),
'ip_version': 4,
'mtu': 1500,
}
@ -466,8 +465,8 @@ class StandaloneNetworkPluginTest(test.TestCase):
instance.db.share_network_subnet_update.assert_called_once_with(
fake_context, fake_share_network_subnet['id'],
dict(network_type=None, segmentation_id=None,
cidr=six.text_type(instance.net.cidr),
gateway=six.text_type(instance.gateway),
cidr=str(instance.net.cidr),
gateway=str(instance.gateway),
ip_version=4,
mtu=1500))
instance.db.network_allocations_get_by_ip_address.assert_has_calls(
@ -504,8 +503,8 @@ class StandaloneNetworkPluginTest(test.TestCase):
network_data = {
'network_type': instance.network_type,
'segmentation_id': instance.segmentation_id,
'cidr': six.text_type(instance.net.cidr),
'gateway': six.text_type(instance.gateway),
'cidr': str(instance.net.cidr),
'gateway': str(instance.gateway),
'ip_version': instance.ip_version,
'mtu': instance.mtu,
}

View File

@ -24,7 +24,6 @@ from unittest import mock
import ddt
from oslo_config import cfg
from oslo_utils import timeutils
from six import moves
from manila import context
from manila import db
@ -58,7 +57,7 @@ class HostManagerTestCase(test.TestCase):
super(HostManagerTestCase, self).setUp()
self.host_manager = host_manager.HostManager()
self.fake_hosts = [host_manager.HostState('fake_host%s' % x)
for x in moves.range(1, 5)]
for x in range(1, 5)]
def test_choose_host_filters_not_found(self):
self.flags(scheduler_default_filters='FakeFilterClass3')
@ -172,7 +171,7 @@ class HostManagerTestCase(test.TestCase):
self.assertEqual(3, len(host_state_map))
# Check that service is up
for i in moves.range(3):
for i in range(3):
share_node = fakes.SHARE_SERVICES_WITH_POOLS[i]
host = share_node['host']
self.assertEqual(share_node, host_state_map[host].service)

View File

@ -19,7 +19,6 @@ Tests For scheduler options.
import datetime
from oslo_serialization import jsonutils
import six
from manila.scheduler import scheduler_options
from manila import test
@ -36,7 +35,7 @@ class FakeSchedulerOptions(scheduler_options.SchedulerOptions):
# For overrides ...
self._time_now = now
self._file_now = file_now
self._file_data = six.b(filedata)
self._file_data = filedata.encode("utf-8")
self.file_was_loaded = False
@ -45,13 +44,8 @@ class FakeSchedulerOptions(scheduler_options.SchedulerOptions):
def _get_file_handle(self, filename):
self.file_was_loaded = True
if six.PY2:
# pylint: disable=import-error
import StringIO
return StringIO.StringIO(self._file_data)
else:
import io
return io.BytesIO(self._file_data)
import io
return io.BytesIO(self._file_data)
def _get_time_now(self):
return self._time_now

View File

@ -18,7 +18,6 @@ import random
from unittest import mock
import ddt
import six
from manila.common import constants
from manila import context
@ -771,7 +770,7 @@ class ShareInstanceAccessTestCase(test.TestCase):
self.assertEqual(fake_expect_driver_update_rules, driver_update_rules)
def _get_pass_rules_and_fail_rules(self):
random_value = six.text_type(random.randint(10, 32))
random_value = str(random.randint(10, 32))
pass_rules = [
{
'access_type': 'ip',

View File

@ -24,7 +24,6 @@ from oslo_concurrency import lockutils
from oslo_serialization import jsonutils
from oslo_utils import importutils
from oslo_utils import timeutils
import six
from manila.common import constants
from manila import context
@ -319,7 +318,7 @@ class ShareManagerTestCase(test.TestCase):
raise exception.ShareAccessExists(
access_type='fake_access_type', access='fake_access')
new_backend_info_hash = (hashlib.sha1(six.text_type(
new_backend_info_hash = (hashlib.sha1(str(
sorted(new_backend_info.items())).encode('utf-8')).hexdigest() if
new_backend_info else None)
old_backend_info = {'info_hash': old_backend_info_hash}
@ -431,7 +430,7 @@ class ShareManagerTestCase(test.TestCase):
self, old_backend_info_hash, new_backend_info):
old_backend_info = {'info_hash': old_backend_info_hash}
new_backend_info_hash = (hashlib.sha1(six.text_type(
new_backend_info_hash = (hashlib.sha1(str(
sorted(new_backend_info.items())).encode('utf-8')).hexdigest() if
new_backend_info else None)
mock_backend_info_update = self.mock_object(
@ -2127,7 +2126,7 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager.message_api.create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext),
message_field.Action.CREATE,
six.text_type(share.project_id),
str(share.project_id),
resource_type=message_field.Resource.SHARE,
resource_id=share['id'],
detail=mock.ANY)
@ -2227,7 +2226,7 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager.message_api.create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext),
message_field.Action.CREATE,
six.text_type(fake_share.project_id),
str(fake_share.project_id),
resource_type=message_field.Resource.SHARE,
resource_id=fake_share['id'],
detail=message_field.Detail.NO_SHARE_SERVER)
@ -2251,7 +2250,7 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager.message_api.create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext),
message_field.Action.CREATE,
six.text_type(shr.project_id),
str(shr.project_id),
resource_type=message_field.Resource.SHARE,
resource_id=shr['id'],
detail=message_field.Detail.NO_SHARE_SERVER)
@ -2311,7 +2310,7 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager.message_api.create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext),
message_field.Action.CREATE,
six.text_type(share.project_id),
str(share.project_id),
resource_type=message_field.Resource.SHARE,
resource_id=share['id'],
exception=mock.ANY)
@ -2821,7 +2820,7 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager.db.share_export_locations_update)))
self.mock_object(share_types,
'get_share_type_extra_specs',
mock.Mock(return_value=six.text_type(dhss)))
mock.Mock(return_value=str(dhss)))
self.mock_object(
self.share_manager, '_get_extra_specs_from_share_type',
mock.Mock(return_value=extra_specs))
@ -3734,8 +3733,8 @@ class ShareManagerTestCase(test.TestCase):
quota.QUOTAS.rollback.assert_called_once_with(
mock.ANY,
reservations,
project_id=six.text_type(share['project_id']),
user_id=six.text_type(share['user_id']),
project_id=str(share['project_id']),
user_id=str(share['user_id']),
share_type_id=None,
)
@ -3855,8 +3854,8 @@ class ShareManagerTestCase(test.TestCase):
quota.QUOTAS.reserve.assert_called_with(
mock.ANY,
project_id=six.text_type(share['project_id']),
user_id=six.text_type(share['user_id']),
project_id=str(share['project_id']),
user_id=str(share['user_id']),
share_type_id=None,
gigabytes=new_size - size,
**deltas

View File

@ -16,8 +16,8 @@
"""Unit tests for the API endpoint."""
import six
from six.moves import http_client
import http.client as http_client
import io
import webob
@ -25,7 +25,7 @@ class FakeHttplibSocket(object):
"""A fake socket implementation for http_client.HTTPResponse, trivial."""
def __init__(self, response_string):
self.response_string = response_string
self._buffer = six.StringIO(response_string)
self._buffer = io.StringIO(response_string)
def makefile(self, _mode, _other):
"""Returns the socket's internal buffer."""

View File

@ -16,7 +16,6 @@
# under the License.
import ddt
import six
from manila import exception
from manila import test
@ -46,18 +45,18 @@ class ManilaExceptionTestCase(test.TestCase):
message = "default message"
exc = FakeManilaException()
self.assertEqual('default message', six.text_type(exc))
self.assertEqual('default message', str(exc))
def test_error_msg(self):
self.assertEqual('test',
six.text_type(exception.ManilaException('test')))
str(exception.ManilaException('test')))
def test_default_error_msg_with_kwargs(self):
class FakeManilaException(exception.ManilaException):
message = "default message: %(code)s"
exc = FakeManilaException(code=500)
self.assertEqual('default message: 500', six.text_type(exc))
self.assertEqual('default message: 500', str(exc))
def test_error_msg_exception_with_kwargs(self):
# NOTE(dprince): disable format errors for this test
@ -68,7 +67,7 @@ class ManilaExceptionTestCase(test.TestCase):
exc = FakeManilaException(code=500)
self.assertEqual('default message: %(misspelled_code)s',
six.text_type(exc))
str(exc))
def test_default_error_code(self):
class FakeManilaException(exception.ManilaException):

View File

@ -21,10 +21,10 @@ from unittest import mock
import ddt
from oslo_config import cfg
from oslo_utils import encodeutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import paramiko
import six
from webob import exc
import manila
@ -325,7 +325,7 @@ class SSHPoolTestCase(test.TestCase):
self.assertNotEqual(first_id, third_id)
paramiko.SSHClient.assert_called_once_with()
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('paramiko.SSHClient')
@mock.patch('os.path.isfile', return_value=True)
def test_sshpool_remove(self, mock_isfile, mock_sshclient, mock_open):
@ -340,7 +340,7 @@ class SSHPoolTestCase(test.TestCase):
self.assertNotIn(ssh_to_remove, list(sshpool.free_items))
@mock.patch('six.moves.builtins.open')
@mock.patch('builtins.open')
@mock.patch('paramiko.SSHClient')
@mock.patch('os.path.isfile', return_value=True)
def test_sshpool_remove_object_not_in_pool(self, mock_isfile,
@ -804,36 +804,23 @@ class ShareMigrationHelperTestCase(test.TestCase):
class ConvertStrTestCase(test.TestCase):
def test_convert_str_str_input(self):
self.mock_object(utils.encodeutils, 'safe_encode')
input_value = six.text_type("string_input")
self.mock_object(encodeutils, 'safe_encode')
input_value = "string_input"
output_value = utils.convert_str(input_value)
if six.PY2:
utils.encodeutils.safe_encode.assert_called_once_with(input_value)
self.assertEqual(
utils.encodeutils.safe_encode.return_value, output_value)
else:
self.assertEqual(0, utils.encodeutils.safe_encode.call_count)
self.assertEqual(input_value, output_value)
self.assertEqual(0, encodeutils.safe_encode.call_count)
self.assertEqual(input_value, output_value)
def test_convert_str_bytes_input(self):
self.mock_object(utils.encodeutils, 'safe_encode')
if six.PY2:
input_value = six.binary_type("binary_input")
else:
input_value = six.binary_type("binary_input", "utf-8")
self.mock_object(encodeutils, 'safe_encode')
input_value = bytes("binary_input", "utf-8")
output_value = utils.convert_str(input_value)
if six.PY2:
utils.encodeutils.safe_encode.assert_called_once_with(input_value)
self.assertEqual(
utils.encodeutils.safe_encode.return_value, output_value)
else:
self.assertEqual(0, utils.encodeutils.safe_encode.call_count)
self.assertIsInstance(output_value, six.string_types)
self.assertEqual(six.text_type("binary_input"), output_value)
self.assertEqual(0, encodeutils.safe_encode.call_count)
self.assertIsInstance(output_value, str)
self.assertEqual(str("binary_input"), output_value)
@ddt.ddt

View File

@ -15,10 +15,10 @@
# under the License.
import fixtures
import functools
import os
from oslo_config import cfg
import six
from manila import context
from manila import utils
@ -26,12 +26,12 @@ from manila import utils
CONF = cfg.CONF
class NamedBinaryStr(six.binary_type):
class NamedBinaryStr(bytes):
"""Wrapper for six.binary_type to facilitate overriding __name__."""
"""Wrapper for bytes to facilitate overriding __name__."""
class NamedUnicodeStr(six.text_type):
class NamedUnicodeStr(str):
"""Unicode string look-alike to facilitate overriding __name__."""
@ -66,7 +66,7 @@ class NamedTuple(tuple):
def annotated(test_name, test_input):
if isinstance(test_input, dict):
annotated_input = NamedDict(test_input)
elif isinstance(test_input, six.text_type):
elif isinstance(test_input, str):
annotated_input = NamedUnicodeStr(test_input)
elif isinstance(test_input, tuple):
annotated_input = NamedTuple(test_input)
@ -98,7 +98,7 @@ def set_timeout(timeout):
def _decorator(f):
@six.wraps(f)
@functools.wraps(f)
def _wrapper(self, *args, **kwargs):
self.useFixture(fixtures.Timeout(timeout, gentle=True))
return f(self, *args, **kwargs)