Example #1
0
 def test_msg_pack(self):
     bus = MagicMock()
     dev = Radio(bus=bus, config={})
     bus.reset_mock()
     dev.send_data('dummy_artf', [1, 2, 3])
     bus.publish.assert_called()
     self.assertEqual(bus.method_calls[-1],
                      call.publish('radio', serialize([0, 'dummy_artf', [1, 2, 3]])))
     dev.send_data('dummy_artf', [1, 2, 3])
     self.assertEqual(bus.method_calls[-1],
                      call.publish('radio', serialize([1, 'dummy_artf', [1, 2, 3]])))
Example #2
0
 def test_report_artifact(self):
     bus = MagicMock()
     c = LoRa(bus=bus, config={'device_id': 1})
     with patch('osgar.node.Node.update') as p:
         p.return_value = 'raw'
         c.raw = b"3|['TYPE_BACKPACK', 3506, -18369, -752]\n"
         c.update()
         self.assertEqual(bus.method_calls, [
             call.register('raw', 'cmd', 'robot_status', 'artf'),
             call.publish('artf',
                          [3, ['TYPE_BACKPACK', 3506, -18369, -752]]),
             call.publish('raw',
                          b"3|['TYPE_BACKPACK', 3506, -18369, -752]\n")
         ])
Example #3
0
    def test_on_robot_trace(self):
        bus = MagicMock()
        mtm = MultiTraceManager(bus=bus, config={})
        mtm.on_robot_trace({
            'A150L':
            [[505, [6.127597694909277, 2.640278491024048, 1.9188244676330934]],
             [506, [5.07939188538461, 2.0835104023227147, 1.9305388336683675]]]
        })
        self.assertIn('A150L', mtm.traces)
        mtm.on_robot_trace({
            'A150L': [[
                500,
                [10.098783014125825, 2.4058896366987415, 2.0341068401239615]
            ]]
        })
        self.assertEqual(len(mtm.traces['A150L']), 3)
        mtm.on_robot_trace({
            'A150L': [[
                500,
                [10.098783014125825, 2.4058896366987415, 2.0341068401239615]
            ]]
        })
        self.assertEqual(len(mtm.traces['A150L']), 3)

        bus.reset_mock()
        mtm.publish_trace_info()
        bus.publish.assert_called()
        self.assertEqual(
            bus.method_calls[-1],
            call.publish('trace_info', {'A150L': [[500, 500], [505, 506]]}))
Example #4
0
    def test_usage(self):
        bus = MagicMock()
        mtm = MultiTraceManager(bus=bus, config={})
        mtm.on_robot_xyz([
            'A150L',
            [505, [6.127597694909277, 2.640278491024048, 1.9188244676330934]]
        ])
        mtm.on_robot_xyz([
            'A150L',
            [506, [5.07939188538461, 2.0835104023227147, 1.9305388336683675]]
        ])
        bus.publish.assert_called()
        self.assertEqual(bus.method_calls[-1],
                         call.publish('trace_info', {'A150L': [[505, 506]]}))

        bus.reset_mock()
        mtm.on_trace_info({'B100R': [[1, 10]]})
        bus.publish.assert_called()
        self.assertEqual(
            bus.method_calls[-1],
            call.publish(
                'robot_trace', {
                    'A150L': [[
                        505,
                        [
                            6.127597694909277, 2.640278491024048,
                            1.9188244676330934
                        ]
                    ],
                              [
                                  506,
                                  [
                                      5.07939188538461, 2.0835104023227147,
                                      1.9305388336683675
                                  ]
                              ]]
                }))

        bus.reset_mock()
        mtm.on_trace_info({'A150L': [[505, 506]]})
        bus.publish.assert_not_called()
Example #5
0
 def test_pose3d(self):
     bus = MagicMock()
     dev = Radio(bus=bus, config={})
     bus.reset_mock()
     data = [[-5.999917943872727, 4.999913526023388, 0.12287766016353471], [6.229389211972107e-12, -7.943606405014296e-12, 1.5034993858140517e-12, 1.0]]
     dev.on_pose3d(data)
     bus.publish.assert_not_called()  # not defined sim_time
     dev.on_sim_time_sec(13)
     dev.on_pose3d(data)
     bus.publish.assert_called()
     self.assertEqual(bus.method_calls[-1],
                      call.publish('radio', serialize([1, 'xyz', [13, [-5.999917943872727, 4.999913526023388, 0.12287766016353471]]])))
