Use properties correctly
Its not possible to call a method which is annotated as a property so which to just using the property directly. Its also difficult to patch a property during unit testing so provide private methods for unit testing to allow properties to be specified during testing. Change-Id: Id9db6578e00fa412e4cf58e75bd89970b6e8e682
This commit is contained in:
parent
22600e77f1
commit
f86d2614b4
|
@ -39,8 +39,8 @@ class CephClientRequires(base_requires.CephRequires):
|
|||
|
||||
def initial_ceph_response(self):
|
||||
data = {
|
||||
'key': self.key(),
|
||||
'auth': self.auth(),
|
||||
'key': self.key,
|
||||
'auth': self.auth,
|
||||
'mon_hosts': self.mon_hosts()
|
||||
}
|
||||
return data
|
||||
|
|
|
@ -46,6 +46,9 @@ class CephClient(base_requires.CephRequires):
|
|||
|
||||
@property
|
||||
def fsid(self):
|
||||
return self._fsid()
|
||||
|
||||
def _fsid(self):
|
||||
return self.all_joined_units.received.get('fsid')
|
||||
|
||||
def mds_key(self):
|
||||
|
@ -56,8 +59,8 @@ class CephClient(base_requires.CephRequires):
|
|||
def initial_ceph_response(self):
|
||||
data = {
|
||||
'mds_key': self.mds_key(),
|
||||
'fsid': self.fsid(),
|
||||
'auth': self.auth(),
|
||||
'fsid': self.fsid,
|
||||
'auth': self.auth,
|
||||
'mon_hosts': self.mon_hosts()
|
||||
}
|
||||
return data
|
||||
|
|
|
@ -33,10 +33,16 @@ class CephRequires(reactive.Endpoint):
|
|||
|
||||
@property
|
||||
def key(self):
|
||||
return self._key()
|
||||
|
||||
def _key(self):
|
||||
return self.all_joined_units.received.get('key')
|
||||
|
||||
@property
|
||||
def auth(self):
|
||||
return self._auth()
|
||||
|
||||
def _auth(self):
|
||||
return self.all_joined_units.received.get('auth')
|
||||
|
||||
@property
|
||||
|
|
|
@ -149,22 +149,22 @@ class TestCephClientRequires(unittest.TestCase):
|
|||
self.assertEqual(hook_patterns[k], v['args'])
|
||||
|
||||
def test_data_changed(self):
|
||||
self.patch_kr('key', 'key1')
|
||||
self.patch_kr('auth', 'auth1')
|
||||
self.patch_kr('_key', 'key1')
|
||||
self.patch_kr('_auth', 'auth1')
|
||||
self.patch_kr('mon_hosts', 'host1')
|
||||
self.cr.changed()
|
||||
self.set_flag.assert_called_once_with('some-relation.available')
|
||||
|
||||
def test_data_changed_incomplete(self):
|
||||
self.patch_kr('key', 'key1')
|
||||
self.patch_kr('auth', None)
|
||||
self.patch_kr('_key', 'key1')
|
||||
self.patch_kr('_auth', None)
|
||||
self.patch_kr('mon_hosts', 'host1')
|
||||
self.cr.changed()
|
||||
self.assertFalse(self.set_flag.called)
|
||||
|
||||
def test_data_changed_existing_broker_rq(self):
|
||||
self.patch_kr('key', 'key1')
|
||||
self.patch_kr('auth', 'auth1')
|
||||
self.patch_kr('_key', 'key1')
|
||||
self.patch_kr('_auth', 'auth1')
|
||||
self.patch_kr('mon_hosts', 'host1')
|
||||
self.patch_kr('get_current_request', DummyRequest())
|
||||
self.is_request_complete.return_value = True
|
||||
|
@ -174,8 +174,8 @@ class TestCephClientRequires(unittest.TestCase):
|
|||
mock.call('some-relation.pools.available')])
|
||||
|
||||
def test_date_changed_existing_broker_rq_incomplete(self):
|
||||
self.patch_kr('key', 'key1')
|
||||
self.patch_kr('auth', 'auth1')
|
||||
self.patch_kr('_key', 'key1')
|
||||
self.patch_kr('_auth', 'auth1')
|
||||
self.patch_kr('mon_hosts', 'host1')
|
||||
self.is_request_complete.return_value = False
|
||||
self.cr.changed()
|
||||
|
|
Loading…
Reference in New Issue