Python 2/3 compatible[2]

Change-Id: Idc4264a0141f5a208fd9c5c653c130470d5f9ca2
This commit is contained in:
zhurong 2018-12-27 20:03:44 +08:00
parent ead191c3e4
commit 54c73c270c
20 changed files with 208 additions and 64 deletions

View File

@ -16,6 +16,7 @@ import copy
import json
import os
import random
import six
import string
import time
@ -164,7 +165,9 @@ class SolumClient(rest_client.RestClient):
def delete_created_lps(self):
resp, body = self.get('v1/language_packs')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
[self._delete_language_pack(pl['uuid']) for pl in data]
def _delete_language_pack(self, uuid):
@ -197,11 +200,13 @@ class SolumClient(rest_client.RestClient):
class SolumResponse(object):
def __init__(self, resp, body, body_type):
self.resp = resp
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.body = body
if body_type == 'json':
self.data = json.loads(self.body.decode('utf-8'))
self.data = json.loads(self.body)
elif body_type == 'yaml':
self.data = yaml.safe_load(self.body.decode('utf-8'))
self.data = yaml.safe_load(self.body)
if self.data.get('uuid'):
self.uuid = self.data.get('uuid')
if self.data.get('id'):
@ -213,11 +218,11 @@ class SolumResponse(object):
@property
def yaml_data(self):
return yaml.safe_load(self.body.decode('utf-8'))
return yaml.safe_load(self.body)
@property
def json_data(self):
return json.loads(self.body.decode('utf-8'))
return json.loads(self.body)
class TestCase(testtools.TestCase):

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -25,7 +26,9 @@ class PlatformDiscoveryTestCase(base.TestCase):
request_without_auth('camp/platform_endpoints',
'GET'))
self.assertEqual(200, resp.status)
endpoints = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
endpoints = json.loads(body)
self.assertEqual('platform_endpoints', endpoints['type'])
self.assertEqual('Solum_CAMP_endpoints', endpoints['name'])
pe_links = endpoints['platform_endpoint_links']
@ -44,7 +47,9 @@ class PlatformDiscoveryTestCase(base.TestCase):
request_without_auth(rel_ep_url,
'GET'))
self.assertEqual(200, resp.status)
endpoint = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
endpoint = json.loads(body)
self.assertEqual('platform_endpoint', endpoint['type'])
self.assertEqual('Solum_CAMP_v1_1_endpoint', endpoint['name'])
self.assertEqual('CAMP 1.1', endpoint['specification_version'])

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
from tempest.lib import exceptions as tempest_exceptions
import yaml
@ -67,7 +68,9 @@ class TestAssembliesController(base.TestCase):
self.assertEqual(200, resp.status, 'GET assemblies resource')
# pick out the assemebly link for our new assembly uuid
assemblies_dct = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
assemblies_dct = json.loads(body)
camp_link = None
for link in assemblies_dct['assembly_links']:
link_uuid = link['href'].split("/")[-1]
@ -83,7 +86,9 @@ class TestAssembliesController(base.TestCase):
resp, body = self.client.get(url)
self.assertEqual(200, resp.status, msg)
assembly = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
assembly = json.loads(body)
self.assertEqual('assembly', assembly['type'])
self.assertEqual(base.assembly_sample_data['name'], assembly['name'])

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -27,7 +28,9 @@ class TestSupportedFormats(base.TestCase):
self.skipTest('CAMP not enabled.')
resp, body = self.client.get('camp/v1_1/formats/')
self.assertEqual(200, resp.status, 'GET formats resource')
formats = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
formats = json.loads(body)
self.assertEqual('formats', formats['type'])
self.assertEqual('Solum_CAMP_formats', formats['name'])
format_links = formats['format_links']
@ -43,7 +46,9 @@ class TestSupportedFormats(base.TestCase):
# get our lone platform_endpoint resource
resp, body = self.client.get(url)
self.assertEqual(200, resp.status, 'GET JSON format resource')
formatr = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
formatr = json.loads(body)
self.assertEqual('format', formatr['type'])
self.assertEqual('JSON', formatr['name'], 'RE-42')
self.assertEqual('application/json', formatr['mime_type'], 'RE-42')

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -27,7 +28,9 @@ class TestParameterDefinitions(base.TestCase):
self.skipTest('CAMP not enabled.')
resp, body = self.client.get('camp/v1_1/assemblies/')
self.assertEqual(200, resp.status, 'GET assemblies resource')
assemblies = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
assemblies = json.loads(body)
# get the URL of the parameter_definitions resource
url = (assemblies['parameter_definitions_uri']
@ -37,7 +40,9 @@ class TestParameterDefinitions(base.TestCase):
resp, body = self.client.get(url)
self.assertEqual(200, resp.status,
'GET assembly parameter_definitions resource')
pd_resc = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
pd_resc = json.loads(body)
self.assertEqual('parameter_definitions', pd_resc['type'])
self.assertIn('parameter_definition_links', pd_resc)
pd_links = pd_resc['parameter_definition_links']
@ -67,7 +72,9 @@ class TestParameterDefinitions(base.TestCase):
self.skipTest('CAMP not enabled.')
resp, body = self.client.get('camp/v1_1/plans/')
self.assertEqual(200, resp.status, 'GET plans resource')
plans = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
plans = json.loads(body)
# get the URL of the parameter_definitions resource
url = (plans['parameter_definitions_uri']
@ -77,7 +84,9 @@ class TestParameterDefinitions(base.TestCase):
resp, body = self.client.get(url)
self.assertEqual(200, resp.status,
'GET plans parameter_definitions resource')
pd_resc = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
pd_resc = json.loads(body)
self.assertEqual('parameter_definitions', pd_resc['type'])
self.assertIn('parameter_definition_links', pd_resc)
pd_links = pd_resc['parameter_definition_links']

View File

@ -12,6 +12,7 @@
import copy
import json
import six
from tempest.lib import exceptions as tempest_exceptions
import yaml
@ -98,7 +99,9 @@ class TestPlansController(base.TestCase):
self.assertEqual(200, resp.status, 'GET plans resource')
# pick out the plan link for our new plan uuid
plans_dct = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
plans_dct = json.loads(body)
camp_link = None
for link in plans_dct['plan_links']:
link_uuid = link['href'].split("/")[-1]
@ -115,7 +118,9 @@ class TestPlansController(base.TestCase):
self.assertEqual(200, resp.status, msg)
# CAMP plans are rendered in JSON
plan = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
plan = json.loads(body)
self.assertEqual(base.plan_sample_data['name'], plan['name'])
self.assertEqual(base.plan_sample_data['description'],
plan['description'])
@ -344,7 +349,9 @@ class TestPlansController(base.TestCase):
uri, patch_json,
headers={'content-type': 'application/json-patch+json'})
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self.assertIn('tags', json_data)
tags = json_data['tags']
self.assertEqual(2, len(tags))

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -20,7 +21,9 @@ class TestPlatformAndContainers(base.TestCase):
def _test_get_resource(self, url, rtype, name):
resp, body = self.client.get(url)
self.assertEqual(200, resp.status, 'GET %s resource' % rtype)
resource = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
resource = json.loads(body)
self.assertEqual(rtype, resource['type'])
self.assertEqual(name, resource['name'])
@ -30,7 +33,9 @@ class TestPlatformAndContainers(base.TestCase):
# get and test our platform resource
resp, body = self.client.get('camp/v1_1/platform/')
self.assertEqual(200, resp.status, 'GET platform resource')
platform = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
platform = json.loads(body)
self.assertEqual('platform', platform['type'])
self.assertEqual('Solum_CAMP_v1_1_platform', platform['name'])
self.assertEqual('CAMP 1.1', platform['specification_version'])

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -21,7 +22,9 @@ class TestTypeDefinitions(base.TestCase):
url = abs_url[len(self.client.base_url) + 1:]
resp, body = self.client.get(url)
self.assertEqual(200, resp.status, msg)
resource = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
resource = json.loads(body)
self.assertEqual(rtype, resource['type'])
self.assertEqual(name, resource['name'])
return body
@ -39,7 +42,9 @@ class TestTypeDefinitions(base.TestCase):
resp, body = self.client.get('camp/v1_1/type_definitions')
self.assertEqual(200, resp.status, 'GET type_definitions resource')
defs_dct = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
defs_dct = json.loads(body)
for link_dct in defs_dct['type_definition_links']:
msg = ("GET type_definition resource for %s" %
link_dct['target_name'])
@ -48,7 +53,7 @@ class TestTypeDefinitions(base.TestCase):
'type_definition',
link_dct['target_name'])
def_dct = json.loads(body.decode('utf-8'))
def_dct = json.loads(body)
for adl_dct in def_dct['attribute_definition_links']:
msg = ("GET attribute_definition resource for %s" %
link_dct['target_name'])

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -21,7 +22,9 @@ from solum_tempest_plugin import base
class VersionDiscoveryTestCase(base.TestCase):
def test_get_root_discovers_v1(self):
resp, body = self.client.get('/')
body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body))
v1 = body[0]
@ -32,7 +35,9 @@ class VersionDiscoveryTestCase(base.TestCase):
def test_delete_root_discovers_v1(self):
resp, body = self.client.delete('/')
body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body))
v1 = body[0]
@ -43,7 +48,9 @@ class VersionDiscoveryTestCase(base.TestCase):
def test_post_root_discovers_v1(self):
resp, body = self.client.post('/', '{}')
body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body))
v1 = body[0]
@ -54,7 +61,9 @@ class VersionDiscoveryTestCase(base.TestCase):
def test_put_root_discovers_v1(self):
resp, body = self.client.put('/', '{}')
body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body))
v1 = body[0]
@ -66,7 +75,9 @@ class VersionDiscoveryTestCase(base.TestCase):
def test_post_no_body_root_discovers_v1(self):
self.skipTest("POST without body will hang request: #1367470")
resp, body = self.client.post('/', None)
body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body))
v1 = body[0]
@ -78,7 +89,9 @@ class VersionDiscoveryTestCase(base.TestCase):
def test_put_no_body_root_discovers_v1(self):
self.skipTest("PUT without body will hang request: #1367470")
resp, body = self.client.put('/', None)
body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
body = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual(1, len(body))
v1 = body[0]

