Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
ad992d3a
Commit
ad992d3a
authored
Nov 08, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed missing key error
parent
4a41f8fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
242 additions
and
202 deletions
+242
-202
tosca_template_service.py
...flask-server/sure_tosca/service/tosca_template_service.py
+7
-2
test_default_controller.py
...a-flask-server/sure_tosca/test/test_default_controller.py
+235
-200
No files found.
sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py
View file @
ad992d3a
...
...
@@ -42,8 +42,12 @@ def query_db(queries, db=None):
updated_results
=
[]
for
res
in
results
:
if
root_key
in
res
:
key
=
res
[
root_key
]
node
=
{
key
:
res
}
res_copy
=
copy
.
deepcopy
(
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
)
return
updated_results
return
None
...
...
@@ -65,6 +69,7 @@ def get_tosca_template(tosca_template_dict):
def
get_tosca_template_dict_by_id
(
id
):
tosca_template_dict
=
tosca_templates_db
.
get
(
doc_id
=
int
(
id
))
return
tosca_template_dict
...
...
sure_tosca-flask-server/sure_tosca/test/test_default_controller.py
View file @
ad992d3a
...
...
@@ -4,6 +4,7 @@ from __future__ import absolute_import
from
flask
import
json
from
six
import
BytesIO
import
os
from
sure_tosca.models.node_template
import
NodeTemplateModel
# noqa: E501
from
sure_tosca.models.topology_template
import
TopologyTemplateModel
# noqa: E501
...
...
@@ -19,232 +20,266 @@ class TestDefaultController(BaseTestCase):
"""
id_example
=
self
.
upload_file
()
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'
)
self
.
assert200
(
response
,
'Response body is : '
+
response
.
data
.
decode
(
'utf-8'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
response
.
is_json
)
self
.
assertIsInstance
(
response
.
json
,
list
)
def
test_get_all_ancestor_types
(
self
):
"""Test case for get_all_ancestor_types
"""
id_example
=
self
.
upload_file
()
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'
)
self
.
assert200
(
response
,
'Response body is : '
+
response
.
data
.
decode
(
'utf-8'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
response
.
is_json
)
self
.
assertIsInstance
(
response
.
json
,
list
)
def
test_get_ancestors_requirements
(
self
):
"""Test case for get_ancestors_requirements
"""
response
=
self
.
client
.
open
(
'/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
id_example
=
self
.
upload_file
()
"""
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'
)
self
.
assert200
(
response
,
'Response body is : '
+
response
.
data
.
decode
(
'utf-8'
))
def
test_get_node_templates
(
self
):
"""Test case for get_node_templates
"""
query_string
=
[(
'type_name'
,
'type_name_example'
),
(
'node_name'
,
'node_name_example'
),
(
'has_interfaces'
,
true
),
(
'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}/topology_template/node_templates'
.
format
(
id
=
'id_example'
),
method
=
'GET'
,
query_string
=
query_string
)
self
.
assert200
(
response
,
'Response body is : '
+
response
.
data
.
decode
(
'utf-8'
))
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}/topology_template/node_templates/{node_name}/type_name'
.
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_parent_type_name
(
self
):
"""Test case for get_parent_type_name
"""
response
=
self
.
client
.
open
(
'/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'
))
def
test_get_related_nodes
(
self
):
"""Test case for get_related_nodes
"""
response
=
self
.
client
.
open
(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'
.
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_relationship_templates
(
self
):
"""Test case for get_relationship_templates
"""
query_string
=
[(
'type_name'
,
'type_name_example'
),
(
'derived_from'
,
'derived_from_example'
)]
response
=
self
.
client
.
open
(
'/tosca-sure/1.0.0/tosca_template/{id}/relationship_templates'
.
format
(
id
=
'id_example'
),
method
=
'GET'
,
query_string
=
query_string
)
self
.
assert200
(
response
,
'Response body is : '
+
response
.
data
.
decode
(
'utf-8'
))
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'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
response
.
is_json
)
self
.
assertIsInstance
(
response
.
json
,
list
)
# 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')
# 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(
# '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/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_node_templates(self):
# """Test case for get_node_templates
#
#
# """
# query_string = [('type_name', 'type_name_example'),
# ('node_name', 'node_name_example'),
# ('has_interfaces', True),
# ('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}/topology_template/node_templates'.format(id='id_example'),
# method='GET',
# query_string=query_string)
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
# 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}/topology_template/node_templates/{node_name}/type_name'.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_parent_type_name(self):
# """Test case for get_parent_type_name
#
#
# """
# response = self.client.open(
# '/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'))
#
# def test_get_related_nodes(self):
# """Test case for get_related_nodes
#
#
# """
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/{node_name}/related'.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_relationship_templates(self):
# """Test case for get_relationship_templates
#
#
# """
# query_string = [('type_name', 'type_name_example'),
# ('derived_from', 'derived_from_example')]
# response = self.client.open(
# '/tosca-sure/1.0.0/tosca_template/{id}/relationship_templates'.format(id='id_example'),
# method='GET',
# query_string=query_string)
# self.assert200(response,
# 'Response body is : ' + response.data.decode('utf-8'))
#
# 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
(
'/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'
))
file_id
=
response
.
data
.
decode
(
'utf-8'
)
.
replace
(
'
\n
'
,
''
)
return
file_id
if
__name__
==
'__main__'
:
import
unittest
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment