Browse Source

Merge "add validation for trigger update"

changes/16/648116/1
Zuul 2 years ago
committed by Gerrit Code Review
parent
commit
b7c0857b0f
  1. 1
      karbor/api/v1/triggers.py
  2. 17
      karbor/tests/unit/api/v1/test_triggers.py

1
karbor/api/v1/triggers.py

@ -170,6 +170,7 @@ class TriggersController(wsgi.Controller):
raise exc.HTTPBadRequest(explanation=msg)
try:
trigger.properties = trigger_property
self.operationengine_api.verify_trigger(context, trigger)
self.operationengine_api.update_trigger(context, trigger)
except exception.InvalidInput as ex:
raise exc.HTTPBadRequest(explanation=ex.msg)

17
karbor/tests/unit/api/v1/test_triggers.py

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from datetime import datetime
import mock
from webob import exc
from karbor.api.v1 import triggers as trigger_api
@ -127,6 +128,22 @@ class TriggerApiTest(base.TestCase):
self.assertEqual(10, int(
trigger1['trigger_info']['properties']['window']))
@mock.patch('karbor.services.operationengine.engine.triggers.timetrigger.'
'time_trigger.utils.check_trigger_definition')
def test_update_trigger_invalid_windows(self,
mock_check_trigger_definition):
trigger = self._create_one_trigger()
name = 'every minutes'
param = self.default_create_trigger_param.copy()
param['name'] = name
param['properties']['window'] = 'abc'
body = self._get_create_trigger_request_body(param)
mock_check_trigger_definition.return_value = exception.InvalidInput
self.assertRaises(exception.ValidationError,
self.controller.update,
self.req, trigger['trigger_info']['id'], body=body)
def test_show_trigger_not_exist(self):
self.assertRaises(exc.HTTPNotFound,
self.controller.show,

Loading…
Cancel
Save