Add negative tests to api
1. Add couple of negative tests, find the way, more to go. 2. Add assertNotFound to the base test class for convenience. 3. MistralException - added default message to enable default instantiation - make mock.assertRaise fails when exception has no default constructor Change-Id: I708637e3995597a819571a90f3292d6e34deab4e
This commit is contained in:
parent
aae48e19ec
commit
1c15945f86
@ -29,7 +29,8 @@ class MistralException(ex.Error):
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
def __init__(self, message):
|
||||
def __init__(self, message=message):
|
||||
self.message = message
|
||||
super(MistralException, self).__init__(
|
||||
'%s: %s' % (self.code, self.message))
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
import pecan
|
||||
import pecan.testing
|
||||
from webtest.app import AppError
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
@ -55,3 +56,12 @@ class FunctionalTest(test_base.DbTestCase):
|
||||
def tearDown(self):
|
||||
super(FunctionalTest, self).tearDown()
|
||||
pecan.set_config({}, overwrite=True)
|
||||
|
||||
def assertNotFound(self, url):
|
||||
try:
|
||||
self.app.get(url, headers={'Accept': 'application/json'})
|
||||
except AppError as error:
|
||||
if hasattr(error, 'message'):
|
||||
self.assertIn('Bad response: 404 Not Found', error.message)
|
||||
return
|
||||
self.fail('Expected 404 Not found but got OK')
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
import mock
|
||||
|
||||
from mistral import exceptions as ex
|
||||
from webtest.app import AppError
|
||||
from mistral.tests.api import base
|
||||
from mistral.db import api as db_api
|
||||
from mistral.engine import engine
|
||||
@ -52,6 +54,11 @@ class TestExecutionsController(base.FunctionalTest):
|
||||
self.assertEqual(resp.status_int, 200)
|
||||
self.assertDictEqual(EXECS[0], resp.json)
|
||||
|
||||
@mock.patch.object(db_api, "execution_get",
|
||||
mock.MagicMock(return_value=None))
|
||||
def test_get_empty(self):
|
||||
self.assertNotFound('/v1/workbooks/my_workbook/executions/123')
|
||||
|
||||
@mock.patch.object(db_api, "execution_update",
|
||||
mock.MagicMock(return_value=UPDATED_EXEC))
|
||||
def test_put(self):
|
||||
@ -66,10 +73,17 @@ class TestExecutionsController(base.FunctionalTest):
|
||||
def test_post(self):
|
||||
resp = self.app.post_json('/v1/workbooks/my_workbook/executions',
|
||||
EXECS[0])
|
||||
|
||||
self.assertEqual(resp.status_int, 201)
|
||||
self.assertDictEqual(EXECS[0], resp.json)
|
||||
|
||||
@mock.patch.object(engine, "start_workflow_execution",
|
||||
mock.MagicMock(side_effect=ex.MistralException))
|
||||
def test_post_throws_exception(self):
|
||||
with self.assertRaises(AppError) as context:
|
||||
self.app.post_json('/v1/workbooks/my_workbook/executions',
|
||||
EXECS[0])
|
||||
self.assertIn('Bad response: 400', context.exception.message)
|
||||
|
||||
@mock.patch.object(db_api, "execution_delete",
|
||||
mock.MagicMock(return_value=None))
|
||||
def test_delete(self):
|
||||
|
Loading…
Reference in New Issue
Block a user