Skip to content

Commit db94a74

Browse files
committed
Add test for assemble_packages #444
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent c9bc83e commit db94a74

2 files changed

Lines changed: 259 additions & 0 deletions

File tree

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
{
2+
"headers": [
3+
{
4+
"tool_name": "scancode-toolkit",
5+
"tool_version": "31.0.0rc5",
6+
"options": {
7+
"input": [
8+
"/tmp/test"
9+
],
10+
"--info": true,
11+
"--json-pp": "/home/jono/Desktop/package_assembly_codebase.json",
12+
"--package": true
13+
},
14+
"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.",
15+
"start_timestamp": "2022-08-12T011956.852635",
16+
"end_timestamp": "2022-08-12T011959.120759",
17+
"output_format_version": "2.0.0",
18+
"duration": 2.2681386470794678,
19+
"message": null,
20+
"errors": [],
21+
"warnings": [],
22+
"extra_data": {
23+
"system_environment": {
24+
"operating_system": "linux",
25+
"cpu_architecture": "64",
26+
"platform": "Linux-5.4.0-122-generic-x86_64-with-glibc2.27",
27+
"platform_version": "#138~18.04.1-Ubuntu SMP Fri Jun 24 14:14:03 UTC 2022",
28+
"python_version": "3.10.4 (main, May 22 2022, 00:46:26) [GCC 7.5.0]"
29+
},
30+
"spdx_license_list_version": "3.17",
31+
"files_count": 3
32+
}
33+
}
34+
],
35+
"dependencies": [],
36+
"packages": [],
37+
"files": [
38+
{
39+
"path": "test",
40+
"type": "directory",
41+
"name": "test",
42+
"base_name": "test",
43+
"extension": "",
44+
"size": 0,
45+
"date": null,
46+
"sha1": null,
47+
"md5": null,
48+
"sha256": null,
49+
"mime_type": null,
50+
"file_type": null,
51+
"programming_language": null,
52+
"is_binary": false,
53+
"is_text": false,
54+
"is_archive": false,
55+
"is_media": false,
56+
"is_source": false,
57+
"is_script": false,
58+
"package_data": [],
59+
"for_packages": [],
60+
"files_count": 3,
61+
"dirs_count": 2,
62+
"size_count": 63,
63+
"scan_errors": []
64+
},
65+
{
66+
"path": "test/get_package_resources",
67+
"type": "directory",
68+
"name": "get_package_resources",
69+
"base_name": "get_package_resources",
70+
"extension": "",
71+
"size": 0,
72+
"date": null,
73+
"sha1": null,
74+
"md5": null,
75+
"sha256": null,
76+
"mime_type": null,
77+
"file_type": null,
78+
"programming_language": null,
79+
"is_binary": false,
80+
"is_text": false,
81+
"is_archive": false,
82+
"is_media": false,
83+
"is_source": false,
84+
"is_script": false,
85+
"package_data": [],
86+
"for_packages": [],
87+
"files_count": 3,
88+
"dirs_count": 1,
89+
"size_count": 63,
90+
"scan_errors": []
91+
},
92+
{
93+
"path": "test/get_package_resources/package.json",
94+
"type": "file",
95+
"name": "package.json",
96+
"base_name": "package",
97+
"extension": ".json",
98+
"size": 63,
99+
"date": "2022-07-27",
100+
"sha1": "47ad6746a065a22a4c2a119cb425c250bddfbf88",
101+
"md5": "5cbb43ca814ec801e8673e348e8eec19",
102+
"sha256": "aac331f407d4d662a2897eafeb4f05a1c2343218220d99779c9553d3b92bd4ac",
103+
"mime_type": "application/json",
104+
"file_type": "JSON data",
105+
"programming_language": null,
106+
"is_binary": false,
107+
"is_text": true,
108+
"is_archive": false,
109+
"is_media": false,
110+
"is_source": false,
111+
"is_script": false,
112+
"package_data": [
113+
{
114+
"type": "npm",
115+
"namespace": null,
116+
"name": "test",
117+
"version": "0.1.0",
118+
"qualifiers": {},
119+
"subpath": null,
120+
"primary_language": "JavaScript",
121+
"description": null,
122+
"release_date": null,
123+
"parties": [],
124+
"keywords": [],
125+
"homepage_url": null,
126+
"download_url": "https://registry.npmjs.org/test/-/test-0.1.0.tgz",
127+
"size": null,
128+
"sha1": null,
129+
"md5": null,
130+
"sha256": null,
131+
"sha512": null,
132+
"bug_tracking_url": null,
133+
"code_view_url": null,
134+
"vcs_url": null,
135+
"copyright": null,
136+
"license_expression": "mit",
137+
"declared_license": [
138+
"MIT"
139+
],
140+
"notice_text": null,
141+
"source_packages": [],
142+
"file_references": [],
143+
"extra_data": {},
144+
"dependencies": [],
145+
"repository_homepage_url": "https://www.npmjs.com/package/test",
146+
"repository_download_url": "https://registry.npmjs.org/test/-/test-0.1.0.tgz",
147+
"api_data_url": "https://registry.npmjs.org/test/0.1.0",
148+
"datasource_id": "npm_package_json",
149+
"purl": "pkg:npm/test@0.1.0"
150+
}
151+
],
152+
"for_packages": [],
153+
"files_count": 0,
154+
"dirs_count": 0,
155+
"size_count": 0,
156+
"scan_errors": []
157+
},
158+
{
159+
"path": "test/get_package_resources/this-should-be-returned",
160+
"type": "file",
161+
"name": "this-should-be-returned",
162+
"base_name": "this-should-be-returned",
163+
"extension": "",
164+
"size": 0,
165+
"date": "2022-07-27",
166+
"sha1": null,
167+
"md5": null,
168+
"sha256": null,
169+
"mime_type": "inode/x-empty",
170+
"file_type": "empty",
171+
"programming_language": null,
172+
"is_binary": false,
173+
"is_text": true,
174+
"is_archive": false,
175+
"is_media": false,
176+
"is_source": false,
177+
"is_script": false,
178+
"package_data": [],
179+
"for_packages": [],
180+
"files_count": 0,
181+
"dirs_count": 0,
182+
"size_count": 0,
183+
"scan_errors": []
184+
},
185+
{
186+
"path": "test/get_package_resources/node_modules",
187+
"type": "directory",
188+
"name": "node_modules",
189+
"base_name": "node_modules",
190+
"extension": "",
191+
"size": 0,
192+
"date": null,
193+
"sha1": null,
194+
"md5": null,
195+
"sha256": null,
196+
"mime_type": null,
197+
"file_type": null,
198+
"programming_language": null,
199+
"is_binary": false,
200+
"is_text": false,
201+
"is_archive": false,
202+
"is_media": false,
203+
"is_source": false,
204+
"is_script": false,
205+
"package_data": [],
206+
"for_packages": [],
207+
"files_count": 1,
208+
"dirs_count": 0,
209+
"size_count": 0,
210+
"scan_errors": []
211+
},
212+
{
213+
"path": "test/get_package_resources/node_modules/this-should-not-be-returned",
214+
"type": "file",
215+
"name": "this-should-not-be-returned",
216+
"base_name": "this-should-not-be-returned",
217+
"extension": "",
218+
"size": 0,
219+
"date": "2022-07-27",
220+
"sha1": null,
221+
"md5": null,
222+
"sha256": null,
223+
"mime_type": "inode/x-empty",
224+
"file_type": "empty",
225+
"programming_language": null,
226+
"is_binary": false,
227+
"is_text": true,
228+
"is_archive": false,
229+
"is_media": false,
230+
"is_source": false,
231+
"is_script": false,
232+
"package_data": [],
233+
"for_packages": [],
234+
"files_count": 0,
235+
"dirs_count": 0,
236+
"size_count": 0,
237+
"scan_errors": []
238+
}
239+
]
240+
}

