def test_validate_scenario_without_required_fields(self):

        template = self.clone_template
        scenario = template[TemplateFields.SCENARIOS][0]
        scenario[TemplateFields.SCENARIO].pop(TemplateFields.CONDITION)
        self.assertFalse(template_syntax_validator.syntax_valid(template))

        template = self.clone_template
        scenario = template[TemplateFields.SCENARIOS][0]
        scenario[TemplateFields.SCENARIO].pop(TemplateFields.ACTIONS)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_entity_without_required_fields(self):

        template = self.clone_template
        definitions = template[TemplateFields.DEFINITIONS]
        entity = definitions[TemplateFields.ENTITIES][0]
        entity[TemplateFields.ENTITY].pop(TemplateFields.CATEGORY)
        self.assertFalse(template_syntax_validator.syntax_valid(template))

        template = self.clone_template
        definitions = template[TemplateFields.DEFINITIONS]
        entity = definitions[TemplateFields.ENTITIES][0]
        entity[TemplateFields.ENTITY].pop(TemplateFields.TEMPLATE_ID)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_action_without_required_fields(self):

        template = self.clone_template
        scenario = template[TemplateFields.SCENARIOS][0]
        action = scenario[TemplateFields.SCENARIO][TemplateFields.ACTIONS][0]
        action[TemplateFields.ACTION].pop(TemplateFields.ACTION_TYPE)
        self.assertFalse(template_syntax_validator.syntax_valid(template))

        template = self.clone_template
        scenario = template[TemplateFields.SCENARIOS][0]
        action = scenario[TemplateFields.SCENARIO][TemplateFields.ACTIONS][0]
        action[TemplateFields.ACTION].pop(TemplateFields.ACTION_TARGET)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_relationships_without_required_fields(self):

        template = self.clone_template
        definitions = template[TemplateFields.DEFINITIONS]
        relationship = definitions[TemplateFields.RELATIONSHIPS][0]
        relationship[TemplateFields.RELATIONSHIP].pop(TemplateFields.SOURCE)
        self.assertFalse(template_syntax_validator.syntax_valid(template))

        template = self.clone_template
        definitions = template[TemplateFields.DEFINITIONS]
        relationship = definitions[TemplateFields.RELATIONSHIPS][0]
        relationship[TemplateFields.RELATIONSHIP].pop(TemplateFields.TARGET)
        self.assertFalse(template_syntax_validator.syntax_valid(template))

        template = self.clone_template
        definitions = template[TemplateFields.DEFINITIONS]
        relationship = definitions[TemplateFields.RELATIONSHIPS][0]
        relationship[TemplateFields.RELATIONSHIP].pop(
            TemplateFields.TEMPLATE_ID)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_init_scenario_repository(self):

        # Test Setup
        valid_template_counter = 0
        for template_definition in self.template_defs:
            if syntax_valid(template_definition):
                valid_template_counter += 1

        # Test assertions
        self.assertIsNotNone(self.scenario_repository)

        scenario_templates = self.scenario_repository.templates
        self.assertEqual(valid_template_counter, len(scenario_templates))
    def add_template(self, template_def):

        if syntax_valid(template_def):
            template = Template(template_def)
            self.templates[template.name] = template
            self._add_template_scenarios(template)
        else:
            metadata = template_def.get(TemplateFields.METADATA, None)
            if metadata:
                template_id = metadata.get(TemplateFields.ID, None)
                LOG.info('Unable to load template: %s' % template_id)
            else:
                LOG.info('Unable to load template with invalid metadata')
    def test_init_scenario_repository(self):

        # Test Setup
        valid_template_counter = 0
        for template_definition in self.template_defs:
            if syntax_valid(template_definition):
                valid_template_counter += 1

        # Test assertions
        self.assertIsNotNone(self.scenario_repository)

        scenario_templates = self.scenario_repository.templates
        self.assertEqual(valid_template_counter, len(scenario_templates))
    def test_validate_template_with_empty_entities(self):

        template = self.clone_template
        template[TemplateFields.DEFINITIONS][TemplateFields.ENTITIES] = []
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_template_without_entities(self):

        template = self.clone_template
        template[TemplateFields.DEFINITIONS].pop(TemplateFields.ENTITIES)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_template_without_definitions_section(self):

        template = self.clone_template
        template.pop(TemplateFields.DEFINITIONS)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_template_without_id_in_metadata_section(self):

        template = self.clone_template
        template[TemplateFields.METADATA].pop(TemplateFields.ID)
        self.assertFalse(template_syntax_validator.syntax_valid(template))
 def test_template_validator(self):
     self.assertTrue(
         template_syntax_validator.syntax_valid(self.first_template))
    def test_validate_template_with_empty_actions(self):

        template = self.clone_template
        scenario = template[TemplateFields.SCENARIOS][0]
        scenario[TemplateFields.SCENARIO][TemplateFields.ACTIONS] = []
        self.assertFalse(template_syntax_validator.syntax_valid(template))
 def test_validate_template_with_empty_scenarios(self):
     template = self.clone_template
     template[TemplateFields.SCENARIOS] = []
     self.assertFalse(template_syntax_validator.syntax_valid(template))
    def test_validate_template_without_scenarios(self):

        template = self.clone_template
        template.pop(TemplateFields.SCENARIOS)
        self.assertFalse(template_syntax_validator.syntax_valid(template))