Пример #1
0
    def test_execute(self):
        """Start the LicenseCheckTask task and test its results."""
        data = str(Path(__file__).parent.parent / 'data/license')
        args = dict.fromkeys(('ecosystem', 'name', 'version'), 'some-value')
        flexmock(EPVCache).should_receive('get_sources').and_return(data)
        task = LicenseCheckTask.create_test_instance(
            task_name='source_licenses')
        results = task.execute(arguments=args)

        assert results is not None
        assert isinstance(results, dict)
        assert results['status'] == 'success'
        # Check task self-validation
        task.validate_result(results)

        # Check scan consumer validation
        schema_ref = pop_schema_ref(results)
        schema = load_worker_schema(schema_ref)
        jsonschema.validate(results, schema)

        short_name = 'LGPL 2.1 or later'
        details = results['details']
        assert details.get(
            'files_count') is not None and details.get('files_count') > 0
        assert short_name in details.get('licenses', {})
        summary = results['summary']
        assert short_name in summary.get('sure_licenses', [])
Пример #2
0
    def validate_result(self, result):
        """Ensure that results comply with the task schema, if defined.

        Tasks define a schema by setting schema_ref appropriately.
        Schemas are retrieved from workers/schemas/generated via pkgutil.
        """
        # Skip validation if no schema is defined
        schema_ref = self.schema_ref
        if schema_ref is None:
            return
        # Load schema if not yet loaded
        schema = self._schema
        if schema is None:
            schema = self._schema = load_worker_schema(schema_ref)
        # Validate result against schema
        jsonschema.validate(result, schema)
        # Record the validated schema details
        set_schema_ref(result, schema_ref)
Пример #3
0
    def validate_result(self, result):
        """Ensure that results comply with the task schema, if defined.

        Tasks define a schema by setting schema_ref appropriately.
        Schemas are retrieved from workers/schemas/generated via pkgutil.
        """
        # Skip validation if no schema is defined
        schema_ref = self.schema_ref
        if schema_ref is None:
            return
        # Load schema if not yet loaded
        schema = self._schema
        if schema is None:
            schema = self._schema = load_worker_schema(schema_ref)
        # Validate result against schema
        try:
            jsonschema.validate(result, schema)
        except jsonschema.exceptions.ValidationError as e:
            raise FatalTaskError(
                'Schema validation failed: {e}'.format(e=str(e)))
        # Record the validated schema details
        set_schema_ref(result, schema_ref)