Commit ad992d3a authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed missing key error

parent 4a41f8fd
...@@ -42,8 +42,12 @@ def query_db(queries, db=None): ...@@ -42,8 +42,12 @@ def query_db(queries, db=None):
updated_results = [] updated_results = []
for res in results: for res in results:
if root_key in res: if root_key in res:
key = res[root_key] res_copy = copy.deepcopy(res)
node = {key: res} key = res_copy[root_key]
res_copy.pop(root_key)
node = {key: res_copy}
else:
logging.error(str(res)+ ' has no '+root_key)
updated_results.append(node) updated_results.append(node)
return updated_results return updated_results
return None return None
...@@ -65,6 +69,7 @@ def get_tosca_template(tosca_template_dict): ...@@ -65,6 +69,7 @@ def get_tosca_template(tosca_template_dict):
def get_tosca_template_dict_by_id(id): def get_tosca_template_dict_by_id(id):
tosca_template_dict = tosca_templates_db.get(doc_id=int(id)) tosca_template_dict = tosca_templates_db.get(doc_id=int(id))
return tosca_template_dict return tosca_template_dict
......
...@@ -4,6 +4,7 @@ from __future__ import absolute_import ...@@ -4,6 +4,7 @@ from __future__ import absolute_import
from flask import json from flask import json
from six import BytesIO from six import BytesIO
import os
from sure_tosca.models.node_template import NodeTemplateModel # noqa: E501 from sure_tosca.models.node_template import NodeTemplateModel # noqa: E501
from sure_tosca.models.topology_template import TopologyTemplateModel # noqa: E501 from sure_tosca.models.topology_template import TopologyTemplateModel # noqa: E501
...@@ -19,232 +20,266 @@ class TestDefaultController(BaseTestCase): ...@@ -19,232 +20,266 @@ class TestDefaultController(BaseTestCase):
""" """
id_example = self.upload_file()
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties'.format(id='id_example', node_name='node_name_example'), '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties'.format(
id=id_example, node_name='compute'),
method='GET') method='GET')
self.assert200(response, self.assertEqual(response.status_code, 200)
'Response body is : ' + response.data.decode('utf-8')) self.assertTrue(response.is_json)
self.assertIsInstance(response.json, list)
def test_get_all_ancestor_types(self): def test_get_all_ancestor_types(self):
"""Test case for get_all_ancestor_types """Test case for get_all_ancestor_types
""" """
id_example = self.upload_file()
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types'.format(id='id_example', node_name='node_name_example'), '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types'.format(
id=id_example, node_name='compute'),
method='GET') method='GET')
self.assert200(response, self.assertEqual(response.status_code, 200)
'Response body is : ' + response.data.decode('utf-8')) self.assertTrue(response.is_json)
self.assertIsInstance(response.json, list)
def test_get_ancestors_requirements(self): def test_get_ancestors_requirements(self):
"""Test case for get_ancestors_requirements """Test case for get_ancestors_requirements
""" """
response = self.client.open( id_example = self.upload_file()
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_dsl_definitions(self):
"""Test case for get_dsl_definitions
"""
query_string = [('anchors', 'anchors_example'),
('derived_from', 'derived_from_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/dsl_definitions'.format(id='id_example'),
method='GET',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_imports(self):
"""Test case for get_imports
"""
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/imports'.format(id='id_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_outputs(self):
"""Test case for get_node_outputs
"""
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_properties(self):
"""Test case for get_node_properties
"""
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(id='id_example', node_name='node_name_example'),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_requirements(self):
"""Test case for get_node_requirements
"""
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements'.format(id='id_example', node_name='node_name_example'), '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements'.format(
id=id_example, node_name='kubernetes'),
method='GET') method='GET')
self.assert200(response, self.assertEqual(response.status_code, 200)
'Response body is : ' + response.data.decode('utf-8')) self.assertTrue(response.is_json)
self.assertIsInstance(response.json, list)
def test_get_node_templates(self):
"""Test case for get_node_templates # def test_get_dsl_definitions(self):
# """Test case for get_dsl_definitions
#
""" #
query_string = [('type_name', 'type_name_example'), # """
('node_name', 'node_name_example'), # # query_string = [('anchors', 'anchors_example'), ('derived_from', 'derived_from_example')]
('has_interfaces', true), # response = self.client.open(
('has_properties', true), # '/tosca-sure/1.0.0/tosca_template/{id}/dsl_definitions'.format(id='id_example'),
('has_attributes', true), # method='GET')
('has_requirements', true), # self.assert200(response,
('has_capabilities', true), # 'Response body is : ' + response.data.decode('utf-8'))
('has_artifacts', true), #
('derived_from', 'derived_from_example')] # def test_get_imports(self):
response = self.client.open( # """Test case for get_imports
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates'.format(id='id_example'), #
method='GET', #
query_string=query_string) # """
self.assert200(response, # response = self.client.open(
'Response body is : ' + response.data.decode('utf-8')) # '/tosca-sure/1.0.0/tosca_template/{id}/imports'.format(id='id_example'),
# method='GET')
def test_get_node_type_name(self): # self.assert200(response,
"""Test case for get_node_type_name # 'Response body is : ' + response.data.decode('utf-8'))
#
# def test_get_node_outputs(self):
""" # """Test case for get_node_outputs
response = self.client.open( #
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name'.format(id='id_example', node_name='node_name_example'), #
method='GET') # """
self.assert200(response, # response = self.client.open(
'Response body is : ' + response.data.decode('utf-8')) # '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs'.format(
# id='id_example', node_name='node_name_example'),
def test_get_parent_type_name(self): # method='GET')
"""Test case for get_parent_type_name # self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
""" # def test_get_node_properties(self):
response = self.client.open( # """Test case for get_node_properties
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from'.format(id='id_example', node_name='node_name_example'), #
method='GET') #
self.assert200(response, # """
'Response body is : ' + response.data.decode('utf-8')) # response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(
def test_get_related_nodes(self): # id='id_example', node_name='node_name_example'),
"""Test case for get_related_nodes # method='GET')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
""" #
response = self.client.open( # def test_get_node_requirements(self):
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'.format(id='id_example', node_name='node_name_example'), # """Test case for get_node_requirements
method='GET') #
self.assert200(response, #
'Response body is : ' + response.data.decode('utf-8')) # """
# response = self.client.open(
def test_get_relationship_templates(self): # '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements'.format(
"""Test case for get_relationship_templates # id='id_example', node_name='node_name_example'),
# method='GET')
# self.assert200(response,
""" # 'Response body is : ' + response.data.decode('utf-8'))
query_string = [('type_name', 'type_name_example'), #
('derived_from', 'derived_from_example')] # def test_get_node_templates(self):
response = self.client.open( # """Test case for get_node_templates
'/tosca-sure/1.0.0/tosca_template/{id}/relationship_templates'.format(id='id_example'), #
method='GET', #
query_string=query_string) # """
self.assert200(response, # query_string = [('type_name', 'type_name_example'),
'Response body is : ' + response.data.decode('utf-8')) # ('node_name', 'node_name_example'),
# ('has_interfaces', True),
def test_get_topology_template(self): # ('has_properties', True),
"""Test case for get_topology_template # ('has_attributes', True),
# ('has_requirements', True),
# ('has_capabilities', True),
""" # ('has_artifacts', True),
response = self.client.open( # ('derived_from', 'derived_from_example')]
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template'.format(id='id_example'), # response = self.client.open(
method='GET') # '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates'.format(id='id_example'),
self.assert200(response, # method='GET',
'Response body is : ' + response.data.decode('utf-8')) # query_string=query_string)
# self.assert200(response,
def test_get_tosca_template(self): # 'Response body is : ' + response.data.decode('utf-8'))
"""Test case for get_tosca_template #
# def test_get_node_type_name(self):
# """Test case for get_node_type_name
""" #
response = self.client.open( #
'/tosca-sure/1.0.0/tosca_template/{id}'.format(id='id_example'), # """
method='GET') # response = self.client.open(
self.assert200(response, # '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name'.format(
'Response body is : ' + response.data.decode('utf-8')) # id='id_example', node_name='node_name_example'),
# method='GET')
def test_get_types(self): # self.assert200(response,
"""Test case for get_types # 'Response body is : ' + response.data.decode('utf-8'))
#
# def test_get_parent_type_name(self):
""" # """Test case for get_parent_type_name
query_string = [('kind_of_type', 'kind_of_type_example'), #
('has_interfaces', true), #
('type_name', 'type_name_example'), # """
('has_properties', true), # response = self.client.open(
('has_attributes', true), # '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from'.format(
('has_requirements', true), # id='id_example', node_name='node_name_example'),
('has_capabilities', true), # method='GET')
('has_artifacts', true), # self.assert200(response,
('derived_from', 'derived_from_example')] # 'Response body is : ' + response.data.decode('utf-8'))
response = self.client.open( #
'/tosca-sure/1.0.0/tosca_template/{id}/types'.format(id='id_example'), # def test_get_related_nodes(self):
method='GET', # """Test case for get_related_nodes
query_string=query_string) #
self.assert200(response, #
'Response body is : ' + response.data.decode('utf-8')) # """
# response = self.client.open(
def test_set_node_properties(self): # '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'.format(
"""Test case for set_node_properties # id='id_example', node_name='node_name_example'),
# method='GET')
# self.assert200(response,
""" # 'Response body is : ' + response.data.decode('utf-8'))
properties = None #
response = self.client.open( # def test_get_relationship_templates(self):
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(id='id_example', node_name='node_name_example'), # """Test case for get_relationship_templates
method='PUT', #
data=json.dumps(properties), #
content_type='application/json') # """
self.assert200(response, # query_string = [('type_name', 'type_name_example'),
'Response body is : ' + response.data.decode('utf-8')) # ('derived_from', 'derived_from_example')]
# response = self.client.open(
def test_upload_tosca_template(self): # '/tosca-sure/1.0.0/tosca_template/{id}/relationship_templates'.format(id='id_example'),
"""Test case for upload_tosca_template # method='GET',
# query_string=query_string)
upload a tosca template description file # self.assert200(response,
""" # 'Response body is : ' + response.data.decode('utf-8'))
data = dict(file=(BytesIO(b'some file data'), 'file.txt')) #
# def test_get_topology_template(self):
# """Test case for get_topology_template
#
#
# """
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}/topology_template'.format(id='id_example'),
# method='GET')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
# def test_get_tosca_template(self):
# """Test case for get_tosca_template
#
#
# """
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}'.format(id='id_example'),
# method='GET')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
# def test_get_types(self):
# """Test case for get_types
#
#
# """
# query_string = [('kind_of_type', 'kind_of_type_example'),
# ('has_interfaces', True),
# ('type_name', 'type_name_example'),
# ('has_properties', True),
# ('has_attributes', True),
# ('has_requirements', True),
# ('has_capabilities', True),
# ('has_artifacts', True),
# ('derived_from', 'derived_from_example')]
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}/types'.format(id='id_example'),
# method='GET',
# query_string=query_string)
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
# def test_set_node_properties(self):
# """Test case for set_node_properties
#
#
# """
# properties = None
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/properties'.format(
# id='id_example', node_name='node_name_example'),
# method='PUT',
# data=json.dumps(properties),
# content_type='application/json')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
# def test_upload_tosca_template(self):
# """Test case for upload_tosca_template
#
# upload a tosca template description file
# """
# data = dict(file=(BytesIO(b'some file data'), 'file.txt'))
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template',
# method='POST',
# data=data,
# content_type='multipart/form-data')
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
def upload_file(self):
tosca_path = "../../../TOSCA/"
input_tosca_file_path = tosca_path + '/application_example_2_topologies.yaml'
self.assertEqual(True, os.path.exists(input_tosca_file_path),
"Input TOSCA file: " + input_tosca_file_path + " not found")
with open(input_tosca_file_path, 'r') as file:
contents = file.read()
byte_contents = bytes(contents, 'utf8')
data = dict(file=(BytesIO(byte_contents), input_tosca_file_path))
response = self.client.open( response = self.client.open(
'/tosca-sure/1.0.0/tosca_template', '/tosca-sure/1.0.0/tosca_template',
method='POST', method='POST',
data=data, data=data,
content_type='multipart/form-data') content_type='multipart/form-data')
self.assert200(response, file_id = response.data.decode('utf-8').replace('\n', '')
'Response body is : ' + response.data.decode('utf-8')) return file_id
if __name__ == '__main__': if __name__ == '__main__':
import unittest import unittest
unittest.main() unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment