def test_webhook_trigger_no_params(self, mock_get, mock_find, mock_action, notify): mock_find.return_value = mock.Mock(id='FAKE_CLUSTER') mock_get.return_value = mock.Mock(id='01234567-abcd-efef', cluster_id='FAKE_CLUSTER', action='DANCE', params={'foo': 'bar'}) mock_action.return_value = 'ACTION_ID' body = vorw.WebhookTriggerRequestBody(params={}) req = vorw.WebhookTriggerRequest(identity='FAKE_RECEIVER', body=body) res = self.eng.webhook_trigger(self.ctx, req.obj_to_primitive()) self.assertEqual({'action': 'ACTION_ID'}, res) mock_get.assert_called_once_with(self.ctx, 'FAKE_RECEIVER') mock_find.assert_called_once_with(self.ctx, 'FAKE_CLUSTER') mock_action.assert_called_once_with( self.ctx, 'FAKE_CLUSTER', 'DANCE', name='webhook_01234567', cause=action_mod.CAUSE_RPC, status=action_mod.Action.READY, inputs={'foo': 'bar'}, ) notify.assert_called_once_with()
def test_webhook_trigger_body_to_primitive(self): sot = sot = webhooks.WebhookTriggerRequestBody(params={'foo': 'boo'}) res = sot.obj_to_primitive() self.assertIn('params', res['senlin_object.changes']) self.assertEqual({'params': '{"foo": "boo"}'}, res['senlin_object.data']) self.assertEqual( 'WebhookTriggerRequestBody', res['senlin_object.name']) self.assertEqual('1.0', res['senlin_object.version']) self.assertEqual('senlin', res['senlin_object.namespace'])
def test_webhook_trigger_receiver_not_found(self, mock_find): mock_find.side_effect = exception.ResourceNotFound(type='receiver', id='RRR') body = vorw.WebhookTriggerRequestBody(params=None) req = vorw.WebhookTriggerRequest(identity='RRR', body=body) ex = self.assertRaises(rpc.ExpectedException, self.eng.webhook_trigger, self.ctx, req.obj_to_primitive()) self.assertEqual(exception.ResourceNotFound, ex.exc_info[0]) self.assertEqual('The receiver (RRR) could not be found.', six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'RRR')
def test_webhook_trigger_to_primitive(self): body = webhooks.WebhookTriggerRequestBody(params={'foo': 'boo'}) sot = webhooks.WebhookTriggerRequest(identity='fake', params=body) self.assertEqual('fake', sot.identity) self.assertIsInstance(sot.params, webhooks.WebhookTriggerRequestBody) res = sot.obj_to_primitive() self.assertIn('identity', res['senlin_object.changes']) self.assertIn('WebhookTriggerRequest', res['senlin_object.name']) self.assertEqual('1.0', res['senlin_object.version']) self.assertEqual('senlin', res['senlin_object.namespace']) self.assertEqual(u'fake', res['senlin_object.data']['identity'])
def test_webhook_trigger_cluster_not_found(self, mock_cluster, mock_find): receiver = mock.Mock() receiver.cluster_id = 'BOGUS' mock_find.return_value = receiver mock_cluster.side_effect = exception.ResourceNotFound(type='cluster', id='BOGUS') body = vorw.WebhookTriggerRequestBody(params=None) req = vorw.WebhookTriggerRequest(identity='RRR', body=body) ex = self.assertRaises(rpc.ExpectedException, self.eng.webhook_trigger, self.ctx, req.obj_to_primitive()) self.assertEqual(exception.BadRequest, ex.exc_info[0]) self.assertEqual("The referenced cluster 'BOGUS' could not be found.", six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'RRR') mock_cluster.assert_called_once_with(self.ctx, 'BOGUS')
def test_webhook_trigger(self): body = webhooks.WebhookTriggerRequestBody(params={'foo': 'boo'}) sot = webhooks.WebhookTriggerRequest(identity='fake', params=body) self.assertEqual('fake', sot.identity) self.assertIsInstance(sot.params, webhooks.WebhookTriggerRequestBody)
def test_webhook_trigger_body(self): sot = webhooks.WebhookTriggerRequestBody(params={'foo': 'boo'}) self.assertEqual({'foo': 'boo'}, sot.params)
def test_webhook_trigger_body_none(self): sot = webhooks.WebhookTriggerRequestBody(params=None) self.assertIsNone(sot.params)