

def test_update_metadata(self):
    self.mox.StubOutWithMock(db, 'aggregate_metadata_delete')
    self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
    db.aggregate_metadata_delete(self.context, 123, 'todelete')
    db.aggregate_metadata_add(self.context, 123, {
        'toadd': 'myval',
    })
    self.mox.ReplayAll()
    fake_notifier.NOTIFICATIONS = []
    agg = aggregate.Aggregate()
    agg._context = self.context
    agg.id = 123
    agg.metadata = {
        'foo': 'bar',
    }
    agg.obj_reset_changes()
    agg.update_metadata({
        'todelete': None,
        'toadd': 'myval',
    })
    self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
    msg = fake_notifier.NOTIFICATIONS[0]
    self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
    self.assertEqual({
        'todelete': None,
        'toadd': 'myval',
    }, msg.payload['meta_data'])
    msg = fake_notifier.NOTIFICATIONS[1]
    self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
    self.assertEqual({
        'todelete': None,
        'toadd': 'myval',
    }, msg.payload['meta_data'])
    self.assertEqual({
        'foo': 'bar',
        'toadd': 'myval',
    }, agg.metadata)

dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/unit/objects/test_aggregate.py _TestAggregateObject.test_update_metadata/original