Ejemplo n.º 1
0
    def test_existing_id(self):
        client_handlers = {
            "existing_id": "existing_handler"
        }
        product_content = Mock()
        user_info_cache = Mock()
        favorites_cache = Mock()
        target = Target(product_content=product_content, client_handlers=client_handlers, user_info_cache=user_info_cache, favorites_cache=favorites_cache)


        target.get_context = Mock(
            return_value="get_context_value"
        )
        target.post_context = Mock()
        handler = Mock(name="new_client_handler")
        handler.id = "existing_id"
        handler.context_id = "context_id"
        handler._context = None

        target.open(handler)

        self.assertTrue("existing_id" in client_handlers)
        self.assertEqual("existing_handler", client_handlers["existing_id"])
        self.assertEqual("context_id", handler.context_id)
        self.assertIsNone(handler._context)

        self.assertEqual(0, target.post_context.call_count)

        self.assertEqual(1, handler.write_message.call_count)
        self.assertDictEqual(
            {'context_id': 'context_id', 'type': 'connection_opened'}, handler.write_message.call_args_list[0][0][0]
        )
Ejemplo n.º 2
0
    def test_existing_id(self):
        client_handlers = {"existing_id": "existing_handler"}
        product_content = Mock()
        user_info_cache = Mock()
        favorites_cache = Mock()
        target = Target(product_content=product_content,
                        client_handlers=client_handlers,
                        user_info_cache=user_info_cache,
                        favorites_cache=favorites_cache)

        target.get_context = Mock(return_value="get_context_value")
        target.post_context = Mock()
        handler = Mock(name="new_client_handler")
        handler.id = "existing_id"
        handler.context_id = "context_id"
        handler._context = None

        target.open(handler)

        self.assertTrue("existing_id" in client_handlers)
        self.assertEqual("existing_handler", client_handlers["existing_id"])
        self.assertEqual("context_id", handler.context_id)
        self.assertIsNone(handler._context)

        self.assertEqual(0, target.post_context.call_count)

        self.assertEqual(1, handler.write_message.call_count)
        self.assertDictEqual(
            {
                'context_id': 'context_id',
                'type': 'connection_opened'
            }, handler.write_message.call_args_list[0][0][0])
Ejemplo n.º 3
0
    def test_context_id_None(self):
        product_content = Mock()
        client_handlers = {}
        user_info_cache = Mock()
        favorites_cache = Mock()
        target = Target(product_content=product_content,
                        client_handlers=client_handlers,
                        user_info_cache=user_info_cache,
                        favorites_cache=favorites_cache)

        target.get_context = Mock()
        target.post_context = Mock(return_value=("context_id_value",
                                                 "context_rev_value"))
        handler = Mock()
        handler.context_id = None
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"

        target.open(handler)

        self.assertEqual(0, target.get_context.call_count)
        self.assertEqual(1, target.post_context.call_count)

        self.assertEqual("user_id_value",
                         target.post_context.call_args_list[0][0][0])
        self.assertEqual("application_id_value",
                         target.post_context.call_args_list[0][0][1])
        self.assertEqual("session_id_value",
                         target.post_context.call_args_list[0][0][2])
        self.assertEqual("locale_value",
                         target.post_context.call_args_list[0][0][3])

        self.assertEqual("context_id_value", handler.context_id)
        self.assertEqual("context_rev_value", handler.context_rev)

        self.assertEqual(1, handler.write_message.call_count)
        self.assertDictEqual(
            {
                'context_id': 'context_id_value',
                'type': 'connection_opened'
            }, handler.write_message.call_args_list[0][0][0])
Ejemplo n.º 4
0
    def test_context_id_None(self):
        product_content = Mock()
        client_handlers = {}
        user_info_cache = Mock()
        favorites_cache = Mock()
        target = Target(product_content=product_content, client_handlers=client_handlers, user_info_cache=user_info_cache, favorites_cache=favorites_cache)

        target.get_context = Mock()
        target.post_context = Mock(
            return_value=("context_id_value", "context_rev_value")
        )
        handler = Mock()
        handler.context_id = None
        handler.user_id = "user_id_value"
        handler.application_id = "application_id_value"
        handler.session_id = "session_id_value"
        handler.locale = "locale_value"

        target.open(handler)

        self.assertEqual(0, target.get_context.call_count)
        self.assertEqual(1, target.post_context.call_count)

        self.assertEqual("user_id_value", target.post_context.call_args_list[0][0][0])
        self.assertEqual("application_id_value", target.post_context.call_args_list[0][0][1])
        self.assertEqual("session_id_value", target.post_context.call_args_list[0][0][2])
        self.assertEqual("locale_value", target.post_context.call_args_list[0][0][3])

        self.assertEqual("context_id_value", handler.context_id)
        self.assertEqual("context_rev_value", handler.context_rev)

        self.assertEqual(1, handler.write_message.call_count)
        self.assertDictEqual(
            {'context_id': 'context_id_value', 'type': 'connection_opened'},
            handler.write_message.call_args_list[0][0][0]
        )