Handle multiple samples per versioned notification

The notification_sample decorator is changed to handle
attaching multiple sample files to a notification object.

Change-Id: I4c3df17d93282f6946221da65d26d0ca3194d3df
This commit is contained in:
Balazs Gibizer 2016-05-26 16:52:04 +02:00
parent 6329d721ef
commit 8279b1ea2e
3 changed files with 15 additions and 4 deletions

View File

@ -51,9 +51,10 @@ class VersionedNotificationDirective(Directive):
payload_name = cls.fields['payload'].objname payload_name = cls.fields['payload'].objname
payload_cls = ovos[payload_name][0] payload_cls = ovos[payload_name][0]
for sample in cls.samples:
notifications.append((full_name(cls), full_name(payload_cls), notifications.append((full_name(cls),
cls.sample)) full_name(payload_cls),
sample))
return notifications return notifications
def _build_markup(self, notifications): def _build_markup(self, notifications):

View File

@ -149,6 +149,9 @@ def notification_sample(sample):
root. root.
""" """
def wrap(cls): def wrap(cls):
cls.sample = sample if not getattr(cls, 'samples', None):
cls.samples = [sample]
else:
cls.samples.append(sample)
return cls return cls
return wrap return wrap

View File

@ -64,6 +64,8 @@ class TestNotificationBase(test.NoDBTestCase):
'extra_field': fields.StringField(), # filled by ctor 'extra_field': fields.StringField(), # filled by ctor
} }
@notification.notification_sample('test-update-1.json')
@notification.notification_sample('test-update-2.json')
@base.NovaObjectRegistry.register_if(False) @base.NovaObjectRegistry.register_if(False)
class TestNotification(notification.NotificationBase): class TestNotification(notification.NotificationBase):
VERSION = '1.0' VERSION = '1.0'
@ -246,6 +248,11 @@ class TestNotificationBase(test.NoDBTestCase):
'nova_object.version': '1.0', 'nova_object.version': '1.0',
'nova_object.namespace': 'nova'}) 'nova_object.namespace': 'nova'})
def test_sample_decorator(self):
self.assertEqual(2, len(self.TestNotification.samples))
self.assertIn('test-update-1.json', self.TestNotification.samples)
self.assertIn('test-update-2.json', self.TestNotification.samples)
notification_object_data = { notification_object_data = {
'EventType': '1.1-8291570eed00192197c7fa02ac677cd4', 'EventType': '1.1-8291570eed00192197c7fa02ac677cd4',