Esempio n. 1
0
    def __init__(self, name, description=None, context=None):
        super(State, self).__init__()
        self.name = name
        self.description = description
        self.context = context

        if not isinstance(name, str):
            self.AddFinding(findings_lib.IllegalKeyTypeError(name, context))
        elif not STATE_NAME_VALIDATOR.match(name):
            self.AddFinding(findings_lib.IllegalCharacterError(name, context))
        if not description:
            self.AddFinding(findings_lib.MissingStateDescriptionWarning(self))
Esempio n. 2
0
    def testStateUniverseGetFindings(self):
        context = findings_lib.FileContext('{0}/file.yaml'.format(_GOOD_PATH))
        folder = state_lib.StateFolder(_GOOD_PATH)
        folder.AddFinding(
            findings_lib.InconsistentFileLocationError('', context))
        namespace = folder.local_namespace
        namespace.AddFinding(
            findings_lib.DuplicateStateDefinitionError(
                state_lib.State('STATE'), 'namespace'))
        state = state_lib.State('STATE', 'description')
        state.AddFinding(findings_lib.MissingStateDescriptionWarning(state))
        namespace.InsertState(state)
        state_universe = state_lib.StateUniverse([folder])

        findings = state_universe.GetFindings()

        self.assertLen(findings, 3)
        self.assertTrue(
            state_universe.HasFindingTypes([
                findings_lib.InconsistentFileLocationError,
                findings_lib.DuplicateStateDefinitionError,
                findings_lib.MissingStateDescriptionWarning
            ]))
        self.assertFalse(state_universe.IsValid())
Esempio n. 3
0
    def __init__(self, name, description=None, file_context=None):
        """Init.

    Args:
      name: required string representing the state.
      description: optional (for now) string semantic definition for the state.
      file_context: optional object with the config file location of this state.

    Returns:
      Instance of State class.
    """
        super(State, self).__init__()
        self.name = name
        self.description = description
        self.file_context = file_context

        if not isinstance(name, str):
            self.AddFinding(
                findings_lib.IllegalKeyTypeError(name, file_context))
        elif not STATE_NAME_VALIDATOR.match(name):
            self.AddFinding(
                findings_lib.InvalidStateNameError(name, file_context))
        if not description:
            self.AddFinding(findings_lib.MissingStateDescriptionWarning(self))