Remove unicode-related Python2-only code

This commit:
- removes the old "u" prefix from all strings
- removes the unicode_key_value_to_string function

Change-Id: I1da347e31e828fd2359f0935a4da47257116d4cb
This commit is contained in:
Cyril Roelandt
2022-09-13 16:15:13 +02:00
parent a3f13bdcb4
commit fc8f9ac2ed
8 changed files with 32 additions and 61 deletions
+12 -12
View File
@@ -66,7 +66,7 @@ class TestClient(testtools.TestCase):
self.endpoint = 'http://example.com:9292'
self.ssl_endpoint = 'https://example.com:9292'
self.token = u'abc123'
self.token = 'abc123'
self.client = getattr(self, self.create_client)()
@@ -80,7 +80,7 @@ class TestClient(testtools.TestCase):
'X-Service-Catalog': 'service_catalog',
}
# with token
kwargs = {'token': u'fake-token',
kwargs = {'token': 'fake-token',
'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertEqual('auth_token', http_client_object.auth_token)
@@ -96,10 +96,10 @@ class TestClient(testtools.TestCase):
'X-Service-Catalog': 'service_catalog',
}
# without X-Auth-Token in identity headers
kwargs = {'token': u'fake-token',
kwargs = {'token': 'fake-token',
'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertEqual(u'fake-token', http_client_object.auth_token)
self.assertEqual('fake-token', http_client_object.auth_token)
self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None)
@@ -210,12 +210,12 @@ class TestClient(testtools.TestCase):
self.mock.get(self.endpoint + path, text=text,
headers={"Content-Type": "text/plain"})
headers = {"test": u'ni\xf1o'}
headers = {"test": 'ni\xf1o'}
resp, body = self.client.get(path, headers=headers)
self.assertEqual(text, resp.text)
def test_headers_encoding(self):
value = u'ni\xf1o'
value = 'ni\xf1o'
fake_location = b'http://web_server:80/images/fake.img'
headers = {"test": value,
"none-val": None,
@@ -262,7 +262,7 @@ class TestClient(testtools.TestCase):
ksarqh = mock_ksarq.call_args[1]['headers']
# Only one Content-Type header (of any text-type)
self.assertEqual(1, [encodeutils.safe_decode(key)
for key in ksarqh.keys()].count(u'Content-Type'))
for key in ksarqh.keys()].count('Content-Type'))
# And it's the one we set
self.assertEqual(b"application/openstack-images-v2.1-json-patch",
ksarqh[b"Content-Type"])
@@ -295,7 +295,7 @@ class TestClient(testtools.TestCase):
def test_parse_endpoint(self):
endpoint = 'http://example.com:9292'
test_client = http.HTTPClient(endpoint, token=u'adc123')
test_client = http.HTTPClient(endpoint, token='adc123')
actual = test_client.parse_endpoint(endpoint)
expected = parse.SplitResult(scheme='http',
netloc='example.com:9292', path='',
@@ -304,7 +304,7 @@ class TestClient(testtools.TestCase):
def test_get_connections_kwargs_http(self):
endpoint = 'http://example.com:9292'
test_client = http.HTTPClient(endpoint, token=u'adc123')
test_client = http.HTTPClient(endpoint, token='adc123')
self.assertEqual(600.0, test_client.timeout)
def test__chunk_body_exact_size_chunk(self):
@@ -321,7 +321,7 @@ class TestClient(testtools.TestCase):
path = '/v1/images/'
self.mock.post(self.endpoint + path, text=text)
headers = {"test": u'chunked_request'}
headers = {"test": 'chunked_request'}
resp, body = self.client.post(path, headers=headers, data=data)
self.assertIsInstance(self.mock.last_request.body, types.GeneratorType)
self.assertEqual(text, resp.text)
@@ -332,7 +332,7 @@ class TestClient(testtools.TestCase):
text = 'OK'
self.mock.post(self.endpoint + path, text=text)
headers = {"test": u'chunked_request'}
headers = {"test": 'chunked_request'}
resp, body = self.client.post(path, headers=headers, data=data)
self.assertEqual(text, resp.text)
@@ -487,7 +487,7 @@ class TestClient(testtools.TestCase):
headers = self.mock.last_request.headers
self.assertEqual(refreshed_token, headers['X-Auth-Token'])
# regression check for bug 1448080
unicode_token = u'ni\xf1o+=='
unicode_token = 'ni\xf1o+=='
http_client.auth_token = unicode_token
http_client.get(path)
headers = self.mock.last_request.headers
+1 -7
View File
@@ -122,7 +122,7 @@ class TestUtils(testtools.TestCase):
# test for removing 'u' from lists in print_list output
columns = ['ID', 'Tags']
images = [Struct(**{'id': 'b8e1c57e-907a-4239-aed8-0df8e54b8d2d',
'tags': [u'Name1', u'Tag_123', u'veeeery long']})]
'tags': ['Name1', 'Tag_123', 'veeeery long']})]
saved_stdout = sys.stdout
try:
sys.stdout = output_list = io.StringIO()
@@ -178,12 +178,6 @@ class TestUtils(testtools.TestCase):
''',
output_list.getvalue())
def test_unicode_key_value_to_string(self):
src = {u'key': u'\u70fd\u7231\u5a77'}
# u'xxxx' in PY3 is str, we will not get extra 'u' from cli
# output in PY3
self.assertEqual(src, utils.unicode_key_value_to_string(src))
def test_schema_args_with_list_types(self):
# NOTE(flaper87): Regression for bug
# https://bugs.launchpad.net/python-glanceclient/+bug/1401032
+2 -2
View File
@@ -504,7 +504,7 @@ class ImageManagerTest(testtools.TestCase):
self.assertEqual(False, image.is_public)
self.assertEqual(False, image.protected)
self.assertEqual(False, image.deleted)
self.assertEqual({u'arch': u'x86_64'}, image.properties)
self.assertEqual({'arch': 'x86_64'}, image.properties)
def test_get_int(self):
image = self.mgr.get(1)
@@ -515,7 +515,7 @@ class ImageManagerTest(testtools.TestCase):
self.assertEqual(False, image.is_public)
self.assertEqual(False, image.protected)
self.assertEqual(False, image.deleted)
self.assertEqual({u'arch': u'x86_64'}, image.properties)
self.assertEqual({'arch': 'x86_64'}, image.properties)
def test_get_encoding(self):
image = self.mgr.get('3')
+4 -4
View File
@@ -550,10 +550,10 @@ data_fixtures = {
{
'id': 'a2b83adc-888e-11e3-8872-78acc0b951d8',
'name': 'image-location-tests',
'locations': [{u'url': u'http://foo.com/',
u'metadata': {u'foo': u'foometa'}},
{u'url': u'http://bar.com/',
u'metadata': {u'bar': u'barmeta'}}],
'locations': [{'url': 'http://foo.com/',
'metadata': {'foo': 'foometa'}},
{'url': 'http://bar.com/',
'metadata': {'bar': 'barmeta'}}],
},
),
'PATCH': (
+1 -1
View File
@@ -854,7 +854,7 @@ class ShellV2Test(testtools.TestCase):
@mock.patch('sys.stdin', autospec=True)
def test_do_image_create_with_unicode(self, mock_stdin):
name = u'\u041f\u0420\u0418\u0412\u0415\u0422\u0418\u041a'
name = '\u041f\u0420\u0418\u0412\u0415\u0422\u0418\u041a'
args = self._make_args({'name': name,
'file': None})