def test_extract_schema_type_component(self):
     expected_mapping = {
         "component1Prop": "boolean",
         "testComponent": "boolean",
         "component1PropReadonly": "boolean",
         "component1Prop2": "boolean",
     }
     template = Template(
         load_json(FileNames.central_property_validation_template_file))
     for key, val in expected_mapping.items():
         schema = template.get_schema(key, is_component=True)
         schema_type = extract_schema_type(schema)
         assert schema_type == val
Exemplo n.º 2
0
    def _validate_payload_against_interfaces(
        self,
        payload: dict,
        template: Template,
    ):
        name_miss = []
        for telemetry_name, telemetry in payload.items():
            schema = template.get_schema(name=telemetry_name,
                                         interface_name=self.interface_name)
            if not schema:
                name_miss.append(telemetry_name)
            else:
                self._process_telemetry(telemetry_name, schema, telemetry)

        if name_miss:
            details = strings.invalid_field_name_mismatch_template(
                name_miss, template.schema_names)
            self._add_central_issue(severity=Severity.warning, details=details)
 def test_extract_schema_type(self):
     expected_mapping = {
         "Bool": "boolean",
         "Date": "date",
         "DateTime": "dateTime",
         "Double": "double",
         "Duration": "duration",
         "IntEnum": "Enum",
         "StringEnum": "Enum",
         "Float": "float",
         "Geopoint": "geopoint",
         "Long": "long",
         "Object": "Object",
         "String": "string",
         "Time": "time",
         "Vector": "vector",
     }
     template = Template(load_json(FileNames.central_device_template_file))
     for key, val in expected_mapping.items():
         schema = template.get_schema(key)
         schema_type = extract_schema_type(schema)
         assert schema_type == val
    def _validate_payload(self, payload: dict, template: Template,
                          is_component: bool):
        name_miss = []
        for telemetry_name, telemetry in payload.items():
            schema = template.get_schema(
                name=telemetry_name,
                identifier=self.component_name,
                is_component=is_component,
            )
            if not schema:
                name_miss.append(telemetry_name)
            else:
                self._process_telemetry(telemetry_name, schema, telemetry)

        if name_miss:
            if is_component:
                details = strings.invalid_field_name_component_mismatch_template(
                    name_miss, template.component_schema_names)
            else:
                details = strings.invalid_field_name_mismatch_template(
                    name_miss,
                    template.schema_names,
                )
            self._add_central_issue(severity=Severity.warning, details=details)
 def test_object_deep(self, value, expected_result):
     template = Template(
         load_json(FileNames.central_deeply_nested_device_template_file))
     schema = template.get_schema("RidiculousObject")
     assert validate(schema, value) == expected_result
 def test_str_enum(self, value, expected_result):
     template = Template(load_json(FileNames.central_device_template_file))
     schema = template.get_schema("StringEnum")
     assert validate(schema, value) == expected_result