コード例 #1
0
 def test_send_to_server(self, _):
     self.WS = WebsocketClientComms(self.p, params)
     self.WS.conn = MagicMock()
     request = Get(None, None, ["block", "attr"])
     request.set_id(54)
     self.WS.send_to_server(request)
     self.WS.conn.write_message.assert_called_once_with(
         '{"typeid": "malcolm:core/Get:1.0", "id": 54, "endpoint": ["block", "attr"]}')
コード例 #2
0
 def test_MWSH_on_message(self, ioloop_mock, server_mock):
     MWSH = MalcWebSocketHandler(MagicMock(), MagicMock())
     MWSH.servercomms = MagicMock()
     request = Get(None, None, ["block", "attr"])
     request.set_id(54)
     message = """{
     "typeid": "malcolm:core/Get:1.0",
     "id": 54,
     "endpoint": ["block", "attr"]
     }"""
     MWSH.on_message(message)
     self.assertEquals(MWSH.servercomms.on_request.call_count, 1)
     actual = MWSH.servercomms.on_request.call_args[0][0]
     self.assertEquals(actual.to_dict(), request.to_dict())
コード例 #3
0
class TestGet(unittest.TestCase):

    def setUp(self):
        self.context = MagicMock()
        self.response_queue = MagicMock()
        self.endpoint = ["BL18I:XSPRESS3", "state", "value"]
        self.get = Get(self.context, self.response_queue, self.endpoint)

    def test_init(self):
        self.assertEqual(self.context, self.get.context)
        self.assertEqual(self.response_queue, self.get.response_queue)
        self.assertEqual(self.endpoint, self.get.endpoint)
        self.assertEqual("malcolm:core/Get:1.0", self.get.typeid)

    def test_setters(self):
        self.get.set_endpoint(["BL18I:XSPRESS3", "state", "value2"])
        self.assertEquals(["BL18I:XSPRESS3", "state", "value2"], self.get.endpoint)
コード例 #4
0
 def send_get_request(self):
     self.log_debug("send_get_request called with request: %s", self._request)
     try:
         self._server.register_get(self._id, self)
         endpoints = [self._block] + self.dict_to_path(self._request.toDict())
         msg = Get(response_queue=self._server.q, endpoint=endpoints)
         msg.set_id(self._id)
         with self._lock:
             self._server.send_to_process(msg)
             self.wait_for_reply()
         self.log_debug("send_get_request received the following response: %s", self._response)
         # Create the reply structure
         response_dict = self._response["value"]
         for ep in reversed(endpoints[1:]):
             response_dict = {ep: response_dict}
         self.log_debug("response_dict: %s", response_dict)
         self._pv_structure = self._server.dict_to_pv_object(response_dict)
     except Exception:
         self.log_exception("Unable to complete send_get_request: %s", self._request)
     self._server.remove_get(self._id)
コード例 #5
0
 def setUp(self):
     self.context = MagicMock()
     self.response_queue = MagicMock()
     self.endpoint = ["BL18I:XSPRESS3", "state", "value"]
     self.get = Get(self.context, self.response_queue, self.endpoint)