Port test_serversV21 to Python 3

* Use encodeutils from oslo.utils to convert things as needed.

* Use base64 module from oslo.serialization to encode text.

Partially-Implements: blueprint goal-python35

Change-Id: I489e3b38021c45d7070bd5fae2deec6cab577745
This commit is contained in:
ChangBo Guo(gcb)
2016-11-18 10:08:09 +08:00
parent 6a2b1e2c99
commit d830fd8583
2 changed files with 6 additions and 9 deletions

View File

@@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import base64
import collections
import datetime
import uuid
@@ -24,7 +23,9 @@ import iso8601
import mock
from mox3 import mox
from oslo_policy import policy as oslo_policy
from oslo_serialization import base64
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
from oslo_utils import timeutils
import six
from six.moves import range
@@ -1837,7 +1838,7 @@ class ServersControllerRebuildInstanceTest(ControllerTest):
"imageRef": self.image_uuid,
"personality": [{
"path": "/path/to/file",
"contents": base64.b64encode("Test String"),
"contents": base64.encode_as_text("Test String"),
}]
},
}
@@ -3038,7 +3039,7 @@ class ServersControllerCreateTest(test.TestCase):
self.req.body = jsonutils.dump_as_bytes(self.body)
robj = self.controller.create(self.req, body=self.body)
self.assertEqual(robj['Location'], selfhref)
self.assertEqual(encodeutils.safe_decode(robj['Location']), selfhref)
def _do_test_create_instance_above_quota(self, resource, allowed, quota,
expected_msg):
@@ -3313,7 +3314,8 @@ class ServersControllerCreateTest(test.TestCase):
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_invalid_personality(self, mock_create):
codec = 'utf8'
content = 'b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA=='
content = encodeutils.safe_encode(
'b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA==')
start_position = 19
end_position = 20
msg = 'invalid start byte'

View File

@@ -18,11 +18,6 @@ nova.tests.unit.api.openstack.compute.test_security_group_default_rules.TestSecu
nova.tests.unit.api.openstack.compute.test_security_group_default_rules.TestSecurityGroupDefaultRulesV21
nova.tests.unit.api.openstack.compute.test_security_groups.SecurityGroupsOutputTestV21
nova.tests.unit.api.openstack.compute.test_security_groups.TestSecurityGroupRulesV21
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerCreateTest
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerRebuildInstanceTest
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerRebuildTestV219
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerTest
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerTestV29
nova.tests.unit.api.openstack.compute.test_simple_tenant_usage.SimpleTenantUsageTestV21
nova.tests.unit.api.openstack.compute.test_urlmap.UrlmapTest
nova.tests.unit.api.openstack.compute.test_user_data.ServersControllerCreateTest