def test_decoding_serialized_report(self):
        report_data1 = make_report(10, 1, 2, 3, 4)

        report = IndividualReadingReport(report_data1)
        ser = report.serialize()

        report2 = IOTileReportParser.DeserializeReport(ser)
        assert report2.origin == report.origin
        assert report2.received_time == report.received_time
Exemple #2
0
def test_encoding():
    report_data = make_report(10, 1, 2, 3, 4)
    received_time = datetime.datetime.utcnow()

    report_data = bytearray(report_data)
    report = IndividualReadingReport(report_data, received_time=received_time)

    report_data2 = report.encode()
    assert report_data2 == report_data
Exemple #3
0
def test_serialization():
    """Make sure we can turn this report into a dictionary object without losing data."""

    report_data = make_report(10, 1, 2, 3, 4)
    received_time = datetime.datetime.utcnow()

    report = IndividualReadingReport(report_data, received_time=received_time)

    ser = report.serialize()
    print(ser)

    assert ser['received_time'] == received_time
    assert ser['origin'] == 10
    assert ser['report_format'] == IndividualReadingReport.ReportType

    str_report = str(report)
    assert str_report == 'IOTile Report (length: 20, visible readings: 1, visible events: 0, not verified and not encrypted)'
Exemple #4
0
def test_save(tmpdir):
    """Make sure we can save and load this report from a file
    """
    p = tmpdir.join('out.bin')

    report_data = make_report(10, 1, 2, 3, 4)
    received_time = datetime.datetime.utcnow()

    report = IndividualReadingReport(report_data, received_time=received_time)
    report.save(str(p))

    data = p.read("rb")

    report2 = IndividualReadingReport(data, received_time=received_time)

    assert report2.origin == report.origin
    assert report2.sent_timestamp == report.sent_timestamp
Exemple #5
0
    def _initialize(self):
        self.dev = MockIOTileDevice(1, 'TestCN')
        self.dev.reports = [IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)])]
        self.adapter = MockDeviceAdapter()
        self.adapter.add_device('test', self.dev)

        self.manager = DeviceManager(self.io_loop)
        self.manager.add_adapter(self.adapter)
        self.hw = None
    def setUp(self):
        super(TestDeviceManager, self).setUp()

        self.dev = MockIOTileDevice(1, 'TestCN')
        self.dev.reports = [
            IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)])
        ]
        self.adapter = MockDeviceAdapter()
        self.adapter.add_device('test', self.dev)

        self.manager = DeviceManager(self.io_loop)
        self.manager.add_adapter(self.adapter)
        self.manager.register_monitor(1, ['report'], self.on_report)
        self.reports = []
        self.reports_received = threading.Event()
Exemple #7
0
def test_fromreadings():
    """Make sure we can create this report dynamically from a list of readings
    """
    report = IndividualReadingReport.FromReadings(10, [IOTileReading(3, 1, 2)])

    assert len(report.visible_readings) == 1
    assert report.signed is False
    assert report.encrypted is False
    assert report.origin == 10

    reading = report.visible_readings[0]

    assert reading.stream == 1
    assert reading.value == 2
    assert reading.raw_time == 3
    assert reading.reading_time is not None
    def setUp(self):
        self.old_serial = serial.Serial
        serial.Serial = util.dummy_serial.Serial
        self.adapter = MockBLED112(3)
        self.dev1 = MockIOTileDevice(100, 'TestCN')
        self.dev1_ble = MockBLEDevice("00:11:22:33:44:55", self.dev1)
        self.adapter.add_device(self.dev1_ble)
        util.dummy_serial.RESPONSE_GENERATOR = self.adapter.generate_response

        self.dev1.reports = [
            IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)])
        ]
        self._reports_received = threading.Event()

        logging.basicConfig(level=logging.INFO, stream=sys.stdout)

        self.scanned_devices = []

        self.hw = HardwareManager(port='bled112:test')
Exemple #9
0
    def stream_realtime(self, stream, value):
        """Stream a realtime value as an IndividualReadingReport.

        If the streaming interface of the VirtualInterface this
        VirtualDevice is attached to is not opened, the realtime
        reading may be dropped.

        Args:
            stream (int): The stream id to send
            value (int): The stream value to send
        """

        if not self.stream_iface_open:
            return

        reading = IOTileReading(0, stream, value)

        report = IndividualReadingReport.FromReadings(self.iotile_id,
                                                      [reading])
        self.stream(report)
Exemple #10
0
def test_parsing_bytearray():
    """Make sure we can parse a report as a bytearray
    """

    report_data = make_report(10, 1, 2, 3, 4)
    received_time = datetime.datetime.utcnow()

    report = IndividualReadingReport(bytearray(report_data), received_time=received_time)

    assert len(report.visible_readings) == 1
    assert report.signed is False
    assert report.encrypted is False
    assert report.origin == 10

    reading = report.visible_readings[0]

    assert reading.stream == 1
    assert reading.value == 2
    assert reading.raw_time == 3
    assert reading.reading_time is not None

    reading_time = received_time + datetime.timedelta(seconds=-1)
    assert reading.reading_time == reading_time