Skip to content

Commit

Permalink
Add test for assemble_packages #444
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Aug 24, 2022
1 parent 138a43f commit 902b6d0
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 0 deletions.
240 changes: 240 additions & 0 deletions scanpipe/tests/data/package_assembly_codebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
{
"headers": [
{
"tool_name": "scancode-toolkit",
"tool_version": "31.0.0rc5",
"options": {
"input": [
"/tmp/test"
],
"--info": true,
"--json-pp": "/home/jono/Desktop/package_assembly_codebase.json",
"--package": true
},
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"start_timestamp": "2022-08-12T011956.852635",
"end_timestamp": "2022-08-12T011959.120759",
"output_format_version": "2.0.0",
"duration": 2.2681386470794678,
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"system_environment": {
"operating_system": "linux",
"cpu_architecture": "64",
"platform": "Linux-5.4.0-122-generic-x86_64-with-glibc2.27",
"platform_version": "#138~18.04.1-Ubuntu SMP Fri Jun 24 14:14:03 UTC 2022",
"python_version": "3.10.4 (main, May 22 2022, 00:46:26) [GCC 7.5.0]"
},
"spdx_license_list_version": "3.17",
"files_count": 3
}
}
],
"dependencies": [],
"packages": [],
"files": [
{
"path": "test",
"type": "directory",
"name": "test",
"base_name": "test",
"extension": "",
"size": 0,
"date": null,
"sha1": null,
"md5": null,
"sha256": null,
"mime_type": null,
"file_type": null,
"programming_language": null,
"is_binary": false,
"is_text": false,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"package_data": [],
"for_packages": [],
"files_count": 3,
"dirs_count": 2,
"size_count": 63,
"scan_errors": []
},
{
"path": "test/get_package_resources",
"type": "directory",
"name": "get_package_resources",
"base_name": "get_package_resources",
"extension": "",
"size": 0,
"date": null,
"sha1": null,
"md5": null,
"sha256": null,
"mime_type": null,
"file_type": null,
"programming_language": null,
"is_binary": false,
"is_text": false,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"package_data": [],
"for_packages": [],
"files_count": 3,
"dirs_count": 1,
"size_count": 63,
"scan_errors": []
},
{
"path": "test/get_package_resources/package.json",
"type": "file",
"name": "package.json",
"base_name": "package",
"extension": ".json",
"size": 63,
"date": "2022-07-27",
"sha1": "47ad6746a065a22a4c2a119cb425c250bddfbf88",
"md5": "5cbb43ca814ec801e8673e348e8eec19",
"sha256": "aac331f407d4d662a2897eafeb4f05a1c2343218220d99779c9553d3b92bd4ac",
"mime_type": "application/json",
"file_type": "JSON data",
"programming_language": null,
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"package_data": [
{
"type": "npm",
"namespace": null,
"name": "test",
"version": "0.1.0",
"qualifiers": {},
"subpath": null,
"primary_language": "JavaScript",
"description": null,
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": null,
"download_url": "https://registry.npmjs.org/test/-/test-0.1.0.tgz",
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"license_expression": "mit",
"declared_license": [
"MIT"
],
"notice_text": null,
"source_packages": [],
"file_references": [],
"extra_data": {},
"dependencies": [],
"repository_homepage_url": "https://www.npmjs.com/package/test",
"repository_download_url": "https://registry.npmjs.org/test/-/test-0.1.0.tgz",
"api_data_url": "https://registry.npmjs.org/test/0.1.0",
"datasource_id": "npm_package_json",
"purl": "pkg:npm/[email protected]"
}
],
"for_packages": [],
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
},
{
"path": "test/get_package_resources/this-should-be-returned",
"type": "file",
"name": "this-should-be-returned",
"base_name": "this-should-be-returned",
"extension": "",
"size": 0,
"date": "2022-07-27",
"sha1": null,
"md5": null,
"sha256": null,
"mime_type": "inode/x-empty",
"file_type": "empty",
"programming_language": null,
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"package_data": [],
"for_packages": [],
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
},
{
"path": "test/get_package_resources/node_modules",
"type": "directory",
"name": "node_modules",
"base_name": "node_modules",
"extension": "",
"size": 0,
"date": null,
"sha1": null,
"md5": null,
"sha256": null,
"mime_type": null,
"file_type": null,
"programming_language": null,
"is_binary": false,
"is_text": false,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"package_data": [],
"for_packages": [],
"files_count": 1,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
},
{
"path": "test/get_package_resources/node_modules/this-should-not-be-returned",
"type": "file",
"name": "this-should-not-be-returned",
"base_name": "this-should-not-be-returned",
"extension": "",
"size": 0,
"date": "2022-07-27",
"sha1": null,
"md5": null,
"sha256": null,
"mime_type": "inode/x-empty",
"file_type": "empty",
"programming_language": null,
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"package_data": [],
"for_packages": [],
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
}
]
}
19 changes: 19 additions & 0 deletions scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,25 @@ def test_scanpipe_pipes_scancode_make_results_summary(self):
summary = scancode.make_results_summary(project, scan_results_location)
self.assertEqual(10, len(summary.keys()))

def test_scanpipe_pipes_scancode_assemble_packages(self):
project = Project.objects.create(name="Analysis")
project_scan_location = self.data_location / "package_assembly_codebase.json"
scancode.create_inventory_from_scan(project, project_scan_location)

self.assertEqual(0, project.discoveredpackages.count())
scancode.assemble_packages(project)
self.assertEqual(1, project.discoveredpackages.count())

package = project.discoveredpackages.all()[0]
self.assertEqual("pkg:npm/[email protected]", package.package_url)

associated_resources = [r.path for r in package.codebase_resources.all()]
expected_resources = [
"get_package_resources/package.json",
"get_package_resources/this-should-be-returned",
]
self.assertEquals(sorted(expected_resources), sorted(associated_resources))

@expectedFailure
def test_scanpipe_pipes_codebase_get_tree(self):
fixtures = self.data_location / "asgiref-3.3.0_fixtures.json"
Expand Down

0 comments on commit 902b6d0

Please sign in to comment.