示例#1
0
    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)
示例#2
0
    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),
                    ))
示例#3
0
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__)
示例#4
0
    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),
                    ))
示例#5
0
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)
示例#6
0
    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()
示例#7
0
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()
示例#8
0
    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()
示例#9
0
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)
示例#10
0
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")
示例#11
0
 def test_send(self):
     pubsub.Publisher(port='tcp://*:48640').send(
         message=messages.JSON(data='test')
     )
示例#12
0
    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)