def setUp(self): '''url: http://tacker:9890/v1.0/vnfs/vnf-uuid/mon-policy-name/ action-name/8ef785 ''' super(TestAlarmReceiver, self).setUp() self.alarmrc = AlarmReceiver(None) self.alarm_url = { '00_base': 'http://tacker:9890/v1.0', '01_url_base': '/vnfs/vnf-uuid/', '02_vnf_id': 'vnf-uuid', '03_monitoring_policy_name': 'mon-policy-name', '04_action_name': 'action-name', '05_key': '8ef785' } self.vnf_id = 'vnf-uuid' self.ordered_url = self._generate_alarm_url()
class TestAlarmReceiver(base.TestCase): def setUp(self): '''url: http://tacker:9890/v1.0/vnfs/vnf-uuid/mon-policy-name/ action-name/8ef785 ''' super(TestAlarmReceiver, self).setUp() self.alarmrc = AlarmReceiver(None) self.alarm_url = { '00_base': 'http://*****:*****@mock.patch('tacker.vnfm.monitor_drivers.token.Token.create_token') def test_process_request(self, mock_token): req = Request.blank(self.ordered_url) req.method = 'POST' self.alarmrc.process_request(req) self.assertIsNotNone(req.body) self.assertIn('triggers', req.environ['PATH_INFO'])
class TestAlarmReceiver(base.TestCase): def setUp(self): '''url: http://tacker:9890/v1.0/vnfs/vnf-uuid/mon-policy-name/ action-name/8ef785 ''' super(TestAlarmReceiver, self).setUp() self.alarmrc = AlarmReceiver(None) self.alarm_url = { '00_base': 'http://*****:*****@mock.patch('tacker.vnfm.monitor_drivers.token.Token.create_token') def test_process_request(self, mock_create_token): mock_create_token.return_value = 'fake_token' req = Request.blank(self.ordered_url) req.method = 'POST' self.alarmrc.process_request(req) self.assertEqual(helpers.compact_byte(''), req.body) self.assertEqual('fake_token', req.headers['X_AUTH_TOKEN']) self.assertIn(self.alarm_url['01_url_base'], req.environ['PATH_INFO']) self.assertIn('triggers', req.environ['PATH_INFO']) self.assertEqual('', req.environ['QUERY_STRING']) mock_create_token.assert_called_once_with() @mock.patch('tacker.vnfm.monitor_drivers.token.Token.create_token') def test_process_request_with_body(self, mock_create_token): req = Request.blank(self.ordered_url) req.method = 'POST' old_body = {'fake_key': 'fake_value'} req.body = jsonutils.dump_as_bytes(old_body) self.alarmrc.process_request(req) body_dict = jsonutils.loads(req.body) self.assertDictEqual(old_body, body_dict['trigger']['params']['data']) self.assertEqual(self.alarm_url['05_key'], body_dict['trigger']['params']['credential']) self.assertEqual(self.alarm_url['03_monitoring_policy_name'], body_dict['trigger']['policy_name']) self.assertEqual(self.alarm_url['04_action_name'], body_dict['trigger']['action_name'])
class TestAlarmReceiver(base.TestCase): def setUp(self): '''url: http://tacker:9890/v1.0/vnfs/vnf-uuid/mon-policy-name/ action-name/8ef785 ''' super(TestAlarmReceiver, self).setUp() self.alarmrc = AlarmReceiver(None) self.alarm_url = { '00_base': 'http://*****:*****@mock.patch('tacker.vnfm.monitor_drivers.token.Token.create_token') def test_process_request(self, mock_create_token): mock_create_token.return_value = 'fake_token' req = Request.blank(self.ordered_url) req.method = 'POST' self.alarmrc.process_request(req) self.assertEqual('', req.body) self.assertEqual('fake_token', req.headers['X_AUTH_TOKEN']) self.assertIn(self.alarm_url['01_url_base'], req.environ['PATH_INFO']) self.assertIn('triggers', req.environ['PATH_INFO']) self.assertEqual('', req.environ['QUERY_STRING']) mock_create_token.assert_called_once_with() @mock.patch('tacker.vnfm.monitor_drivers.token.Token.create_token') def test_process_request_with_body(self, mock_create_token): req = Request.blank(self.ordered_url) req.method = 'POST' old_body = {'fake_key': 'fake_value'} req.body = jsonutils.dump_as_bytes(old_body) self.alarmrc.process_request(req) body_dict = jsonutils.loads(req.body) self.assertDictEqual(old_body, body_dict['trigger']['params']['data']) self.assertEqual(self.alarm_url['05_key'], body_dict['trigger']['params']['credential']) self.assertEqual(self.alarm_url['03_monitoring_policy_name'], body_dict['trigger']['policy_name']) self.assertEqual(self.alarm_url['04_action_name'], body_dict['trigger']['action_name'])