Modify class structures for tests
This patch introduces a new class hierarchy for tests and makes the application return JSON responses when it catches Neutron exceptions. Change-Id: I4cfd413067772f5907068a13a15d448ba968b39e Signed-off-by: Taku Fukushima <f.tac.mac@gmail.com>
This commit is contained in:
parent
8d6b0f0d16
commit
50b9f430bc
@ -20,5 +20,20 @@ class TestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCase, self).setUp()
|
||||
app.config['DEBUG'] = True
|
||||
app.config['TESTING'] = True
|
||||
self.app = app.test_client()
|
||||
|
||||
|
||||
class TestKuryrBase(TestCase):
|
||||
"""Base class for all Kuryr unittests."""
|
||||
|
||||
def setUp(self):
|
||||
super(TestKuryrBase, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestKuryrBase, self).tearDown()
|
||||
|
||||
|
||||
class TestKuryrFailures(TestKuryrBase):
|
||||
"""Unitests for checking if Kuryr handles the failures appropriately."""
|
||||
|
@ -14,11 +14,11 @@ from ddt import ddt, data, unpack
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from kuryr.constants import SCHEMA
|
||||
from kuryr.tests import base
|
||||
from kuryr.tests.base import TestKuryrBase
|
||||
|
||||
|
||||
@ddt
|
||||
class TestKuryr(base.TestCase):
|
||||
class TestKuryr(TestKuryrBase):
|
||||
"""Basic unitests for libnetwork remote driver URI endpoints.
|
||||
|
||||
This test class covers the following HTTP methods and URIs as described in
|
||||
@ -35,7 +35,6 @@ class TestKuryr(base.TestCase):
|
||||
- POST /NetworkDriver.Join
|
||||
- POST /NetworkDriver.Leave
|
||||
"""
|
||||
|
||||
@data(('/Plugin.Activate', SCHEMA['PLUGIN_ACTIVATE']),
|
||||
('/NetworkDriver.CreateNetwork', SCHEMA['SUCCESS']),
|
||||
('/NetworkDriver.DeleteNetwork', SCHEMA['SUCCESS']),
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from flask import Flask, jsonify
|
||||
from neutronclient.common.exceptions import NeutronClientException
|
||||
from werkzeug.exceptions import default_exceptions
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
@ -30,6 +31,9 @@ def make_json_app(import_name, **kwargs):
|
||||
See:
|
||||
- https://github.com/docker/libnetwork/blob/3c8e06bc0580a2a1b2440fe0792fbfcd43a9feca/docs/remote.md#errors # noqa
|
||||
"""
|
||||
app = Flask(import_name, **kwargs)
|
||||
|
||||
@app.errorhandler(NeutronClientException)
|
||||
def make_json_error(ex):
|
||||
response = jsonify({"Err": str(ex)})
|
||||
response.status_code = (ex.code
|
||||
@ -39,8 +43,6 @@ def make_json_app(import_name, **kwargs):
|
||||
response.headers['Content-Type'] = content_type
|
||||
return response
|
||||
|
||||
app = Flask(import_name, **kwargs)
|
||||
|
||||
for code in default_exceptions.iterkeys():
|
||||
app.error_handler_spec[None][code] = make_json_error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user