Пример #1
0
 def test_should_return_no_properties(self, mock_device_svc,
                                      mock_device_template_svc):
     # test to check that no property updates are reported when version is not upadted
     # setup
     device_twin_data = json.dumps(self._device_twin)
     raw_twin = ast.literal_eval(
         device_twin_data.replace("current_time",
                                  datetime.now().isoformat()))
     twin = DeviceTwin(raw_twin)
     twin_next = DeviceTwin(raw_twin)
     monitor = PropertyMonitor(
         cmd=None,
         app_id=app_id,
         device_id=device_id,
         token=None,
         central_dns_suffix=None,
     )
     result = monitor._compare_properties(twin_next.reported_property,
                                          twin.reported_property)
     assert result is None
    def test_should_return_updated_properties(
        self, mock_device_svc, mock_device_template_svc
    ):
        # setup
        device_twin_data = json.dumps(self._device_twin)
        raw_twin = ast.literal_eval(
            device_twin_data.replace("current_time", datetime.now().isoformat())
        )

        twin = DeviceTwin(raw_twin)
        twin_next = DeviceTwin(raw_twin)
        twin_next.reported_property.version = twin.reported_property.version + 1
        monitor = PropertyMonitor(
            cmd=None,
            app_id=app_id,
            device_id=device_id,
            token=None,
            central_dns_suffix=None,
        )
        result = monitor._compare_properties(
            twin_next.reported_property, twin.reported_property
        )
        assert len(result) == 3
        assert len(result["$iotin:urn_azureiot_Client_SDKInformation"]) == 3
        assert result["$iotin:urn_azureiot_Client_SDKInformation"]["language"]
        assert result["$iotin:urn_azureiot_Client_SDKInformation"]["version"]
        assert result["$iotin:urn_azureiot_Client_SDKInformation"]["vendor"]

        assert len(result["$iotin:deviceinfo"]) == 8
        assert result["$iotin:deviceinfo"]["manufacturer"]
        assert result["$iotin:deviceinfo"]["model"]
        assert result["$iotin:deviceinfo"]["osName"]
        assert result["$iotin:deviceinfo"]["processorArchitecture"]
        assert result["$iotin:deviceinfo"]["swVersion"]
        assert result["$iotin:deviceinfo"]["processorManufacturer"]
        assert result["$iotin:deviceinfo"]["totalStorage"]
        assert result["$iotin:deviceinfo"]["totalMemory"]

        assert len(result["$iotin:settings"]) == 1
        assert result["$iotin:settings"]["fanSpeed"]