def test_get_license_analysis_for_stack_with_empty_param(_mock_post): """Test with empty normalized_packages.""" result = la.get_license_analysis_for_stack({}) _mock_post.assert_called_once() assert isinstance(result, LicenseAnalysis) assert result.conflict_packages is None assert result.unknown_licenses is None assert result.outlier_packages is None
def test_get_license_analysis_for_stack_unknown_licenses(_mock_post): """Test for unknown license result.""" # really unknown with open("tests/data/license_unknown.json", "r") as f: _mock_post.return_value = json.loads(f.read()) result = la.get_license_analysis_for_stack(_get_normalized_packages()) _mock_post.assert_called_once() assert isinstance(result, LicenseAnalysis) assert result.conflict_packages == [] assert result.outlier_packages == [] assert result.unknown_licenses.component_conflict == [] assert len(result.unknown_licenses.unknown) == 1 assert result.unknown_licenses.unknown[0].package == 'p1' assert result.unknown_licenses.unknown[0].license == 'REDHAT'
def get_result(self) -> StackAggregatorResult: """Aggregate stack data.""" # denormalize package details according to request.dependencies relations package_details = self._get_denormalized_package_details() unknown_dependencies = self._get_direct_unknown_packages() started_at = time.time() license_analysis = get_license_analysis_for_stack(package_details) logger.info( '%s took %0.2f secs for get_license_analysis_for_stack()', self._request.external_request_id, time.time() - started_at) return StackAggregatorResult(**self._request.dict(exclude={'packages'}), analyzed_dependencies=package_details, unknown_dependencies=unknown_dependencies, license_analysis=license_analysis, registration_link=AGGREGATOR_SETTINGS.snyk_signin_url)
def test_get_license_analysis_for_stack_conflict_packages(_mock_post): """Test for unknown license result.""" # conflict_packages with open("tests/data/license_component_conflict.json", "r") as f: _mock_post.return_value = json.loads(f.read()) result = la.get_license_analysis_for_stack(_get_normalized_packages()) _mock_post.assert_called_once() assert isinstance(result, LicenseAnalysis) assert len(result.conflict_packages) == 1 assert result.conflict_packages[0].package1 == 'package1' assert result.conflict_packages[0].package2 == 'package2' assert result.conflict_packages[0].license1 == 'license1' assert result.conflict_packages[0].license2 == 'license2' assert result.unknown_licenses.unknown == [] assert len(result.unknown_licenses.component_conflict) == 1 assert result.unknown_licenses.component_conflict[0].package == 'p2' assert (result.unknown_licenses.component_conflict[0].conflict_licenses[0]. license1 == 'apache 2.0') assert (result.unknown_licenses.component_conflict[0].conflict_licenses[0]. license2 == 'gplv2')