def test_walk_no_children(self):
        cache = self._create_app_state_cache()

        self.zoo_keeper.connected = True
        self.zoo_keeper.get_children('path1',
                                     watch=mox.IgnoreArg()).AndReturn(None)

        app_state = ApplicationStateMock()
        app_state.mock_dict = {'key': 'value'}
        result = ApplicationStatesMessage()
        compare = dict()
        compare.update({
            ApplicationStateMock().configuration_path:
            app_state.to_dictionary()
        })

        self.mox.StubOutWithMock(cache, "_get_application_state")
        cache._get_application_state('path1').AndReturn(app_state)

        self.mox.ReplayAll()

        cache._walk('path1', result)
        self.assertEquals(result, compare)

        self.mox.VerifyAll()
    def test_walk_children(self):
        cache = ApplicationStateCache(self.configuration, self.zoo_keeper,
                                      self.web_socket_clients,
                                      self.time_estimate_cache)
        app_state1 = ApplicationStateMock()
        app_state1.mock_dict = {'key': 'value'}
        app_state1.configuration_path = "path1/foo"

        app_state2 = ApplicationStateMock()
        app_state2.mock_dict = {'key': 'value'}
        app_state2.configuration_path = "path1/bar"

        result = ApplicationStatesMessage()
        compare = dict()
        compare.update({'path1/bar': app_state2.to_dictionary()})
        compare.update({'path1/foo': app_state1.to_dictionary()})

        self.zoo_keeper.connected = True
        self.zoo_keeper.get_children('path1', watch=mox.IgnoreArg()).AndReturn(
            ['foo', 'bar'])
        self.zoo_keeper.get_children('path1/foo',
                                     watch=mox.IgnoreArg()).AndReturn([])
        self.zoo_keeper.get_children('path1/bar',
                                     watch=mox.IgnoreArg()).AndReturn([])

        self.mox.StubOutWithMock(cache, "_get_application_state")
        cache._get_application_state('path1/foo').AndReturn(app_state2)
        cache._get_application_state('path1/bar').AndReturn(app_state1)

        self.mox.ReplayAll()

        cache._walk('path1', result)
        self.assertEquals(result, compare)

        self.mox.VerifyAll()