コード例 #1
0
    def _create_instrumentation_dummy(self) -> Instrumentation:
        alert_level = AlertLevel()
        alert_level.level = 1
        alert_level.name = "Instrumentation Alert Level"
        alert_level.triggerAlertTriggered = True
        alert_level.triggerAlertNormal = True
        alert_level.instrumentation_cmd = "dummy.py"
        alert_level.instrumentation_timeout = 10

        sensor_alert = SensorAlert()
        sensor_alert.nodeId = 2
        sensor_alert.sensorId = 3
        sensor_alert.description = "Instrumentation Sensor Alert"
        sensor_alert.timeReceived = 1337
        sensor_alert.alertDelay = 20
        sensor_alert.state = 1
        sensor_alert.hasOptionalData = True
        sensor_alert.optionalData = {"key1": "value1", "key2": "value2"}
        sensor_alert.changeState = False
        sensor_alert.alertLevels = [1]
        sensor_alert.triggeredAlertLevels = [1]
        sensor_alert.hasLatestData = False
        sensor_alert.dataType = SensorDataType.NONE
        sensor_alert.sensorData = None

        logger = logging.getLogger("Instrumentation Test Case")

        return Instrumentation(alert_level, sensor_alert, logger)
コード例 #2
0
    def test_process_output_invalid_description(self):
        """
        Tests an invalid description output processing of an instrumentation script.
        """
        instrumentation = self._create_instrumentation_dummy()
        sensor_alert = instrumentation._sensor_alert

        invalid_sensor_alert = SensorAlert().deepcopy(sensor_alert)
        invalid_sensor_alert.description = sensor_alert.description + "_invalid"

        # Test instrumentation script output processing.
        was_success, new_sensor_alert = instrumentation._process_output(
            json.dumps(invalid_sensor_alert.convert_to_dict()))
        self.assertFalse(was_success)
        self.assertIsNone(new_sensor_alert)