Merge "Use b64encode to replace of encodestring"

This commit is contained in:
Jenkins 2015-09-09 13:20:22 +00:00 committed by Gerrit Code Review
commit 66b9b26bb1
2 changed files with 6 additions and 2 deletions

View File

@ -454,7 +454,7 @@ class Meter(base.Base):
meter_id = '%s+%s' % (kwargs['resource_id'], kwargs['name'])
# meter_id is of type Unicode but base64.encodestring() only accepts
# strings. See bug #1333177
meter_id = base64.encodestring(meter_id.encode('utf-8'))
meter_id = base64.b64encode(meter_id.encode('utf-8'))
kwargs['meter_id'] = meter_id
super(Meter, self).__init__(**kwargs)

View File

@ -785,7 +785,11 @@ class TestListMeters(v2.FunctionalTest,
data = self.get_json('/meters')
for i in data:
meter_id = '%s+%s' % (i['resource_id'], i['name'])
expected = base64.encodestring(meter_id.encode('utf-8'))
expected = base64.b64encode(meter_id.encode('utf-8'))
if six.PY3:
expected = expected.decode('ascii')
self.assertEqual(expected, i['meter_id'])
self.assertFalse(i['meter_id'].endswith('\n'))
self.assertEqual(
[i['resource_id'].encode('utf-8'), i['name'].encode('utf-8')],
base64.b64decode(i['meter_id']).split('+'))