cleanup and tests

This commit is contained in:
Edward Hope-Morley
2014-12-12 18:47:36 +00:00
parent e634cc7d2a
commit 2a2e0a102c
2 changed files with 21 additions and 7 deletions

View File

@@ -882,14 +882,15 @@ def send_identity_notifications(notifications, use_trigger=False):
# Set all to None
_notifications = {k: None for k in set(keys)}
# Set new values
for k, v in notifications.iteritems():
_notifications[k] = v
if use_trigger:
# Set new values
_notifications['trigger'] = str(uuid.uuid4())
# Broadcast
log("Sending notifications", level=DEBUG)
log("Sending identity-service notifications (trigger=%s)" % (use_trigger),
level=DEBUG)
for rid in rel_ids:
relation_set(relation_id=rid, relation_settings=_notifications)

View File

@@ -291,14 +291,17 @@ class TestKeystoneUtils(CharmTestCase):
publicurl=publicurl, adminurl=adminurl,
internalurl=internalurl)
@patch.object(utils, 'uuid')
@patch.object(utils, 'relation_set')
@patch.object(utils, 'relation_get')
@patch.object(utils, 'relation_ids')
@patch.object(utils, 'is_elected_leader')
def testsend_identity_notifications(self, mock_is_elected_leader,
mock_relation_ids, mock_relation_get,
mock_relation_set):
mock_relation_ids.side_effect = ['testrel:0']
def test_send_identity_notifications(self, mock_is_elected_leader,
mock_relation_ids, mock_relation_get,
mock_relation_set, mock_uuid):
mock_uuid.uuid4.return_value = '1234'
rid = 'testrel:0'
mock_relation_ids.return_value = [rid]
mock_is_elected_leader.return_value = False
utils.send_identity_notifications({'foo-endpoint-changed': 1})
self.assertFalse(mock_relation_set.called)
@@ -307,5 +310,15 @@ class TestKeystoneUtils(CharmTestCase):
utils.send_identity_notifications({})
self.assertFalse(mock_relation_set.called)
utils.send_identity_notifications({'foo-endpoint-changed': 1})
settings = {'foo-endpoint-changed': 1}
utils.send_identity_notifications(settings)
self.assertTrue(mock_relation_set.called)
mock_relation_set.assert_called_once_with(relation_id=rid,
relation_settings=settings)
mock_relation_set.reset_mock()
settings = {'foo-endpoint-changed': 1}
utils.send_identity_notifications(settings, use_trigger=True)
self.assertTrue(mock_relation_set.called)
settings['trigger'] = '1234'
mock_relation_set.assert_called_once_with(relation_id=rid,
relation_settings=settings)