View File

@ -11,6 +11,7 @@
# under the License.
import json
import six
import time
import requests
@ -25,7 +26,10 @@ class TestTriggerController(base.TestCase):
lp_name = self.client.create_lp()
data = apputils.get_sample_data(languagepack=lp_name)
resp = self.client.create_app(data=data)
bdy = json.loads(resp.body.decode('utf-8'))
body = resp.body
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
bdy = json.loads(body)
trigger_uri = bdy['trigger_uri']
# Using requests instead of self.client to test unauthenticated request
status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
@ -46,7 +50,10 @@ class TestTriggerController(base.TestCase):
lp_name = self.client.create_lp()
data = apputils.get_sample_data(languagepack=lp_name)
resp = self.client.create_app(data=data)
bdy = json.loads(resp.body.decode('utf-8'))
body = resp.body
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
bdy = json.loads(body)
trigger_uri = bdy['trigger_uri']
# Using requests instead of self.client to test unauthenticated request
resp = requests.post(trigger_uri)

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
import time
from tempest.lib import exceptions as tempest_exceptions
@ -96,7 +97,9 @@ class TestAppController(base.TestCase):
headers={'content-type': 'application/json'})
self.assertEqual(200, resp.status)
app_body = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
app_body = json.loads(body)
self.assertEqual('newfakeappname', app_body["name"])
self.assertEqual("newruncmd", app_body["workflow_config"]["run_cmd"])
self.assertEqual("newrepo", app_body["source"]["repository"])
@ -144,8 +147,10 @@ class TestAppController(base.TestCase):
self.assertEqual(201, create_resp.status)
id = create_resp.id
resp, body = self.client.delete_app(id)
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.assertEqual(202, resp.status)
self.assertEqual(b'', body)
self.assertEqual('', body)
time.sleep(2)
self.client.delete_language_pack(lp_name)

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from tempest.lib import exceptions as tempest_exceptions
@ -70,7 +71,9 @@ class TestAssemblyController(base.TestCase):
self.assertEqual(200, resp.status)
# Search for uuids of created assemblies
assembly_list = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
assembly_list = json.loads(body)
found_uuid_1 = False
found_uuid_2 = False
for assembly in assembly_list:
@ -115,7 +118,9 @@ class TestAssemblyController(base.TestCase):
plan_uuid)
resp, body = self.client.get('v1/assemblies/%s' % uuid)
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, sample_data)
# Now check that HTTPS is respected. No new assemblies are created.
@ -126,7 +131,9 @@ class TestAssemblyController(base.TestCase):
resp, body = self.client.get('v1/assemblies/%s' % uuid,
headers=use_https)
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, sample_data)
def test_assemblies_get_not_found(self):
@ -152,7 +159,9 @@ class TestAssemblyController(base.TestCase):
updated_json = json.dumps(updated_data)
resp, body = self.client.put('v1/assemblies/%s' % uuid, updated_json)
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, updated_data)
def test_assemblies_put_not_found(self):
@ -204,8 +213,10 @@ class TestAssemblyController(base.TestCase):
uuid = assembly_resp.uuid
resp, body = self.client.delete_assembly(uuid)
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.assertEqual(204, resp.status)
self.assertEqual(b'', body)
self.assertEqual('', body)
def test_assemblies_delete_not_found(self):
self.assertRaises(tempest_exceptions.NotFound,

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from tempest.lib import exceptions as tempest_exceptions
@ -62,7 +63,9 @@ class TestComponentController(base.TestCase):
data = json.dumps(sample_data)
resp, body = self.client.post('v1/components', data)
self.assertEqual(201, resp.status)
out_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
out_data = json.loads(body)
uuid = out_data['uuid']
self.assertIsNotNone(uuid)
return uuid, assembly_uuid, plan_uuid
@ -70,7 +73,9 @@ class TestComponentController(base.TestCase):
def test_components_get_all(self):
uuid, assembly_uuid, plan_uuid = self._create_component()
resp, body = self.client.get('v1/components')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(200, resp.status)
filtered = [com for com in data if com['uuid'] == uuid]
self.assertEqual(1, len(filtered))
@ -91,7 +96,9 @@ class TestComponentController(base.TestCase):
sample_json = json.dumps(sample_data)
resp, body = self.client.post('v1/components', sample_json)
self.assertEqual(201, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, sample_data)
self._delete_component(json_data['uuid'])
@ -105,7 +112,9 @@ class TestComponentController(base.TestCase):
plan_uuid)
resp, body = self.client.get('v1/components/%s' % uuid)
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, sample_data)
self._delete_component(uuid)
@ -123,7 +132,9 @@ class TestComponentController(base.TestCase):
updated_json = json.dumps(updated_data)
resp, body = self.client.put('v1/components/%s' % uuid, updated_json)
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, updated_data)
self._delete_component(uuid)
@ -145,8 +156,10 @@ class TestComponentController(base.TestCase):
def test_components_delete(self):
uuid, assembly_uuid, plan_uuid = self._create_component()
resp, body = self.client.delete('v1/components/%s' % uuid)
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.assertEqual(204, resp.status)
self.assertEqual(b'', body)
self.assertEqual('', body)
def test_components_delete_not_found(self):
self.assertRaises(tempest_exceptions.NotFound,

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -22,6 +23,8 @@ class TestExtensionController(base.TestCase):
def test_extensions_get_all(self):
resp, body = self.client.get('v1/extensions')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual([], data)

View File

@ -14,6 +14,7 @@
import json
import random
import six
import string
import time
@ -45,7 +46,9 @@ class TestLanguagePackController(base.TestCase):
def _delete_all(self):
resp, body = self.client.get('v1/language_packs')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(200, resp.status)
[self._delete_language_pack(pl['uuid']) for pl in data]
@ -58,7 +61,9 @@ class TestLanguagePackController(base.TestCase):
jsondata = json.dumps(sample_lp)
resp, body = self.client.post('v1/language_packs', jsondata)
self.assertEqual(201, resp.status)
out_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
out_data = json.loads(body)
uuid = out_data['uuid']
self.assertIsNotNone(uuid)
return uuid, sample_lp
@ -66,7 +71,9 @@ class TestLanguagePackController(base.TestCase):
def test_language_packs_get_all(self):
uuid, sample_lp = self._create_language_pack()
resp, body = self.client.get('v1/language_packs')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(200, resp.status)
filtered = [pl for pl in data if pl['uuid'] == uuid]
self.assertEqual(uuid, filtered[0]['uuid'])
@ -77,7 +84,9 @@ class TestLanguagePackController(base.TestCase):
sample_json = json.dumps(sample_lp)
resp, body = self.client.post('v1/language_packs', sample_json)
self.assertEqual(201, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self.assertEqual("QUEUED", json_data["status"])
self.assertEqual(sample_lp['name'], json_data["name"])
self._delete_language_pack(json_data["uuid"])
@ -90,7 +99,9 @@ class TestLanguagePackController(base.TestCase):
uuid, sample_lp = self._create_language_pack()
resp, body = self.client.get('v1/language_packs/%s' % uuid)
self.assertEqual(200, resp.status)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self.assertEqual(sample_lp['source_uri'], json_data['source_uri'])
self.assertEqual(sample_lp['name'], json_data['name'])
self._delete_language_pack(uuid)
@ -102,8 +113,10 @@ class TestLanguagePackController(base.TestCase):
def test_language_packs_delete(self):
uuid, sample_lp = self._create_language_pack()
resp, body = self.client.delete('v1/language_packs/%s' % uuid)
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.assertEqual(204, resp.status)
self.assertEqual(b'', body)
self.assertEqual('', body)
def test_language_packs_delete_not_found(self):
self.assertRaises(tempest_exceptions.NotFound,
@ -135,7 +148,10 @@ class TestLanguagePackController(base.TestCase):
self.assertRaises(tempest_exceptions.Conflict,
self.client.delete, 'v1/language_packs/%s' % uuid)
bdy = json.loads(resp.body.decode('utf-8'))
body = resp.body
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
bdy = json.loads(body)
self.client.delete_app(bdy["id"])
# Sleep for a few seconds to make sure plans are deleted.

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -22,6 +23,8 @@ class TestOperationController(base.TestCase):
def test_operations_get_all(self):
resp, body = self.client.get('v1/operations')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual([], data)

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.lib import exceptions as tempest_exceptions
import yaml
@ -224,8 +226,10 @@ class TestPlanController(base.TestCase):
self.assertEqual(201, create_resp.status)
uuid = create_resp.uuid
resp, body = self.client.delete_plan(uuid)
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.assertEqual(202, resp.status)
self.assertEqual(b'', body)
self.assertEqual('', body)
def test_plans_delete_not_found(self):
self.assertRaises(tempest_exceptions.NotFound,

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -23,7 +24,9 @@ class TestRootController(base.TestCase):
def test_index(self):
resp, body = self.client.request_without_auth('', 'GET')
self.assertEqual(200, resp.status)
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(data[0]['id'], 'v1.0')
self.assertEqual(data[0]['status'], 'CURRENT')
self.assertEqual(data[0]['link'],
@ -33,7 +36,9 @@ class TestRootController(base.TestCase):
def test_platform(self):
resp, body = self.client.request_without_auth('v1', 'GET')
self.assertEqual(200, resp.status)
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(data['uri'], '%s/v1' % self.client.base_url)
self.assertEqual(data['type'], 'platform')
self.assertEqual(data['name'], 'solum')

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from solum_tempest_plugin import base
@ -22,6 +23,8 @@ class TestSensorController(base.TestCase):
def test_sensors_get_all(self):
resp, body = self.client.get('v1/sensors')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(200, resp.status)
self.assertEqual([], data)

View File

@ -14,6 +14,7 @@
# under the License.
import json
import six
from tempest.lib import exceptions as tempest_exceptions
@ -35,7 +36,9 @@ class TestServiceController(base.TestCase):
def _delete_all(self):
resp, body = self.client.get('v1/services')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(resp.status, 200)
[self._delete_service(ser['uuid']) for ser in data]
@ -55,7 +58,9 @@ class TestServiceController(base.TestCase):
jsondata = json.dumps(sample_data)
resp, body = self.client.post('v1/services', jsondata)
self.assertEqual(resp.status, 201)
out_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
out_data = json.loads(body)
uuid = out_data['uuid']
self.assertIsNotNone(uuid)
return uuid
@ -63,7 +68,9 @@ class TestServiceController(base.TestCase):
def test_services_get_all(self):
uuid = self._create_service()
resp, body = self.client.get('v1/services')
data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
data = json.loads(body)
self.assertEqual(resp.status, 200)
filtered = [ser for ser in data if ser['uuid'] == uuid]
self.assertEqual(filtered[0]['uuid'], uuid)
@ -72,7 +79,9 @@ class TestServiceController(base.TestCase):
sample_json = json.dumps(sample_data)
resp, body = self.client.post('v1/services', sample_json)
self.assertEqual(resp.status, 201)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, sample_data)
self._delete_service(json_data['uuid'])
@ -84,7 +93,9 @@ class TestServiceController(base.TestCase):
uuid = self._create_service()
resp, body = self.client.get('v1/services/%s' % uuid)
self.assertEqual(resp.status, 200)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, sample_data)
self._delete_service(uuid)
@ -102,7 +113,9 @@ class TestServiceController(base.TestCase):
updated_json = json.dumps(updated_data)
resp, body = self.client.put('v1/services/%s' % uuid, updated_json)
self.assertEqual(resp.status, 200)
json_data = json.loads(body.decode('utf-8'))
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
json_data = json.loads(body)
self._assert_output_expected(json_data, updated_data)
self._delete_service(uuid)
@ -124,8 +137,10 @@ class TestServiceController(base.TestCase):
def test_services_delete(self):
uuid = self._create_service()
resp, body = self.client.delete('v1/services/%s' % uuid)
if isinstance(body, six.binary_type):
body = body.decode('utf-8')
self.assertEqual(resp.status, 204)
self.assertEqual(body, b'')
self.assertEqual(body, '')
def test_services_delete_not_found(self):
self.assertRaises(tempest_exceptions.NotFound,