scanpipe/tests/test_pipes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,25 @@ def test_scanpipe_pipes_scancode_make_results_summary(self):
615615
summary = scancode.make_results_summary(project, scan_results_location)
616616
self.assertEqual(10, len(summary.keys()))
617617

618+
def test_scanpipe_pipes_scancode_assemble_packages(self):
619+
project = Project.objects.create(name="Analysis")
620+
project_scan_location = self.data_location / "package_assembly_codebase.json"
621+
scancode.create_inventory_from_scan(project, project_scan_location)
622+
623+
self.assertEqual(0, project.discoveredpackages.count())
624+
scancode.assemble_packages(project)
625+
self.assertEqual(1, project.discoveredpackages.count())
626+
627+
package = project.discoveredpackages.all()[0]
628+
self.assertEqual("pkg:npm/test@0.1.0", package.package_url)
629+
630+
associated_resources = [r.path for r in package.codebase_resources.all()]
631+
expected_resources = [
632+
"get_package_resources/package.json",
633+
"get_package_resources/this-should-be-returned",
634+
]
635+
self.assertEquals(sorted(expected_resources), sorted(associated_resources))
636+
618637
@expectedFailure
619638
def test_scanpipe_pipes_codebase_get_tree(self):
620639
fixtures = self.data_location / "asgiref-3.3.0_fixtures.json"

0 commit comments

Comments
 (0)