예제 #1
0
    def test_parse_event_body_nested(self):
        # Given
        person = '@Person{name:Par,age:11,salary:5.9,friend:@Person{name:Foo,age:18,salary:99.9}'
        message = '@event(node: "bar/baz/2", lane: "foo/bar")' + person
        # When
        actual = _Envelope._parse_recon(message)
        # Then
        self.assertEqual('event', actual._tag)
        self.assertEqual('bar/baz/2', actual._node_uri)
        self.assertEqual('foo/bar', actual._lane_uri)

        self.assertEqual(5, len(actual._body.get_items()))
        self.assertEqual('Person', actual._body.get_items()[0].key.value)
        self.assertEqual('name', actual._body.get_items()[1].key.value)
        self.assertEqual('Par', actual._body.get_items()[1].value.value)
        self.assertEqual('age', actual._body.get_items()[2].key.value)
        self.assertEqual(11, actual._body.get_items()[2].value.value)
        self.assertEqual('salary', actual._body.get_items()[3].key.value)
        self.assertEqual(5.9, actual._body.get_items()[3].value.value)
        self.assertEqual('friend', actual._body.get_items()[4].key.value)
        self.assertEqual(4, len(actual._body.get_items()[4].value.get_items()))
        self.assertEqual('Person', actual._body.get_items()[4].value.get_items()[0].key.value)
        self.assertEqual('name', actual._body.get_items()[4].value.get_items()[1].key.value)
        self.assertEqual('Foo', actual._body.get_items()[4].value.get_items()[1].value.value)
        self.assertEqual('age', actual._body.get_items()[4].value.get_items()[2].key.value)
        self.assertEqual(18, actual._body.get_items()[4].value.get_items()[2].value.value)
        self.assertEqual('salary', actual._body.get_items()[4].value.get_items()[3].key.value)
        self.assertEqual(99.9, actual._body.get_items()[4].value.get_items()[3].value.value)
예제 #2
0
 def test_parse_event_escaped(self):
     # Given
     message = '@event(node: "bar/baz/2", lane: "foo/bar")'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('event', actual._tag)
     self.assertEqual('bar/baz/2', actual._node_uri)
     self.assertEqual('foo/bar', actual._lane_uri)
예제 #3
0
 def test_parse_command_escaped(self):
     # Given
     message = '@command(node: "foo/bar", lane: "lane/uri/test")'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('command', actual._tag)
     self.assertEqual('foo/bar', actual._node_uri)
     self.assertEqual('lane/uri/test', actual._lane_uri)
예제 #4
0
 def test_parse_unlinked_rate(self):
     # Given
     message = '@unlinked(node: "foo", lane: "1/bar/", rate: 33)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('1/bar/', actual._lane_uri)
     self.assertEqual(33, actual._rate)
예제 #5
0
 def test_parse_unlinked_prio(self):
     # Given
     message = '@unlinked(node: foo, lane: bar, prio: 1000.3)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('bar', actual._lane_uri)
     self.assertEqual(1000.3, actual._prio)
예제 #6
0
 def test_parse_link_escaped(self):
     # Given
     message = '@link(node: "bar/baz/5", lane: "foo/baz")'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('link', actual._tag)
     self.assertEqual('bar/baz/5', actual._node_uri)
     self.assertEqual('foo/baz', actual._lane_uri)
예제 #7
0
 def test_parse_link(self):
     # Given
     message = '@link(node: boo, lane: far)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('link', actual._tag)
     self.assertEqual('boo', actual._node_uri)
     self.assertEqual('far', actual._lane_uri)
예제 #8
0
 def test_parse_event(self):
     # Given
     message = '@event(node: foo, lane: bar)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('event', actual._tag)
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('bar', actual._lane_uri)
예제 #9
0
 def test_parse_synced_body_string(self):
     # Given
     message = '@synced(node: foo, lane: bar)"Hello, World"'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('synced', actual._tag)
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('bar', actual._lane_uri)
     self.assertEqual('Hello, World', actual._body.value)
예제 #10
0
 def test_parse_unlinked_body_float(self):
     # Given
     message = '@unlinked(node: "bar/baz/2", lane: "foo/bar")-0.00031'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('unlinked', actual._tag)
     self.assertEqual('bar/baz/2', actual._node_uri)
     self.assertEqual('foo/bar', actual._lane_uri)
     self.assertEqual(-0.00031, actual._body.value)
예제 #11
0
 def test_parse_linked_body_int(self):
     # Given
     message = '@linked(node: "bar/baz/2", lane: "foo/bar")9999999'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('linked', actual._tag)
     self.assertEqual('bar/baz/2', actual._node_uri)
     self.assertEqual('foo/bar', actual._lane_uri)
     self.assertEqual(9999999, actual._body.value)
