Commit f7b8348a authored by Spiros Koulouzis's avatar Spiros Koulouzis

1st commit

parent 935a2048
.travis.yaml
.swagger-codegen-ignore
README.md
tox.ini
git_push.sh
test-requirements.txt
setup.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints
# Default ignored files
/workspace.xml
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Default" />
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (sure_tosca-flask-server)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
<component name="PythonCompatibilityInspectionAdvertiser">
<option name="version" value="3" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sure_tosca-flask-server.iml" filepath="$PROJECT_DIR$/.idea/sure_tosca-flask-server.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6 (sure_tosca-flask-server)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
#- "3.5-dev" # 3.5 development branch
#- "nightly" # points to the latest development branch e.g. 3.6-dev
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
script: nosetests
FROM python:2-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
EXPOSE 8081
ENTRYPOINT ["python"]
CMD ["-m", "sure_tosca"]
\ No newline at end of file
# Swagger generated server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a swagger-enabled Flask server.
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
## Requirements
Python 2.7+
## Usage
To run the server, please execute the following from the root directory:
```
pip install -r requirements.txt
python -m sure_tosca
```
and open your browser to here:
```
http://localhost:8081/tosca-sure/1.0.0/ui/
```
Your Swagger definition lives here:
```
http://localhost:8081/tosca-sure/1.0.0/swagger.json
```
To launch the integration tests, use tox:
```
sudo pip install tox
tox
```
## Running with Docker
To run the server on a Docker container, please execute the following from the root directory:
```bash
# building the image
docker build -t sure_tosca .
# starting up a container
docker run -p 8081:8081 sure_tosca
```
\ No newline at end of file
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
git_user_id=$1
git_repo_id=$2
release_note=$3
if [ "$git_user_id" = "" ]; then
git_user_id=""
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id=""
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note=""
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi
# Initialize the local directory as a Git repository
git init
# Adds the files in the local repository and stages them for commit.
git add .
# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"
# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
fi
fi
git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'
connexion == 2.4.0
python-dateutil == 2.8.0
typing == 3.7.4.1
swagger-ui-bundle == 0.0.5
\ No newline at end of file
# coding: utf-8
import sys
from setuptools import setup, find_packages
NAME = "sure_tosca"
VERSION = "1.0.0"
# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
REQUIRES = ["connexion"]
setup(
name=NAME,
version=VERSION,
description="tosca-sure",
author_email="S.Koulouzis@uva.nl",
url="",
keywords=["Swagger", "tosca-sure"],
install_requires=REQUIRES,
packages=find_packages(),
package_data={'': ['swagger/swagger.yaml']},
include_package_data=True,
entry_points={
'console_scripts': ['sure_tosca=sure_tosca.__main__:main']},
long_description="""\
TOSCA Simple qUeRy sErvice (SURE).
"""
)
#!/usr/bin/env python
import connexion
from sure_tosca import encoder
def main():
app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'tosca-sure'})
app.run(port=8081)
if __name__ == '__main__':
main()
import connexion
import six
from sure_tosca.models.node_template import NodeTemplate # noqa: E501
from sure_tosca.models.topology_template import TopologyTemplate # noqa: E501
from sure_tosca.models.tosca_template import ToscaTemplate # noqa: E501
from sure_tosca import util
def get_all_ancestor_properties(id, body=None, node_name=None): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node&#39;s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: List[Dict[str, object]]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_all_ancestor_types(id, body=None, node_name=None): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node&#39;s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: List[str]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_ancestors_requirements(id, body=None, node_name=None): # noqa: E501
"""
Recursively get all requirements all the way to the ROOT including the input node&#39;s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_interface_types(id, body=None, interface_type=None): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param interface_type: The interface type
:type interface_type: str
:rtype: List[Dict[str, object]]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_node_outputs(id, body=None, node_name=None): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_node_properties(id, body=None, node_name=None): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_node_requirements(id, body=None, node_name=None): # noqa: E501
"""get_node_requirements
Returns the requirements for an input node as described in the template not in the node&#39;s definition # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: Dict[str, object]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_node_templates(id, node_name=None, node_type=None, has_interface=None): # noqa: E501
"""get_node_templates
returns nodes templates in topology # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_name: filter by node name
:type node_name: str
:param node_type: filter by node type
:type node_type: str
:param has_interface: filter if node has interface
:type has_interface: bool
:rtype: List[NodeTemplate]
"""
return 'do some magic!'
def get_node_type_name(id, body=None, node_name=None): # noqa: E501
"""
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: str
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_parent_type_name(id, body=None, node_name=None): # noqa: E501
"""
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: str
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_related_node(id, body=None, node_name=None): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param body:
:type body: dict | bytes
:param node_name: The node name
:type node_name: str
:rtype: List[NodeTemplate]
"""
if connexion.request.is_json:
body = NodeTemplate.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def get_topology_template(id): # noqa: E501
"""get_topology_template
r # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:rtype: TopologyTemplate
"""
return 'do some magic!'
def get_tosca_template(id): # noqa: E501
"""get_tosca_template
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:rtype: ToscaTemplate
"""
return 'do some magic!'
def set_node_properties(id, properties, node_name): # noqa: E501
"""
s # noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param properties:
:type properties:
:param node_name: The node name
:type node_name: str
:rtype: Dict[str, object]
"""
return 'do some magic!'
def upload_tosca_template(file): # noqa: E501
"""upload a tosca template description file
upload and validate a tosca template description file # noqa: E501
:param file: tosca Template description
:type file: werkzeug.datastructures.FileStorage
:rtype: str
"""
return 'do some magic!'
from connexion.apps.flask_app import FlaskJSONEncoder
import six
from sure_tosca.models.base_model_ import Model
class JSONEncoder(FlaskJSONEncoder):
include_nulls = False
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
attr = o.attribute_map[attr]
dikt[attr] = value
return dikt
return FlaskJSONEncoder.default(self, o)
# coding: utf-8
# flake8: noqa
from __future__ import absolute_import
# import models into model package
from sure_tosca.models.node_template import NodeTemplate
from sure_tosca.models.topology_template import TopologyTemplate
from sure_tosca.models.tosca_template import ToscaTemplate
import pprint
import six
from sure_tosca import util
class Model(object):
# swaggerTypes: The key is attribute name and the
# value is attribute type.
swagger_types = {}
# attributeMap: The key is attribute name and the
# value is json key in definition.
attribute_map = {}
@classmethod
def from_dict(cls, dikt):
"""Returns the dict as a model"""
return util.deserialize_model(dikt, cls)
def to_dict(self):
"""Returns the model properties as a dict
:rtype: dict
"""
result = {}
for attr, _ in six.iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model
:rtype: str
"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from sure_tosca.models.base_model_ import Model
from sure_tosca import util
class NodeTemplate(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, items=None, additional_properties=None): # noqa: E501
"""NodeTemplate - a model defined in Swagger
:param items: The items of this NodeTemplate. # noqa: E501
:type items: object
:param additional_properties: The additional_properties of this NodeTemplate. # noqa: E501
:type additional_properties: object
"""
self.swagger_types = {
'items': object,
'additional_properties': object
}
self.attribute_map = {
'items': 'items',
'additional_properties': 'additionalProperties'
}
self._items = items
self._additional_properties = additional_properties
@classmethod
def from_dict(cls, dikt):
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The NodeTemplate of this NodeTemplate. # noqa: E501
:rtype: NodeTemplate
"""
return util.deserialize_model(dikt, cls)
@property
def items(self):
"""Gets the items of this NodeTemplate.
:return: The items of this NodeTemplate.
:rtype: object
"""
return self._items
@items.setter
def items(self, items):
"""Sets the items of this NodeTemplate.
:param items: The items of this NodeTemplate.
:type items: object
"""
self._items = items
@property
def additional_properties(self):
"""Gets the additional_properties of this NodeTemplate.
:return: The additional_properties of this NodeTemplate.
:rtype: object
"""
return self._additional_properties
@additional_properties.setter
def additional_properties(self, additional_properties):
"""Sets the additional_properties of this NodeTemplate.
:param additional_properties: The additional_properties of this NodeTemplate.
:type additional_properties: object
"""
self._additional_properties = additional_properties
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from sure_tosca.models.base_model_ import Model
from sure_tosca import util
class TopologyTemplate(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, items=None, additional_properties=None): # noqa: E501
"""TopologyTemplate - a model defined in Swagger
:param items: The items of this TopologyTemplate. # noqa: E501
:type items: object
:param additional_properties: The additional_properties of this TopologyTemplate. # noqa: E501
:type additional_properties: object
"""
self.swagger_types = {
'items': object,
'additional_properties': object
}
self.attribute_map = {
'items': 'items',
'additional_properties': 'additionalProperties'
}
self._items = items
self._additional_properties = additional_properties
@classmethod
def from_dict(cls, dikt):
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The TopologyTemplate of this TopologyTemplate. # noqa: E501
:rtype: TopologyTemplate
"""
return util.deserialize_model(dikt, cls)
@property
def items(self):
"""Gets the items of this TopologyTemplate.
:return: The items of this TopologyTemplate.
:rtype: object
"""
return self._items
@items.setter
def items(self, items):
"""Sets the items of this TopologyTemplate.
:param items: The items of this TopologyTemplate.
:type items: object
"""
self._items = items
@property
def additional_properties(self):
"""Gets the additional_properties of this TopologyTemplate.
:return: The additional_properties of this TopologyTemplate.
:rtype: object
"""
return self._additional_properties
@additional_properties.setter
def additional_properties(self, additional_properties):
"""Sets the additional_properties of this TopologyTemplate.
:param additional_properties: The additional_properties of this TopologyTemplate.
:type additional_properties: object
"""
self._additional_properties = additional_properties
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from sure_tosca.models.base_model_ import Model
from sure_tosca import util
class ToscaTemplate(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, items=None, additional_properties=None): # noqa: E501
"""ToscaTemplate - a model defined in Swagger
:param items: The items of this ToscaTemplate. # noqa: E501
:type items: str
:param additional_properties: The additional_properties of this ToscaTemplate. # noqa: E501
:type additional_properties: object
"""
self.swagger_types = {
'items': str,
'additional_properties': object
}
self.attribute_map = {
'items': 'items',
'additional_properties': 'additionalProperties'
}
self._items = items
self._additional_properties = additional_properties
@classmethod
def from_dict(cls, dikt):
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The ToscaTemplate of this ToscaTemplate. # noqa: E501
:rtype: ToscaTemplate
"""
return util.deserialize_model(dikt, cls)
@property
def items(self):
"""Gets the items of this ToscaTemplate.
:return: The items of this ToscaTemplate.
:rtype: str
"""
return self._items
@items.setter
def items(self, items):
"""Sets the items of this ToscaTemplate.
:param items: The items of this ToscaTemplate.
:type items: str
"""
self._items = items
@property
def additional_properties(self):
"""Gets the additional_properties of this ToscaTemplate.
:return: The additional_properties of this ToscaTemplate.
:rtype: object
"""
return self._additional_properties
@additional_properties.setter
def additional_properties(self, additional_properties):
"""Sets the additional_properties of this ToscaTemplate.
:param additional_properties: The additional_properties of this ToscaTemplate.
:type additional_properties: object
"""
self._additional_properties = additional_properties
This diff is collapsed.
import logging
import connexion
from flask_testing import TestCase
from sure_tosca.encoder import JSONEncoder
class BaseTestCase(TestCase):
def create_app(self):
logging.getLogger('connexion.operation').setLevel('ERROR')
app = connexion.App(__name__, specification_dir='../swagger/')
app.app.json_encoder = JSONEncoder
app.add_api('swagger.yaml')
return app.app
# coding: utf-8
from __future__ import absolute_import
from flask import json
from six import BytesIO
from sure_tosca.models.node_template import NodeTemplate # noqa: E501
from sure_tosca.models.topology_template import TopologyTemplate # noqa: E501
from sure_tosca.models.tosca_template import ToscaTemplate # noqa: E501
from sure_tosca.test import BaseTestCase
class TestDefaultController(BaseTestCase):
"""DefaultController integration test stubs"""
def test_get_all_ancestor_properties(self):
"""Test case for get_all_ancestor_properties
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/ancestors_properties'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_all_ancestor_types(self):
"""Test case for get_all_ancestor_types
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/ancestors_types'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_ancestors_requirements(self):
"""Test case for get_ancestors_requirements
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/ancestors_requirements'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_interface_types(self):
"""Test case for get_interface_types
"""
body = NodeTemplate()
query_string = [('interface_type', 'interface_type_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/interface_types'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_outputs(self):
"""Test case for get_node_outputs
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/outputs'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_properties(self):
"""Test case for get_node_properties
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/properties'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_node_requirements(self):
"""Test case for get_node_requirements
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/requirements'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
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 = [('node_name', 'node_name_example'),
('node_type', 'node_type_example'),
('has_interface', true)]
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
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/type_name'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
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
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/parent_type_name'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_related_node(self):
"""Test case for get_related_node
"""
body = NodeTemplate()
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/related'.format(id='id_example'),
method='GET',
data=json.dumps(body),
content_type='application/json',
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_set_node_properties(self):
"""Test case for set_node_properties
"""
properties = None
query_string = [('node_name', 'node_name_example')]
response = self.client.open(
'/tosca-sure/1.0.0/tosca_template/{id}/topology_template/node_templates/properties'.format(id='id_example'),
method='PUT',
data=json.dumps(properties),
content_type='application/json',
query_string=query_string)
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'))
if __name__ == '__main__':
import unittest
unittest.main()
import datetime
import six
import typing
def _deserialize(data, klass):
"""Deserializes dict, list, str into an object.
:param data: dict, list or str.
:param klass: class literal, or string of class name.
:return: object.
"""
if data is None:
return None
if klass in six.integer_types or klass in (float, str, bool):
return _deserialize_primitive(data, klass)
elif klass == object:
return _deserialize_object(data)
elif klass == datetime.date:
return deserialize_date(data)
elif klass == datetime.datetime:
return deserialize_datetime(data)
elif type(klass) == typing.GenericMeta:
if klass.__extra__ == list:
return _deserialize_list(data, klass.__args__[0])
if klass.__extra__ == dict:
return _deserialize_dict(data, klass.__args__[1])
else:
return deserialize_model(data, klass)
def _deserialize_primitive(data, klass):
"""Deserializes to primitive type.
:param data: data to deserialize.
:param klass: class literal.
:return: int, long, float, str, bool.
:rtype: int | long | float | str | bool
"""
try:
value = klass(data)
except UnicodeEncodeError:
value = six.u(data)
except TypeError:
value = data
return value
def _deserialize_object(value):
"""Return a original value.
:return: object.
"""
return value
def deserialize_date(string):
"""Deserializes string to date.
:param string: str.
:type string: str
:return: date.
:rtype: date
"""
try:
from dateutil.parser import parse
return parse(string).date()
except ImportError:
return string
def deserialize_datetime(string):
"""Deserializes string to datetime.
The string should be in iso8601 datetime format.
:param string: str.
:type string: str
:return: datetime.
:rtype: datetime
"""
try:
from dateutil.parser import parse
return parse(string)
except ImportError:
return string
def deserialize_model(data, klass):
"""Deserializes list or dict to model.
:param data: dict, list.
:type data: dict | list
:param klass: class literal.
:return: model object.
"""
instance = klass()
if not instance.swagger_types:
return data
for attr, attr_type in six.iteritems(instance.swagger_types):
if data is not None \
and instance.attribute_map[attr] in data \
and isinstance(data, (list, dict)):
value = data[instance.attribute_map[attr]]
setattr(instance, attr, _deserialize(value, attr_type))
return instance
def _deserialize_list(data, boxed_type):
"""Deserializes a list and its elements.
:param data: list to deserialize.
:type data: list
:param boxed_type: class literal.
:return: deserialized list.
:rtype: list
"""
return [_deserialize(sub_data, boxed_type)
for sub_data in data]
def _deserialize_dict(data, boxed_type):
"""Deserializes a dict and its elements.
:param data: dict to deserialize.
:type data: dict
:param boxed_type: class literal.
:return: deserialized dict.
:rtype: dict
"""
return {k: _deserialize(v, boxed_type)
for k, v in six.iteritems(data)}
flask-testing==0.7.1
coverage==4.5.4
nose>=1.3.7
pluggy>=0.13.0
#py>=1.4.31
randomize>=0.14
[tox]
envlist = py27, py35
[testenv]
deps=-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands=
nosetests \
[]
\ No newline at end of file
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