def test_init_scenario_repository(self):

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

        # Test assertions
        self.assertIsNotNone(self.scenario_repository)

        scenario_templates = self.scenario_repository.templates
        # there is one bad template
        self.assertThat(
            scenario_templates, matchers.HasLength(valid_template_counter),
            'scenario_repository.templates '
            'should contain all valid templates')

        entity_equivalences = self.scenario_repository.entity_equivalences
        for entity_props, equivalence in entity_equivalences.items():
            # Example structure of entity_equivalences
            #   { A: (A, B, C),
            #     B: (A, B, C),
            #     C: (A, B, C)}
            # Verify entity itself is also included. It is not required, but
            # worth noting when handling equivalence
            self.assertTrue(entity_props in equivalence)
            for equivalent_props in equivalence:
                # Verify equivalent scenarios are present in repository
                self.assertTrue(equivalent_props in
                                self.scenario_repository.entity_scenarios)
Esempio n. 2
0
    def add_template(self, template_def):

        result = syntax_validation(template_def)

        if not result.is_valid_config:
            LOG.info('Unable to load template, syntax err: %s'
                     % result.comment)
        else:
            result = content_validation(template_def, self._def_templates)
            if not result.is_valid_config:
                LOG.info('Unable to load template, content err: %s'
                         % result.comment)

        template_uuid = uuidutils.generate_uuid()
        current_time = datetime_utils.utcnow()
        self.templates[str(template_uuid)] = Template(template_uuid,
                                                      template_def,
                                                      current_time,
                                                      result)
        if result.is_valid_config:
            template_data = \
                TemplateLoader().load(template_def, self._def_templates)
            for scenario in template_data.scenarios:
                for equivalent_scenario in self._expand_equivalence(scenario):
                    self._add_scenario(equivalent_scenario)
Esempio n. 3
0
    def validate_template(self, ctx, templates):
        LOG.debug("TemplateApis validate_template templates:"
                  "%s", str(templates))

        results = []
        for template in templates:

            template_def = template[1]
            path = template[0]

            syntax_result = syntax_validation(template_def)
            if not syntax_result.is_valid:
                self._add_result(path, self.FAILED_MSG,
                                 syntax_result.description,
                                 syntax_result.comment,
                                 syntax_result.status_code, results)
                continue

            content_result = content_validation(template_def)
            if not content_result.is_valid:
                self._add_result(path, self.FAILED_MSG,
                                 content_result.description,
                                 content_result.comment,
                                 content_result.status_code, results)
                continue

            self._add_result(path, self.OK_MSG, 'Template validation',
                             status_msgs[0], 0, results)

        return json.dumps({'results': results})
Esempio n. 4
0
    def _test_execution_with_correct_result(self, template):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertTrue(result.is_valid)
        self.assertEqual(result.comment, CORRECT_RESULT_MESSAGE)
Esempio n. 5
0
    def _test_execution_with_fault_result(self, template, expected_comment):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertFalse(result.is_valid)
        self.assertTrue(str(result.comment).startswith(expected_comment))
    def _test_execution_with_correct_result(self, template):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertTrue(result.is_valid)
        self.assertEqual(result.comment, CORRECT_RESULT_MESSAGE)
    def _test_execution_with_fault_result(self, template, expected_comment):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertFalse(result.is_valid)
        self.assertTrue(str(result.comment).startswith(expected_comment))
    def _test_execution_with_correct_result(self, template):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertTrue(result.is_valid_config)
        self.assertEqual(result.comment, status_msgs[0])
        self.assertEqual(result.status_code, 0)
    def _test_execution_with_correct_result(self, template):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertTrue(result.is_valid_config)
        self.assertEqual(result.comment, status_msgs[0])
        self.assertEqual(0, result.status_code)
    def _test_execution_with_fault_result(self, template, expected_code):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertFalse(result.is_valid_config)
        self.assertTrue(result.comment.startswith(status_msgs[expected_code]))
        self.assertEqual(result.status_code, expected_code)
    def _test_execution_with_fault_result(self, template, expected_code):

        # Test action
        result = template_syntax_validator.syntax_validation(template)

        # Test assertions
        self.assertFalse(result.is_valid_config)
        self.assertTrue(result.comment.startswith(status_msgs[expected_code]))
        self.assertEqual(expected_code, result.status_code)
Esempio n. 12
0
def validate_template(template, def_templates):
    result = syntax_validation(template)
    if not result.is_valid_config:
        LOG.error('Unable to load template, syntax error: %s' % result.comment)
        return result
    result = content_validation(template, def_templates)
    if not result.is_valid_config:
        LOG.error('Unable to load template, content error:%s' % result.comment)
        return result
    return result
    def test_init_scenario_repository(self):

        # Test Setup
        valid_template_counter = 0
        for template_definition in self.template_defs:
            syntax_validation_result = syntax_validation(template_definition)
            if syntax_validation_result.is_valid:
                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_init_scenario_repository(self):

        # Test Setup
        valid_template_counter = 0
        for template_definition in self.template_defs:
            syntax_validation_result = syntax_validation(template_definition)
            if syntax_validation_result.is_valid_config:
                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))
Esempio n. 15
0
    def add_template(self, template_def):

        syntax_validation_result = syntax_validation(template_def)
        content_validation_result = content_validation(template_def)
        if syntax_validation_result.is_valid and \
                content_validation_result.is_valid:
            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')
Esempio n. 16
0
    def add_template(self, template_def):

        current_time = datetime_utils.utcnow()

        result = syntax_validation(template_def)
        if not result.is_valid:
            LOG.info('Unable to load template: %s', result.comment)
        else:
            result = content_validation(template_def)
            if not result.is_valid:
                LOG.info('Unable to load template: %s', result.comment)

        template_uuid = uuid.uuid4()
        self.templates[str(template_uuid)] = Template(template_uuid,
                                                      template_def,
                                                      current_time, result)
        if result.is_valid:
            template_data = TemplateData(template_def)
            self._add_template_scenarios(template_data)
Esempio n. 17
0
    def add_template(self, template_def):

        current_time = datetime_utils.utcnow()

        result = syntax_validation(template_def)
        if not result.is_valid:
            LOG.info('Unable to load template: %s' % result.comment)
        else:
            result = content_validation(template_def)
            if not result.is_valid:
                LOG.info('Unable to load template: %s' % result.comment)

        template_uuid = md5(str(template_def).encode()).hexdigest()
        self.templates[str(template_uuid)] = Template(template_uuid,
                                                      template_def,
                                                      current_time,
                                                      result)
        if result.is_valid:
            template_data = TemplateData(template_def)
            self._add_template_scenarios(template_data)
Esempio n. 18
0
    def validate_template(self, ctx, templates):
        LOG.debug("TemplateApis validate_template templates:"
                  "%s", str(templates))

        results = []
        for template in templates:

            template_def = template[1]
            path = template[0]

            syntax_result = syntax_validation(template_def)
            if not syntax_result.is_valid:
                self._add_result(path,
                                 self.FAILED_MSG,
                                 syntax_result.description,
                                 syntax_result.comment,
                                 syntax_result.status_code,
                                 results)
                continue

            content_result = content_validation(template_def)
            if not content_result.is_valid:
                self._add_result(path,
                                 self.FAILED_MSG,
                                 content_result.description,
                                 content_result.comment,
                                 content_result.status_code,
                                 results)
                continue

            self._add_result(path,
                             self.OK_MSG,
                             'Template validation',
                             status_msgs[0],
                             0,
                             results)

        return json.dumps({'results': results})