def test_write_event_escaped(self):
        # Given
        envelope = _EventMessage('/this/is/spam', 'hello')
        expected = '@event(node:"/this/is/spam",lane:hello)'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_event(self):
        # Given
        envelope = _EventMessage('test', 'foo')
        expected = '@event(node:test,lane:foo)'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_event_body_string(self):
        # Given
        envelope = _EventMessage('/this/is/spam',
                                 'hello',
                                 body=Text.create_from("-33.12 / 6"))
        expected = '@event(node:"/this/is/spam",lane:hello)"-33.12 / 6"'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_event_body_bool(self):
        # Given
        envelope = _EventMessage('/this/is/spam',
                                 'hello',
                                 body=Bool.create_from(False))
        expected = '@event(node:"/this/is/spam",lane:hello)false'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_event_body_float(self):
        # Given
        envelope = _EventMessage('/this/is/spam',
                                 'hello',
                                 body=Num.create_from(33.12))
        expected = '@event(node:"/this/is/spam",lane:hello)33.12'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
Beispiel #6
0
 def test_event_message_empty_body(self):
     # Given
     node_uri = 'foo_event_node'
     lane_uri = 'bar_event_lane'
     # When
     actual = _EventMessage(node_uri, lane_uri)
     # Then
     self.assertEqual('foo_event_node', actual._node_uri)
     self.assertEqual('bar_event_lane', actual._lane_uri)
     self.assertEqual('event', actual._tag)
     self.assertEqual('foo_event_node/bar_event_lane', actual._route)
     self.assertEqual(_Absent._get_absent(), actual._body)
     self.assertIsInstance(actual._form, _EventMessageForm)
Beispiel #7
0
 def test_event_message_existing_body(self):
     # Given
     node_uri = 'foo_event_node'
     lane_uri = 'bar_event_lane'
     body = Text.create_from('Event_Body')
     # When
     actual = _EventMessage(node_uri, lane_uri, body)
     # Then
     self.assertEqual('foo_event_node', actual._node_uri)
     self.assertEqual('bar_event_lane', actual._lane_uri)
     self.assertEqual('foo_event_node/bar_event_lane', actual._route)
     self.assertEqual('event', actual._tag)
     self.assertEqual(body, actual._body)
     self.assertIsInstance(actual._form, _EventMessageForm)
 def test_event_form_mold(self):
     # Given
     form = _EventMessageForm()
     envelope = _EventMessage('event_node',
                              'event_lane',
                              body=Text.create_from('Event_body'))
     # When
     actual = form._mold(envelope)
     # Then
     self.assertIsInstance(actual, RecordMap)
     self.assertEqual(2, actual.size)
     self.assertEqual('event', actual._tag)
     self.assertEqual('event_node',
                      actual.get_item(0).value.get_item(0).value.value)
     self.assertEqual('event_lane',
                      actual.get_item(0).value.get_item(1).value.value)
     self.assertEqual('Event_body', actual.get_item(1).value)
    def test_write_event_body_nested(self):
        # Given

        friend = RecordMap.create()
        friend.add(
            Attr.create_attr(Text.create_from('Person'),
                             _Extant._get_extant()))
        friend.add(
            Slot.create_slot(Text.create_from('name'),
                             Text.create_from('Sam/Spam')))
        friend.add(
            Slot.create_slot(Text.create_from('age'), Num.create_from(1)))
        friend.add(
            Slot.create_slot(Text.create_from('salary'), Num.create_from(22)))

        body = RecordMap.create()
        body.add(
            Attr.create_attr(Text.create_from('Person'),
                             _Extant._get_extant()))
        body.add(
            Slot.create_slot(Text.create_from('name'),
                             Text.create_from('Par')))
        body.add(Slot.create_slot(Text.create_from('age'),
                                  Num.create_from(11)))
        body.add(
            Slot.create_slot(Text.create_from('salary'),
                             Num.create_from(-5.9)))
        body.add(Slot.create_slot(Text.create_from('friend'), friend))

        envelope = _EventMessage('/this/is/spam', 'hello', body=body)
        person = '@Person{name:Par,age:11,salary:-5.9,friend:@Person{name:"Sam/Spam",age:1,salary:22}}'
        expected = '@event(node:"/this/is/spam",lane:hello)' + person

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_event_body_object(self):
        # Given
        body = RecordMap.create()
        body.add(
            Attr.create_attr(Text.create_from('Person'),
                             _Extant._get_extant()))
        body.add(
            Slot.create_slot(Text.create_from('name'),
                             Text.create_from('Bar')))
        body.add(Slot.create_slot(Text.create_from('age'),
                                  Num.create_from(14)))
        body.add(
            Slot.create_slot(Text.create_from('salary'),
                             Num.create_from(-5.9)))

        envelope = _EventMessage('/this/is/spam', 'hello', body=body)
        expected = '@event(node:"/this/is/spam",lane:hello)@Person{name:Bar,age:14,salary:-5.9}'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)