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', [])
def test_error(self): data = "/this-is-not-a-real-directory" 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') with pytest.raises(Exception): results = task.execute(arguments=args)
def test_error(self): """Start the LicenseCheckTask worker task with improper parameters and test its results.""" data = "/this-is-not-a-real-directory" 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') res = task.execute(arguments=args) assert res is None
def _transform_licenses(self): if self._raw_data.get('LicenseUrl'): from f8a_worker.process import IndianaJones # download_file # It's here due to circular dependencies from f8a_worker.workers import LicenseCheckTask # run_scancode self._data['declared_licenses'] = [self._raw_data['LicenseUrl']] with TemporaryDirectory() as tmpdir: try: # Get file from 'LicenseUrl' and let LicenseCheckTask decide what license it is if IndianaJones.download_file(self._raw_data['LicenseUrl'], tmpdir): scancode_results = LicenseCheckTask.run_scancode( tmpdir) if scancode_results.get('summary', {}).get('sure_licenses'): self._data['declared_licenses'] = \ scancode_results['summary']['sure_licenses'] except Exception: # Don't raise if IndianaJones or LicenseCheckTask fail pass
def _handle_dotnet_solution(self, data): """Handle nuget package metadata.""" # TODO: reduce cyclomatic complexity if not data.get('Metadata'): return {} data = data['Metadata'] key_map = ( ('Id', 'name'), ('Description', ), ('ProjectUrl', 'homepage'), # ('Summary',), ('Copyright',), # ('RequireLicenseAcceptance', 'require_license_acceptance'), ) transformed = self.transform_keys(data, key_map) if data.get('Authors'): transformed['author'] = ','.join(data['Authors']) if data.get('LicenseUrl'): from f8a_worker.process import IndianaJones # download_file # It's here due to circular dependencies from f8a_worker.workers import LicenseCheckTask # run_scancode transformed['declared_licenses'] = [data['LicenseUrl']] with TemporaryDirectory() as tmpdir: try: # Get file from 'LicenseUrl' and let LicenseCheckTask decide what license it is if IndianaJones.download_file(data['LicenseUrl'], tmpdir): scancode_results = LicenseCheckTask.run_scancode( tmpdir) if scancode_results.get('summary', {}).get('sure_licenses'): transformed['declared_licenses'] = \ scancode_results['summary']['sure_licenses'] except Exception: # Don't raise if IndianaJones or LicenseCheckTask fail pass # transform # "DependencyGroups": [ # { # "Packages": [ # { # "Id": "NETStandard.Library", # "VersionRange": {"OriginalString": "1.6.0"} # } # ] # } # ] # to ["NETStandard.Library 1.6.0"] deps = set() for dep_group in data.get('DependencyGroups', []): for package in dep_group.get('Packages', []): deps.add('{} {}'.format( package.get('Id', ''), package.get('VersionRange', {}).get('OriginalString', ''))) if deps: transformed['dependencies'] = list(deps) repository = data.get('Repository') if isinstance(repository, dict) and repository: transformed['code_repository'] = { 'type': repository.get('Type'), 'url': repository.get('Url') } elif 'ProjectUrl' in data: transformed['code_repository'] = self._identify_gh_repo( data['ProjectUrl']) version = data.get('Version') if isinstance(version, dict) and version: transformed['version'] = '{}.{}.{}'.format( version.get('Major', ''), version.get('Minor', ''), version.get('Patch', '')) if data.get('Tags'): transformed['keywords'] = self._split_keywords(data['Tags']) return transformed