|
48 | 48 | from scanpipe.models import WebhookSubscription |
49 | 49 | from scanpipe.pipes import flag |
50 | 50 | from scanpipe.pipes import purldb |
| 51 | +from scanpipe.pipes.output import PRINT_SUPPORTED_FORMATS |
| 52 | +from scanpipe.pipes.output import SUPPORTED_FORMATS as PIPE_SUPPORTED_FORMATS |
51 | 53 | from scanpipe.tests import filter_warnings |
52 | 54 | from scanpipe.tests import make_dependency |
53 | 55 | from scanpipe.tests import make_mock_response |
@@ -756,6 +758,29 @@ def test_scanpipe_management_command_output(self): |
756 | 758 | self.assertIn('"bomFormat": "CycloneDX"', out_value) |
757 | 759 | self.assertIn('"specVersion": "1.5",', out_value) |
758 | 760 |
|
| 761 | + def test_supported_formats_sync(self): |
| 762 | + """ |
| 763 | + Ensure SUPPORTED_FORMATS in management/commands/output.py always matches |
| 764 | + the canonical list in pipes/output.py, and that PRINT_SUPPORTED_FORMATS |
| 765 | + is a strict subset of SUPPORTED_FORMATS (never includes csv or xlsx). |
| 766 | + """ |
| 767 | + from scanpipe.management.commands.output import SUPPORTED_FORMATS as CMD_FORMATS |
| 768 | + |
| 769 | + self.assertEqual( |
| 770 | + set(PIPE_SUPPORTED_FORMATS), |
| 771 | + set(CMD_FORMATS), |
| 772 | + "SUPPORTED_FORMATS in management/commands/output.py is out of sync " |
| 773 | + "with pipes/output.py. Update one of them.", |
| 774 | + ) |
| 775 | + # PRINT_SUPPORTED_FORMATS must be a subset of SUPPORTED_FORMATS |
| 776 | + self.assertTrue( |
| 777 | + set(PRINT_SUPPORTED_FORMATS).issubset(set(PIPE_SUPPORTED_FORMATS)), |
| 778 | + "PRINT_SUPPORTED_FORMATS contains formats not in SUPPORTED_FORMATS.", |
| 779 | + ) |
| 780 | + # csv and xlsx must never be in PRINT_SUPPORTED_FORMATS (--print incompatible) |
| 781 | + self.assertNotIn("csv", PRINT_SUPPORTED_FORMATS) |
| 782 | + self.assertNotIn("xlsx", PRINT_SUPPORTED_FORMATS) |
| 783 | + |
759 | 784 | def test_scanpipe_management_command_delete_project(self): |
760 | 785 | project = make_project(name="my_project") |
761 | 786 | work_path = project.work_path |
@@ -984,6 +1009,31 @@ def test_scanpipe_management_command_run(self): |
984 | 1009 | json_data = json.loads(out.getvalue()) |
985 | 1010 | self.assertEqual(3, len(json_data["files"])) |
986 | 1011 |
|
| 1012 | + # Test --format spdx |
| 1013 | + out = StringIO() |
| 1014 | + with redirect_stdout(out): |
| 1015 | + call_command("run", "do_nothing", input_location, "--format", "spdx") |
| 1016 | + out_value = out.getvalue() |
| 1017 | + self.assertIn('"spdxVersion":', out_value) |
| 1018 | + |
| 1019 | + # Test --format cyclonedx |
| 1020 | + out = StringIO() |
| 1021 | + with redirect_stdout(out): |
| 1022 | + call_command("run", "do_nothing", input_location, "--format", "cyclonedx") |
| 1023 | + out_value = out.getvalue() |
| 1024 | + self.assertIn('"bomFormat": "CycloneDX"', out_value) |
| 1025 | + |
| 1026 | + # Test --format ort-package-list |
| 1027 | + # do_nothing pipeline doesn't find packages, so it generates an empty list, but it shouldn't crash |
| 1028 | + out = StringIO() |
| 1029 | + with redirect_stdout(out): |
| 1030 | + call_command("run", "do_nothing", input_location, "--format", "ort-package-list") |
| 1031 | + |
| 1032 | + # Test incompatible streaming formats are rejected by argparse choices |
| 1033 | + expected = "Error: argument --format: invalid choice: 'csv'" |
| 1034 | + with self.assertRaisesMessage(CommandError, expected): |
| 1035 | + call_command("run", "do_nothing", input_location, "--format", "csv") |
| 1036 | + |
987 | 1037 | # Multiple pipeline and selected_groups are supported |
988 | 1038 | out = StringIO() |
989 | 1039 | with redirect_stdout(out): |
|
0 commit comments