Example #6
0
    def test_partial_update(self):
        bus = MagicMock()
        mtm = MultiTraceManager(bus=bus, config={})
        for i in range(10):
            mtm.on_robot_xyz(['A10L', [i, [2 * i, 0, 0]]])

        bus.reset_mock()
        mtm.on_trace_info({'A10L': [[1, 8]]})
        bus.publish.assert_called()
        self.assertEqual(
            bus.method_calls[-1],
            call.publish('robot_trace',
                         {'A10L': [[0, [0, 0, 0]], [9, [18, 0, 0]]]}))
Example #7
0
    def test_on_breadcrumb(self):
        data = [29.929257253892082, -1.5821685677914703, 1.575092509709292]  # xyz location of newly deployed breadcrumb
        bus = MagicMock()
        dev = Radio(bus=bus, config={})
        bus.reset_mock()
        dev.on_breadcrumb(data)
        bus.publish.assert_called()
        self.assertEqual(bus.method_calls[0],
                         call.publish('radio', serialize([0, 'breadcrumb', [29.929257253892082, -1.5821685677914703, 1.575092509709292]])))

        new_msg = serialize([0, 'breadcrumb', [29.929257253892082, -1.5821685677914703, 1.575092509709292]])
        bus.reset_mock()
        dev.on_radio([b'A1300L', new_msg])
        bus.publish.assert_called()
    def test_publishing(self):
        event = self.load_event('AssignGlobalIndex')
        events_topic = Mock()
        changesets_topic = Mock()

        p = Publisher(changesets_topic, events_topic)
        changesets = parse_dynamodb_new_records(event, None)
        
        p.publish(changesets)

        changesets_topic.assert_has_calls([
            call.publish('{"stream_id": "99038933-e620-444d-9033-4128254f0cbd", "changeset_id": 2, "events": [{"type": "init", "foo": "bar"}, {"type": "update", "foo": "baz"}], "metadata": {"timestamp": "123123", "command_id": "456346234", "issued_by": "*****@*****.**"}}', '8ebf57ca0228236805c448931bc9f2d8def48fff0380a57d13701091'),
            call.publish('{"stream_id": "206bc1ed-8e67-4a64-a596-8b32c0c20a97", "changeset_id": 1, "events": [{"type": "init", "foo": "bar"}, {"type": "update", "foo": "baz"}], "metadata": {"timestamp": "123123", "command_id": "456346234", "issued_by": "*****@*****.**"}}', '4520eff932295c3ca621d2a8fb018a7a82ddfde0fc86ae8538ea8524')
        ])

        events_topic.assert_has_calls([
            call.publish('{"stream_id": "99038933-e620-444d-9033-4128254f0cbd", "changeset_id": 2, "event_id": 3, "data": {"type": "init", "foo": "bar"}}', '8ebf57ca0228236805c448931bc9f2d8def48fff0380a57d13701091'),
            call.publish('{"stream_id": "99038933-e620-444d-9033-4128254f0cbd", "changeset_id": 2, "event_id": 4, "data": {"type": "update", "foo": "baz"}}', '8ebf57ca0228236805c448931bc9f2d8def48fff0380a57d13701091'),
            call.publish('{"stream_id": "206bc1ed-8e67-4a64-a596-8b32c0c20a97", "changeset_id": 1, "event_id": 1, "data": {"type": "init", "foo": "bar"}}', '4520eff932295c3ca621d2a8fb018a7a82ddfde0fc86ae8538ea8524'),
            call.publish('{"stream_id": "206bc1ed-8e67-4a64-a596-8b32c0c20a97", "changeset_id": 1, "event_id": 2, "data": {"type": "update", "foo": "baz"}}', '4520eff932295c3ca621d2a8fb018a7a82ddfde0fc86ae8538ea8524')
        ])