예제 #12
0
 def test_parse_command_body_string(self):
     # Given
     message = '@command(node: "foo/bar", lane: "lane/uri/test")"0.32"'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('command', actual._tag)
     self.assertEqual('foo/bar', actual._node_uri)
     self.assertEqual('lane/uri/test', actual._lane_uri)
     self.assertEqual('0.32', actual._body.value)
예제 #13
0
 def test_parse_synced_body_bool(self):
     # Given
     message = '@synced(node: foo, lane: bar)true'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('synced', actual._tag)
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('bar', actual._lane_uri)
     self.assertEqual(True, actual._body.value)
예제 #14
0
 def test_parse_sync_body_string(self):
     # Given
     message = '@sync(node: "bar/baz/2", lane: "foo/bar")"Hello, World"'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('sync', actual._tag)
     self.assertEqual('bar/baz/2', actual._node_uri)
     self.assertEqual('foo/bar', actual._lane_uri)
     self.assertEqual('Hello, World', actual._body.value)
예제 #15
0
 def test_parse_sync_rate(self):
     # Given
     message = '@sync(node: foo, lane: bar, rate: 33)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('sync', actual._tag)
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('bar', actual._lane_uri)
     self.assertEqual(33, actual._rate)
예제 #16
0
 def test_parse_sync_body_bool(self):
     # Given
     message = '@sync(node: "bar/baz/2", lane: "foo/bar")false'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('sync', actual._tag)
     self.assertEqual('bar/baz/2', actual._node_uri)
     self.assertEqual('foo/bar', actual._lane_uri)
     self.assertEqual(False, actual._body.value)
예제 #17
0
 def test_parse_event_body_bool(self):
     # Given
     message = '@event(node: "bar/baz/2", lane: "foo/bar")true'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('event', actual._tag)
     self.assertEqual('bar/baz/2', actual._node_uri)
     self.assertEqual('foo/bar', actual._lane_uri)
     self.assertEqual(True, actual._body.value)
예제 #18
0
 def test_parse_linked_prio_rate(self):
     # Given
     message = '@linked(node: foo, lane: bar, prio: 13, rate: 37)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('linked', actual._tag)
     self.assertEqual('foo', actual._node_uri)
     self.assertEqual('bar', actual._lane_uri)
     self.assertEqual(13, actual._prio)
     self.assertEqual(37, actual._rate)
예제 #19
0
 def test_parse_command_body_remove(self):
     # Given
     message = '@command(node:"/unit/foo",lane:shoppingCart)@remove(key:FromClientLink)'
     # When
     actual = _Envelope._parse_recon(message)
     # Then
     self.assertEqual('command', actual._tag)
     self.assertEqual('/unit/foo', actual._node_uri)
     self.assertEqual('shoppingCart', actual._lane_uri)
     self.assertEqual('remove', actual._body.get_items()[0].key.value)
     self.assertEqual('key', actual._body.get_items()[0].value.get_items()[0].key.value)
     self.assertEqual('FromClientLink', actual._body.get_items()[0].value.get_items()[0].value.value)
예제 #20
0
    async def _wait_for_messages(self) -> None:
        """
        Wait for messages from the remote agent and propagate them
        to all subscribers.
        """

        if self.status == _ConnectionStatus.IDLE:
            self.status = _ConnectionStatus.RUNNING
            try:
                while self.status == _ConnectionStatus.RUNNING:
                    message = await self.websocket.recv()
                    response = _Envelope._parse_recon(message)
                    await self.__subscribers._receive_message(response)
            finally:
                await self._close()
예제 #21
0
    def test_parse_event_body_object(self):
        # Given
        message = '@event(node: "bar/baz/2", lane: "foo/bar")@Person{name:Bar,age:14,salary:5.9}'
        # When
        actual = _Envelope._parse_recon(message)
        # Then
        self.assertEqual('event', actual._tag)
        self.assertEqual('bar/baz/2', actual._node_uri)
        self.assertEqual('foo/bar', actual._lane_uri)

        self.assertEqual(4, len(actual._body.get_items()))
        self.assertEqual('Person', actual._body.get_items()[0].key.value)
        self.assertEqual('name', actual._body.get_items()[1].key.value)
        self.assertEqual('Bar', actual._body.get_items()[1].value.value)
        self.assertEqual('age', actual._body.get_items()[2].key.value)
        self.assertEqual(14, actual._body.get_items()[2].value.value)
        self.assertEqual('salary', actual._body.get_items()[3].key.value)
        self.assertEqual(5.9, actual._body.get_items()[3].value.value)