def test_decode(self): msg = MBMessage() msg.encode(self.msg_id, self.action, self.target, self.payload, self.context) json = msg.to_json() msg.decode(json) self.assertEqual(json, msg.to_json())
def test__on_recv(self): client = ZmqObject(['tcp://localhost:5555'], zmq.REQ) msg = MBMessage('foo', 'action_bar', None, { 'first_arg': 2, 'second_arg': 3 }, {'multiplier': 6}) zmq_msg = msg.to_json() worker = self.worker worker_thread = threading.Thread(target=worker.start) worker_thread.start() time.sleep(2) client.zmq_connect() client.zmq_send(zmq_msg) result = worker.decode_msg(client.zmq_recv()) client.socket.close() self.assertEqual(result.payload, 30)
def post(self): post_data = json.loads(self.request.body) email = post_data.get('email') username = post_data.get('username') password = post_data.get('password') api_msg = MBMessage(None, 'authenticate', {'username': email or username}, {'password': password}, self.context()) resp = yield self.dispatch(api_msg) resp_msg = MBMessage(resp.msg_id, resp.action, api_msg.target, resp.payload, resp.context, merge_target=False) self.mb_cookies(resp) self.set_header('Content-Type', 'application/json') self.write(resp_msg.to_json()) self.finish()
def test_init_decode(self): msg = MBMessage( self.msg_id, self.action, self.target, self.payload, self.context) result = msg.to_json() excepted = json.dumps([msg.msg_id, msg.action, self.target, msg.payload, {}, msg.timestamp,]) dec_msg = MBMessage(result) self.assertEqual(result, dec_msg.to_json())
def _unmarshal(raw_response): resp = GoHandler.hyperdrive_decode(go_handlers, raw_response) if not resp: logging.info("GO ERROR") return None resp_msg = MBMessage(resp.msg_id, resp.action, resp.target, resp.payload, resp.context, merge_target=False) self.mb_cookies(resp) return resp_msg.to_json()
def _unmarshal(raw_response): resp = GoHandler.hyperdrive_decode(go_handlers, raw_response) if not resp: logging.info("GO ERROR") return None resp_msg = MBMessage(resp.msg_id, resp.action, resp.target, resp.payload, resp.context, merge_target=False) self.mb_cookies(resp) return resp_msg.to_json()
def post(self): api_msg = self.decode_api_msg(self.request.body) go = GoHandler.can_handle(self, api_msg) if go: resp = yield go.dispatch() resp_msg = go.make_response(resp) else: resp = yield self.dispatch(api_msg) resp_msg = MBMessage(resp.msg_id, resp.action, api_msg.target, resp.payload, resp.context, merge_target=False) self.mb_cookies(resp) self.set_header('Content-Type', 'application/json') self.write(resp_msg.to_json()) self.finish()
def post(self): api_msg = self.decode_api_msg(self.request.body) go = GoHandler.can_handle(self, api_msg) if go: resp = yield go.dispatch() resp_msg = go.make_response(resp) else: resp = yield self.dispatch(api_msg) resp_msg = MBMessage(resp.msg_id, resp.action, api_msg.target, resp.payload, resp.context, merge_target=False) self.mb_cookies(resp) self.set_header('Content-Type', 'application/json') self.write(resp_msg.to_json()) self.finish()
def test__on_recv(self): client = ZmqObject(['tcp://localhost:5555'], zmq.REQ) msg = MBMessage('foo', 'action_bar', None, {'first_arg': 2, 'second_arg': 3}, {'multiplier': 6}) zmq_msg = msg.to_json() worker = self.worker worker_thread = threading.Thread(target=worker.start) worker_thread.start() time.sleep(2) client.zmq_connect() client.zmq_send(zmq_msg) result = worker.decode_msg(client.zmq_recv()) client.socket.close() self.assertEqual(result.payload, 30)