Commit 20ef7ed7 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Unit test compute methods, fix emerging bugs

parent 1b369c3e
......@@ -21,7 +21,7 @@ setup(
description='OCCI to Openstack/Cyclades API bridge',
url='http://code.grnet.gr/projects/snf-occi',
license='GPLv3',
packages=['soi', ],
packages=['soi', 'soi.tests'],
entry_points='''
[paste.app_factory]
snf_occi_app=soi:main
......
......@@ -142,32 +142,21 @@ def snf_delete_server(cls, req, server_id):
def snf_run_action(cls, req, action, server_id):
"""Synnefo: server actions"""
actions_map = {
"stop": {"kwargs": {"server_id": server_id,
"json_data": {"shutdown": {}}
}
},
"start": {"kwargs": {"server_id": server_id,
"json_data": {"start": {}}
}
},
"restart": {"kwargs": {"server_id": server_id,
"json_data": {"reboot": {"type": "SOFT"}}
}
}
}
try:
action = actions_map[action]
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'servers_action_post'
req.environ.update(action)
req.get_response(cls.app)
json_data = {
'start': {'start': {}},
'stop': {'shutdown': {}},
'restart': {'reboot': {'type': 'SOFT'}}
}[action]
except KeyError:
raise webob.exc.HTTPNotImplemented(
explanation='Action {0} not supported'.format(action))
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'servers_action_post'
req.environ['kwargs'] = {'server_id': server_id, 'json_data': json_data}
req.get_response(cls.app)
function_map = {
'index': snf_index,
......
......@@ -12,31 +12,3 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This it the entry point for paste deploy .
Paste config file needs to point to egg:<package name>:<entrypoint name>:
use = egg:snfOCCI#sample_app
sample_app entry point is defined in setup.py:
entry_points='''
[paste.app_factory]
sample_app = soi:main
''',
which point to this function call (<module name>:function).
"""
from soi import wsgi
from soi import synnefo
# W0613:unused args
# pylint: disable=W0613
def main(global_config, **settings):
"""This is the entry point for paste into the Synnefo OCCI Interface"""
factory = wsgi.SNFOCCIMiddleware.factory({})
return factory(synnefo.call_kamaki)
# Copyright (C) 2016 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
class FakeReq:
"""use it for testing"""
def __init__(self, *args, **kwargs):
self.environ = dict()
def get_response(self, *args, **kwargs):
"""Don't do enything"""
class DummyClass:
"""use it for testing"""
def app(self, *args, **kwargs):
"""inner app"""
def get_from_response(self, *args, **kwargs):
"""Don't do enything"""
This diff is collapsed.
......@@ -14,6 +14,7 @@
from soi import utils
from mock import patch
from soi.tests import fakes
def test_patch_class_methods():
......@@ -38,34 +39,12 @@ def test_patch_class_methods():
assert client.an_other_method('arg1', 'arg2') == 'replace arg1 arg2'
def test_empty_list_200():
@patch('soi.tests.fakes.DummyClass.get_from_response', return_value='g f r')
@patch('soi.tests.fakes.FakeReq.get_response', return_value='my response')
def test_empty_list_200(gr, gfr):
"""Test the empty list method"""
class FakeReq:
"""use it for testing"""
environ = dict()
def get_response(self, *args, **kwargs):
"""Don't do enything"""
class DummyClass:
"""use it for testing"""
def app(self, *args, **kwargs):
"""inner app"""
def get_from_response(self, *args, **kwargs):
"""Don't do enything"""
setattr(utils, 'FakeReq', FakeReq)
setattr(utils, 'DummyClass', DummyClass)
with patch(
'soi.utils.FakeReq.get_response',
return_value='my response') as gr:
with patch(
'soi.utils.DummyClass.get_from_response',
return_value='get from response') as gfr:
cls, req = DummyClass(), FakeReq()
r = utils.empty_list_200(cls, req)
assert r == 'get from response'
gfr.assert_called_once_with('my response', 'empty list', [])
gr.assert_called_once_with(cls.app)
cls, req = fakes.DummyClass(), fakes.FakeReq()
r = utils.empty_list_200(cls, req)
assert r == 'g f r'
gfr.assert_called_once_with('my response', 'empty list', [])
gr.assert_called_once_with(cls.app)
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