コード例 #1
0
    def test_view_product_message(self):
        product_content = Mock()
        client_handlers = 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.on_new_message = Mock()
        target.on_next_page_message = Mock()
        target.on_view_product_details_message = Mock()

        target.on_message(
            "handler_value",
            {
                "type": "view_product_details"
            }
        )

        self.assertEqual(0, target.on_new_message.call_count)
        self.assertEqual(0, target.on_next_page_message.call_count)

        self.assertEqual(1, target.on_view_product_details_message.call_count)
        self.assertEqual("handler_value", target.on_view_product_details_message.call_args_list[0][0][0])
        self.assertDictEqual(
            {
                "type": "view_product_details"
            },
            target.on_view_product_details_message.call_args_list[0][0][1]
        )
コード例 #2
0
    def test_view_product_message(self):
        product_content = Mock()
        client_handlers = 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.on_new_message = Mock()
        target.on_next_page_message = Mock()
        target.on_view_product_details_message = Mock()

        target.on_message("handler_value", {"type": "view_product_details"})

        self.assertEqual(0, target.on_new_message.call_count)
        self.assertEqual(0, target.on_next_page_message.call_count)

        self.assertEqual(1, target.on_view_product_details_message.call_count)
        self.assertEqual(
            "handler_value",
            target.on_view_product_details_message.call_args_list[0][0][0])
        self.assertDictEqual(
            {"type": "view_product_details"},
            target.on_view_product_details_message.call_args_list[0][0][1])
コード例 #3
0
ファイル: websocket.py プロジェクト: rdefeo/api
class WebSocket(WebSocketHandler):
    _param_extractor = None
    _cookie_extractor = None
    _logic = None
    user_id = None
    id = None
    application_id = None
    session_id = None

    context_id = None
    context_rev = None
    context = None

    suggest_id = None
    offset = None
    page_size = None

    def initialize(self, product_content, client_handlers, user_info_cache, favorites_cache):
        from api.logic.websocket import WebSocket as WebSocketLogic

        self._logic = WebSocketLogic(
            product_content=product_content,
            client_handlers=client_handlers,
            user_info_cache=user_info_cache,
            favorites_cache=favorites_cache,
        )
        self._param_extractor = ParamExtractor(self)
        self._cookie_extractor = WebSocketCookieExtractor(self)

    def check_origin(self, origin):
        return True

    def open(self):
        self.id = uuid4()
        self.user_id = self._cookie_extractor.user_id()
        self.application_id = self._cookie_extractor.application_id()
        self.session_id = self._cookie_extractor.session_id()
        self.context_id = self._param_extractor.context_id()
        self.suggest_id = self._param_extractor.suggest_id()
        self.locale = self._param_extractor.locale()
        self.page_size = 20

        self._logic.open(self)

    def on_message(self, message):
        self._logic.on_message(self, json_decode(message))
        if self.user_id is None:  # maybe they logged in
            self.user_id = self._cookie_extractor.user_id()

    def on_close(self):
        self._logic.on_close(self)
コード例 #4
0
class WebSocket(WebSocketHandler):
    _param_extractor = None
    _cookie_extractor = None
    _logic = None
    user_id = None
    id = None
    application_id = None
    session_id = None

    context_id = None
    context_rev = None
    context = None

    suggest_id = None
    offset = None
    page_size = None

    def initialize(self, product_content, client_handlers, user_info_cache,
                   favorites_cache):
        from api.logic.websocket import WebSocket as WebSocketLogic
        self._logic = WebSocketLogic(product_content=product_content,
                                     client_handlers=client_handlers,
                                     user_info_cache=user_info_cache,
                                     favorites_cache=favorites_cache)
        self._param_extractor = ParamExtractor(self)
        self._cookie_extractor = WebSocketCookieExtractor(self)

    def check_origin(self, origin):
        return True

    def open(self):
        self.id = uuid4()
        self.user_id = self._cookie_extractor.user_id()
        self.application_id = self._cookie_extractor.application_id()
        self.session_id = self._cookie_extractor.session_id()
        self.context_id = self._param_extractor.context_id()
        self.suggest_id = self._param_extractor.suggest_id()
        self.locale = self._param_extractor.locale()
        self.page_size = 20

        self._logic.open(self)

    def on_message(self, message):
        self._logic.on_message(self, json_decode(message))
        if self.user_id is None:  # maybe they logged in
            self.user_id = self._cookie_extractor.user_id()

    def on_close(self):
        self._logic.on_close(self)
コード例 #5
0
    def test_new_message(self):
        product_content = Mock()
        client_handlers = 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.new_message_handler = MagicMock()
        target.on_next_page_message = Mock()
        target.on_view_product_details_message = Mock()

        target.on_message("handler_value", {"type": "new_message"})

        target.new_message_handler.on_new_message.assert_called_once_with(
            'handler_value', {'type': 'new_message'}, new_conversation=False)

        self.assertEqual(0, target.on_next_page_message.call_count)
        self.assertEqual(0, target.on_view_product_details_message.call_count)
コード例 #6
0
    def test_home_page_message(self):
        product_content = Mock()
        client_handlers = 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.new_message_handler = MagicMock()
        target.on_next_page_message = Mock()
        target.on_view_product_details_message = Mock()

        target.on_message(
            "handler_value",
            {
                "type": "home_page_message"
            }
        )

        target.new_message_handler.on_new_message.assert_called_once_with('handler_value', {'type': 'home_page_message'}, new_conversation=True)

        self.assertEqual(0, target.on_next_page_message.call_count)
        self.assertEqual(0, target.on_view_product_details_message.call_count)