test_coordinator.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:charm-helpers 作者: juju 项目源码 文件源码
def test_load_state(self, leader_get):
        c = coordinator.BaseCoordinator()
        unit = hookenv.local_unit()

        # c.granted is just the leader_get decoded.
        leader_get.return_value = '{"json": true}'
        c._load_state()
        self.assertDictEqual(c.grants, {'json': True})

        # With no relid, there is no peer relation so request state
        # is pulled from a local stash.
        with patch.object(c, '_load_local_state') as loc_state:
            loc_state.return_value = {'local': True}
            c._load_state()
            self.assertDictEqual(c.requests, {unit: {'local': True}})

        # With a relid, request details are pulled from the peer relation.
        # If there is no data in the peer relation from the local unit,
        # we still pull it from the local stash as it means this is the
        # first time we have joined.
        c.relid = 'cluster:1'
        with patch.object(c, '_load_local_state') as loc_state, \
                patch.object(c, '_load_peer_state') as peer_state:
            loc_state.return_value = {'local': True}
            peer_state.return_value = {'foo/2': {'mylock': 'whatever'}}
            c._load_state()
            self.assertDictEqual(c.requests, {unit: {'local': True},
                                              'foo/2': {'mylock': 'whatever'}})

        # If there are local details in the peer relation, the local
        # stash is ignored.
        with patch.object(c, '_load_local_state') as loc_state, \
                patch.object(c, '_load_peer_state') as peer_state:
            loc_state.return_value = {'local': True}
            peer_state.return_value = {unit: {},
                                       'foo/2': {'mylock': 'whatever'}}
            c._load_state()
            self.assertDictEqual(c.requests, {unit: {},
                                              'foo/2': {'mylock': 'whatever'}})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号