def test_write_command_escaped(self):
        # Given
        envelope = _CommandMessage('dead/parrot', 'spam/ham')
        expected = '@command(node:"dead/parrot",lane:"spam/ham")'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_command(self):
        # Given
        envelope = _CommandMessage('test', 'foo')
        expected = '@command(node:test,lane:foo)'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
예제 #3
0
    async def __remove_message(self, key: Any) -> None:
        """
        Send a `remove` message to the remote agent of the downlink.

        :param key:             - Key for the entry in the map lane that should be removed from the remote agent.
        """
        await self._initialised.wait()

        message = _CommandMessage(self._node_uri, self._lane_uri,
                                  RemoveRequest(key).to_record())
        await self._model._send_message(message)
예제 #4
0
    async def _send_message(self, value: Any) -> None:
        """
        Send a message to the remote agent of the downlink.

        :param value:           - New value for the lane of the remote agent.
        """
        await self._initialised.wait()
        recon = RecordConverter.get_converter().object_to_record(value)
        message = _CommandMessage(self._node_uri, self._lane_uri, recon)

        await self._model._send_message(message)
    def test_write_command_body_string(self):
        # Given
        envelope = _CommandMessage('dead/parrot',
                                   'spam/ham',
                                   body=Text.create_from('Polly the parrot.'))
        expected = '@command(node:"dead/parrot",lane:"spam/ham")"Polly the parrot."'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_command_body_bool(self):
        # Given
        envelope = _CommandMessage('dead/parrot',
                                   'spam/ham',
                                   body=Bool.create_from(True))
        expected = '@command(node:"dead/parrot",lane:"spam/ham")true'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_command_body_float(self):
        # Given
        envelope = _CommandMessage('dead/parrot',
                                   'spam/ham',
                                   body=Num.create_from(-911.119))
        expected = '@command(node:"dead/parrot",lane:"spam/ham")-911.119'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
예제 #8
0
    async def __put_message(self, key: Any, value: Any) -> None:
        """
        Send a `put` message to the remote agent of the downlink.

        :param key:             - Key for the new entry in the map lane of the remote agent.
        :param value:           - Value for the new entry in the map lane of the remote agent.
        """
        await self._initialised.wait()

        message = _CommandMessage(self._node_uri, self._lane_uri,
                                  UpdateRequest(key, value).to_record())
        await self._model._send_message(message)
예제 #9
0
 def test_command_message_empty_body(self):
     # Given
     node_uri = 'foo_command_node'
     lane_uri = 'bar_command_lane'
     # When
     actual = _CommandMessage(node_uri, lane_uri)
     # Then
     self.assertEqual('foo_command_node', actual._node_uri)
     self.assertEqual('bar_command_lane', actual._lane_uri)
     self.assertEqual('command', actual._tag)
     self.assertEqual('foo_command_node/bar_command_lane', actual._route)
     self.assertEqual(_Absent._get_absent(), actual._body)
     self.assertIsInstance(actual._form, _CommandMessageForm)
예제 #10
0
 def test_command_message_existing_body(self):
     # Given
     node_uri = 'foo_command_node'
     lane_uri = 'bar_command_lane'
     body = Text.create_from('Command_Body')
     # When
     actual = _CommandMessage(node_uri, lane_uri, body)
     # Then
     self.assertEqual('foo_command_node', actual._node_uri)
     self.assertEqual('bar_command_lane', actual._lane_uri)
     self.assertEqual('command', actual._tag)
     self.assertEqual('foo_command_node/bar_command_lane', actual._route)
     self.assertEqual(body, actual._body)
     self.assertIsInstance(actual._form, _CommandMessageForm)
예제 #11
0
    async def __send_command(self, host_uri: str, node_uri: str, lane_uri: str,
                             body: Any) -> None:
        """
        Send a command message to a given host.

        :param host_uri:        - Host URI of the remote agent.
        :param node_uri:        - Node URI of the remote agent.
        :param lane_uri:        - Lane URI of the command lane of the remote agent.
        :param body:            - The message body.
        """
        record = RecordConverter.get_converter().object_to_record(body)
        host_uri = _URI._normalise_warp_scheme(host_uri)
        message = _CommandMessage(node_uri, lane_uri, body=record)
        connection = await self._get_connection(host_uri)
        await connection._send_message(message._to_recon())
예제 #12
0
 def test_command_form_mold(self):
     # Given
     form = _CommandMessageForm()
     envelope = _CommandMessage('command_node',
                                'command_lane',
                                body=Text.create_from('Command_body'))
     # When
     actual = form._mold(envelope)
     # Then
     self.assertIsInstance(actual, RecordMap)
     self.assertEqual(2, actual.size)
     self.assertEqual('command', actual._tag)
     self.assertEqual('command_node',
                      actual.get_item(0).value.get_item(0).value.value)
     self.assertEqual('command_lane',
                      actual.get_item(0).value.get_item(1).value.value)
     self.assertEqual('Command_body', actual.get_item(1).value)
    def test_write_command_body_remove(self):
        # Given
        envelope = _CommandMessage(
            '/unit/foo',
            'shoppingCart',
            body=RecordMap.create_record_map(
                Attr.create_attr(
                    Text.create_from('remove'),
                    RecordMap.create_record_map(
                        Slot.create_slot(
                            Text.create_from('key'),
                            Text.create_from('FromClientLink'))))))
        expected = '@command(node:"/unit/foo",lane:shoppingCart)@remove(key:FromClientLink)'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)