def process_request(self, request): method, params, error = self.parse_jrpc(request) if not error: response_data = getattr(self, method)(**params) else: response_data = error return messages.JSON(data=response_data)
def run(self): with log_exceptions(): while True: input_event = self.driver.stick.wait_for_event( emptybuffer=True) self.publisher.send( messages.JSON( topic=self.topics['joystick'], data=self.format_event(input_event), ))
def test_parse(): msgs = ( messages.Message(data='test'), messages.Base64(data='test'), messages.JSON(data='test'), messages.FilePath(data='test'), messages.Pickle(data='test'), ) for message in msgs: assert isinstance(messages.parse(message.serialize()), message.__class__)
def run(self): with log_exceptions(): sleep_time = settings.ENVIRONMENTAL_SENSORS_INTERVAL while True: if sleep_time: time.sleep(sleep_time) for topic in self.topics: self.publisher.send(messages.JSON( topic=self.topics[topic], data=getattr(self, topic), ))
class TestJsonrpcServerResource(object): request = messages.JSON(data={'method': 'test', 'params': True}) resource = services.JsonrpcServerResource(server=services.JsonrpcServer( address='tcp://localhost:48662', port='tcp://*:48662', endpoints={'test': lambda x: True if x is True else False})) resource.test = lambda x: True if x is True else False def test_parse_jrpc(self): self.resource.parse_jrpc(request=self.request) def test_process_request(self): self.resource.process_request(request=self.request)
def test_receive(self): with mock_zmq() as zmq_mock: topics = ('test', ) publisher_address = 'tcp://localhost:48641' subscriber = pubsub.Subscriber( publishers=(publisher_address, ), topics=topics ) message = messages.JSON(topic=topics[0], data='test') zmq_mock.recv.return_value = message.serialize() subscriber.receive()
class TestServer(object): message = messages.JSON(data='test') port = 'tcp://*:{}' def test_respond(self): with mock_zmq(): clientserver.Server(port=self.port.format(48650)).respond( self.message) def test_receive(self): with mock_zmq() as zmq_mock: zmq_mock.recv.return_value = self.message.serialize() clientserver.Server(port=self.port.format(48651)).receive()
def test_receive(self): with mock_zmq() as zmq_mock: topics = ('test', ) publisher_to_forward_address = 'tcp://localhost:48642' forwarder = pubsub.Publisher(port='tcp://*:48643') subscriber = pubsub.MessageForwarder( publisher=forwarder, publishers=(publisher_to_forward_address, ), topics=topics ) message = messages.JSON(topic=topics[0], data='test') zmq_mock.recv.return_value = message.serialize() subscriber.receive()
class TestClient(object): message = messages.JSON(data='test') servers = ('tcp://localhost:48640', ) def test_connect(self): clientserver.Client(servers=self.servers).connect(self.servers[0]) def test_process_response(self): clientserver.Client(servers=self.servers).process_response( self.message.serialize()) def test_request(self): with mock_zmq() as zmq_mock: message = messages.JSON(data='test') zmq_mock.recv.return_value = message.serialize() clientserver.Client(servers=self.servers).request(self.message)
def run(): logger.info("Starting...") if settings.ENVIRONMENTAL_SERVICE_ENABLED: environmental.Service().start() if settings.INERTIAL_SERVICE_ENABLED: inertial.Service().start() if settings.JOYSTICK_SERVICE_ENABLED: joystick.Service().start() if settings.LED_MATRIX_SERVICE_ENABLED: led_matrix_service = led_matrix.Service() led_matrix_service.start() led_matrix_service.get_client().request(message=messages.JSON( data={'method': 'clear'})) logger.info("Done")
def test_send(self): pubsub.Publisher(port='tcp://*:48640').send( message=messages.JSON(data='test') )
def test_request(self): with mock_zmq() as zmq_mock: message = messages.JSON(data='test') zmq_mock.recv.return_value = message.serialize() clientserver.Client(servers=self.servers).request(self.message)