1# Licensed under the Apache License, Version 2.0 (the "License"); you may 2# not use this file except in compliance with the License. You may obtain 3# a copy of the License at 4# 5# http://www.apache.org/licenses/LICENSE-2.0 6# 7# Unless required by applicable law or agreed to in writing, software 8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10# License for the specific language governing permissions and limitations 11# under the License. 12 13from openstack.tests.unit import base 14 15from openstack.clustering.v1 import event 16 17 18FAKE = { 19 'action': 'NODE_CREATE', 20 'cluster_id': None, 21 'id': 'ffaed25e-46f5-4089-8e20-b3b4722fd597', 22 'level': '20', 23 'oid': 'efff1c11-2ada-47da-bedd-2c9af4fd099a', 24 'oname': 'node_create_b4a49016', 25 'otype': 'NODEACTION', 26 'project': '42d9e9663331431f97b75e25136307ff', 27 'status': 'START', 28 'status_reason': 'The action was abandoned.', 29 'timestamp': '2016-10-10T12:46:36.000000', 30 'user': '5e5bf8027826429c96af157f68dc9072', 31 'meta_data': { 32 "action": { 33 "created_at": "2019-07-13T13:18:18Z", 34 "outputs": {} 35 } 36 } 37} 38 39 40class TestEvent(base.TestCase): 41 42 def setUp(self): 43 super(TestEvent, self).setUp() 44 45 def test_basic(self): 46 sot = event.Event() 47 self.assertEqual('event', sot.resource_key) 48 self.assertEqual('events', sot.resources_key) 49 self.assertEqual('/events', sot.base_path) 50 self.assertTrue(sot.allow_fetch) 51 self.assertTrue(sot.allow_list) 52 53 def test_instantiate(self): 54 sot = event.Event(**FAKE) 55 self.assertEqual(FAKE['id'], sot.id) 56 self.assertEqual(FAKE['action'], sot.action) 57 self.assertEqual(FAKE['cluster_id'], sot.cluster_id) 58 self.assertEqual(FAKE['level'], sot.level) 59 self.assertEqual(FAKE['oid'], sot.obj_id) 60 self.assertEqual(FAKE['oname'], sot.obj_name) 61 self.assertEqual(FAKE['otype'], sot.obj_type) 62 self.assertEqual(FAKE['project'], sot.project_id) 63 self.assertEqual(FAKE['status'], sot.status) 64 self.assertEqual(FAKE['status_reason'], sot.status_reason) 65 self.assertEqual(FAKE['timestamp'], sot.generated_at) 66 self.assertEqual(FAKE['user'], sot.user_id) 67 self.assertEqual(FAKE['meta_data'], sot.meta_data) 68