Skip to content

Commit 8d97ff4

Browse files
committed
Add unit test for the verify-project management command
Signed-off-by: tdruez <[email protected]>
1 parent 4d1b0f8 commit 8d97ff4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

scanpipe/management/commands/verify-project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ def handle(self, *args, **options):
9696
if errors:
9797
raise CommandError("Project verification failed:\n" + "\n".join(errors))
9898

99-
self.stdout.write(self.style.SUCCESS("Project verification passed."))
99+
self.stdout.write("Project verification passed.", self.style.SUCCESS)

scanpipe/tests/test_commands.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,49 @@ def test_scanpipe_management_command_report(self):
13711371
expected = ("project1", "file.ext", "file", "file.ext", "requires-review")
13721372
self.assertEqual(expected, row1[0:5])
13731373

1374+
def test_scanpipe_management_command_verify_project(self):
1375+
project = make_project(name="my_project")
1376+
make_package(project, package_url="pkg:generic/[email protected]")
1377+
make_dependency(project)
1378+
1379+
out = StringIO()
1380+
call_command(
1381+
"verify-project",
1382+
"--project",
1383+
project.name,
1384+
"--packages",
1385+
"1",
1386+
"--vulnerable-packages",
1387+
"0",
1388+
"--dependencies",
1389+
"1",
1390+
"--vulnerable-dependencies",
1391+
"0",
1392+
stdout=out,
1393+
)
1394+
self.assertIn("Project verification passed.", out.getvalue())
1395+
1396+
out = StringIO()
1397+
expected = (
1398+
"Project verification failed:\n"
1399+
"Expected at least 5 packages, found 1\n"
1400+
"Expected exactly 10 vulnerable packages, found 0\n"
1401+
"Expected at least 5 dependencies, found 1"
1402+
)
1403+
with self.assertRaisesMessage(CommandError, expected):
1404+
call_command(
1405+
"verify-project",
1406+
"--project",
1407+
project.name,
1408+
"--packages",
1409+
"5",
1410+
"--vulnerable-packages",
1411+
"10",
1412+
"--dependencies",
1413+
"5",
1414+
stdout=out,
1415+
)
1416+
13741417

13751418
class ScanPipeManagementCommandMixinTest(TestCase):
13761419
class CreateProjectCommand(

0 commit comments

Comments
 (0)