Skip to content

Commit

Permalink
Add more unit test for the project management command #13
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Sep 17, 2020
1 parent fd6b57a commit 879b1dd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

if __name__ == "__main__":
from scancodeio import command_line

command_line()
4 changes: 1 addition & 3 deletions scancodeio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# Visit https://github.com/nexB/scancode.io for support and download.

import os
from pathlib import Path
import sys
from pathlib import Path

from django.conf import settings

Expand Down Expand Up @@ -61,5 +61,3 @@ def command_line():

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "scancodeio.settings")
execute_from_command_line(sys.argv)


35 changes: 31 additions & 4 deletions scanpipe/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,41 @@ def test_scanpipe_management_command_graph(self):
self.assertIn("DockerPipeline.png", out_value)
self.assertTrue(Path(f"/{temp_dir}/DockerPipeline.png").exists())

def test_scanpipe_management_command_createproject(self):
def test_scanpipe_management_command_createproject_base(self):
out = StringIO()

with self.assertRaises(CommandError) as error:
call_command("createproject", stderr=out)
expected = "Error: the following arguments are required: name"
self.assertEqual(expected, str(error.exception))
with self.assertRaisesMessage(CommandError, expected):
call_command("createproject", stdout=out)

call_command("createproject", "my_project", stdout=out)
self.assertIn("Project my_project created", out.getvalue())
self.assertTrue(Project.objects.get(name="my_project"))

with self.assertRaises(SystemExit):
call_command("createproject", "my_project", stderr=out)
expected = "Project with this Name already exists."
self.assertIn(expected, out.getvalue())

def test_scanpipe_management_command_createproject_with_pipelines(self):
out = StringIO()

options = ["--pipeline", "non-existing.py"]
with self.assertRaises(SystemExit):
call_command("createproject", "my_project", *options, stderr=out)
self.assertIn("non-existing.py is not a valid pipeline", out.getvalue())

options = [
"--pipeline",
"scanpipe/pipelines/docker.py",
"--pipeline",
"scanpipe/pipelines/root_filesystems.py",
]
call_command("createproject", "my_project", *options, stdout=out)
self.assertIn("Project my_project created", out.getvalue())
project = Project.objects.get(name="my_project")
expected = [
"scanpipe/pipelines/docker.py",
"scanpipe/pipelines/root_filesystems.py",
]
self.assertEqual(expected, [run.pipeline for run in project.runs.all()])
23 changes: 19 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,24 @@
"Topic :: Utilities",
],
keywords=[
"open source", "scan", "license", "package", "dependency",
"copyright", "filetype", "author", "extract", "licensing",
"scancode", "scanpipe", "docker", "rootfs", "vm", "virtual machine",
"pipeline", "code analysis", "container",
"open source",
"scan",
"license",
"package",
"dependency",
"copyright",
"filetype",
"author",
"extract",
"licensing",
"scancode",
"scanpipe",
"docker",
"rootfs",
"vm",
"virtual machine",
"pipeline",
"code analysis",
"container",
],
)

0 comments on commit 879b1dd

Please sign in to comment.