|
33 | 33 | from django.core.management import call_command |
34 | 34 | from django.test import TestCase |
35 | 35 |
|
| 36 | +import openpyxl |
36 | 37 | import xlsxwriter |
37 | 38 | from licensedcode.cache import get_licensing |
38 | 39 | from lxml import etree |
|
42 | 43 | from scanpipe.models import CodebaseResource |
43 | 44 | from scanpipe.models import Project |
44 | 45 | from scanpipe.models import ProjectMessage |
| 46 | +from scanpipe.pipes import flag |
45 | 47 | from scanpipe.pipes import output |
46 | 48 | from scanpipe.tests import FIXTURES_REGEN |
47 | 49 | from scanpipe.tests import make_dependency |
48 | 50 | from scanpipe.tests import make_package |
| 51 | +from scanpipe.tests import make_resource_file |
49 | 52 | from scanpipe.tests import mocked_now |
50 | 53 | from scanpipe.tests import package_data1 |
51 | 54 |
|
@@ -210,16 +213,30 @@ def test_scanpipe_pipes_outputs_to_xlsx(self): |
210 | 213 | model="Model", |
211 | 214 | details={}, |
212 | 215 | ) |
| 216 | + make_resource_file( |
| 217 | + project=project, path="path/file1.ext", status=flag.REQUIRES_REVIEW |
| 218 | + ) |
213 | 219 |
|
214 | 220 | output_file = output.to_xlsx(project=project) |
215 | 221 | self.assertIn(output_file.name, project.output_root) |
216 | 222 |
|
217 | 223 | # Make sure the output can be generated even if the work_directory was wiped |
218 | 224 | shutil.rmtree(project.work_directory) |
219 | | - with self.assertNumQueries(8): |
| 225 | + with self.assertNumQueries(9): |
220 | 226 | output_file = output.to_xlsx(project=project) |
221 | 227 | self.assertIn(output_file.name, project.output_root) |
222 | 228 |
|
| 229 | + workbook = openpyxl.load_workbook(output_file, read_only=True, data_only=True) |
| 230 | + expected_sheet_names = [ |
| 231 | + "PACKAGES", |
| 232 | + "DEPENDENCIES", |
| 233 | + "RESOURCES", |
| 234 | + "RELATIONS", |
| 235 | + "MESSAGES", |
| 236 | + "TODOS", |
| 237 | + ] |
| 238 | + self.assertEqual(expected_sheet_names, workbook.get_sheet_names()) |
| 239 | + |
223 | 240 | def test_scanpipe_pipes_outputs_vulnerability_as_cyclonedx(self): |
224 | 241 | component_bom_ref = "pkg:pypi/[email protected]" |
225 | 242 | data = self.data / "cyclonedx/django-4.0.10-vulnerability.json" |
@@ -480,6 +497,34 @@ def test_scanpipe_pipes_outputs_to_attribution(self): |
480 | 497 | output_file = output.to_attribution(project=project) |
481 | 498 | self.assertEqual("EMPTY_TEMPLATE", output_file.read_text()) |
482 | 499 |
|
| 500 | + def test_scanpipe_pipes_outputs_get_todos_data(self): |
| 501 | + project = Project.objects.create(name="Analysis") |
| 502 | + todos_data = output.get_todos_data(project) |
| 503 | + self.assertEqual([], list(todos_data)) |
| 504 | + |
| 505 | + make_resource_file( |
| 506 | + project=project, path="path/file1.ext", status=flag.REQUIRES_REVIEW |
| 507 | + ) |
| 508 | + make_resource_file(project=project, path="path/file2.ext") |
| 509 | + |
| 510 | + todos_data = output.get_todos_data(project) |
| 511 | + expected = [ |
| 512 | + { |
| 513 | + "path": "path/file1.ext", |
| 514 | + "status": "requires-review", |
| 515 | + "size": None, |
| 516 | + "name": "file1.ext", |
| 517 | + "extension": ".ext", |
| 518 | + "programming_language": "", |
| 519 | + "mime_type": "", |
| 520 | + "tag": "path", |
| 521 | + "detected_license_expression": "", |
| 522 | + "compliance_alert": "", |
| 523 | + "project__name": "Analysis", |
| 524 | + } |
| 525 | + ] |
| 526 | + self.assertEqual(expected, list(todos_data)) |
| 527 | + |
483 | 528 |
|
484 | 529 | class ScanPipeXLSXOutputPipesTest(TestCase): |
485 | 530 | def test__add_xlsx_worksheet_does_truncates_long_strings_over_max_len(self): |
|
0 commit comments