def test_update_subscriber_redisSubscriber_Not_None(self):
        self.target._MessageDispatcher__sourceDispatcherId = "DispatcherId"
        subscription_map =\
            self.target._MessageDispatcher__subscription_map
        subscription_map._EventSubscriptionMap__subscriptions =\
            {"remote_object": set(["key01:value01",
                                   "key01:value02"]),
             "local_object": set(["key01:value01",
                                  "key01:value02"])}
        subscription_map._EventSubscriptionMap__subscription_map =\
            {"key01:value01": set(["remote_object",
                                   "local_object"]),
             "key01:value02": set(["remote_object",
                                   "local_object"])}
        remote_object = RemoteObject("remote_object", self.target)
        self.target._MessageDispatcher__local_objects =\
            {"remote_object": remote_object}
        self.target._MessageDispatcher__redisSubscriber = redis.StrictRedis(
            host=self.target._MessageDispatcher__redisServer,
            port=self.target._MessageDispatcher__redisPort)
        self.target._MessageDispatcher__redisSubscriber =\
            self.target._MessageDispatcher__redisSubscriber.pubsub()

        with patch("redis.client.PubSub.subscribe") as mock_subscribe:
            self.target._MessageDispatcher__update_subscriber()

            mock_subscribe.assert_called_once_with([
                "DispatcherId", "remote_object", "key01:value01",
                "key01:value02"
            ])
    def test_dispatch_request_object_id_not_in_local_objects(self):
        request = Request("NoneID", "method", "path")
        remote_object = RemoteObject("remote_object", self.target)
        self.target._MessageDispatcher__local_objects =\
            {"remote_object": remote_object}

        self.result = self.target.dispatch_request(request)

        self.assertEqual(self.result.status_code, 404)
        self.assertEqual(self.result.body, None)
    def test_dispatch_request_object_id_in_local_objects(self):
        request = Request("remote_object", "method", "path")
        remote_object = RemoteObject("remote_object", self.target)
        self.target._MessageDispatcher__local_objects =\
            {"remote_object": remote_object}

        with patch("org.o3project.odenos.remoteobject." +
                   "remote_object.RemoteObject." +
                   "dispatch_request") as mock_dispatch_request:
            mock_dispatch_request.return_value = "mock_dispatch_request"

            self.result = self.target.dispatch_request(request)

        self.assertEqual(self.result, "mock_dispatch_request")
    def test_dispatch_event(self):
        event = Event("key01", "value01", "event_body")
        subscription_map =\
            self.target._MessageDispatcher__subscription_map
        subscription_map._EventSubscriptionMap__subscriptions =\
            {"remote_object": set(["key01:value01",
                                   "key01:value02"]),
             "local_object": set(["key01:value01",
                                  "key01:value02"])}
        subscription_map._EventSubscriptionMap__subscription_map =\
            {"key01:value01": set(["remote_object",
                                   "local_object"]),
             "key01:value02": set(["remote_object",
                                   "local_object"])}
        remote_object = RemoteObject("remote_object", self.target)
        self.target._MessageDispatcher__local_objects =\
            {"remote_object": remote_object}

        with patch("org.o3project.odenos.remoteobject." +
                   "remote_object.RemoteObject." +
                   "dispatch_event") as mock_dispatch_event:
            self.target.dispatch_event(event)

        mock_dispatch_event.assert_called_once_with(event)