Skip to content

Commit b0ef77a

Browse files
committed
add tests
Signed-off-by: Aayush Kumar <aayush214.kumar@gmail.com>
1 parent 912fc7f commit b0ef77a

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

scanpipe/tests/test_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,16 @@ def test_scanpipe_codebase_resource_model_compliance_alert_update_fields(self):
15931593
# Reset the index value
15941594
scanpipe_app.license_policies_index = None
15951595

1596+
def test_scanpipe_codebase_root_parent_directory_path(self):
1597+
resource1 = self.project1.codebaseresources.create(path="file")
1598+
1599+
self.assertEqual("", resource1.parent_directory_path)
1600+
1601+
def test_scanpipe_codebase_regular_parent_directory_path(self):
1602+
resource2 = self.project1.codebaseresources.create(path="dir1/dir2/file")
1603+
1604+
self.assertEqual("dir1/dir2", resource2.parent_directory_path)
1605+
15961606
def test_scanpipe_scan_fields_model_mixin_methods(self):
15971607
expected = [
15981608
"detected_license_expression",

scanpipe/tests/test_pipelines.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,64 @@ def test_scanpipe_scan_codebase_pipeline_integration(self):
860860
expected_file = self.data / "scancode" / "is-npm-1.0.0_scan_codebase.json"
861861
self.assertPipelineResultEqual(expected_file, result_file)
862862

863+
def test_scanpipe_scan_codebase_creates_top_level_paths(self):
864+
pipeline_name = "scan_codebase"
865+
project1 = make_project()
866+
867+
filename = "is-npm-1.0.0.tgz"
868+
input_location = self.data / "scancode" / filename
869+
project1.copy_input_from(input_location)
870+
871+
run = project1.add_pipeline(pipeline_name)
872+
pipeline = run.make_pipeline_instance()
873+
874+
exitcode, out = pipeline.execute()
875+
self.assertEqual(0, exitcode, msg=out)
876+
877+
expected_top_level_paths = ["is-npm-1.0.0.tgz", "is-npm-1.0.0.tgz-extract"]
878+
879+
top_level_resources = project1.codebaseresources.filter(
880+
parent_directory_path=None
881+
)
882+
top_level_paths = [res.path for res in top_level_resources]
883+
884+
self.assertListEqual(top_level_paths, expected_top_level_paths)
885+
886+
def test_scanpipe_scan_codebase_creates_parent_directory_path_field(self):
887+
pipeline_name = "scan_codebase"
888+
project1 = make_project()
889+
890+
filename = "is-npm-1.0.0.tgz"
891+
input_location = self.data / "scancode" / filename
892+
project1.copy_input_from(input_location)
893+
894+
run = project1.add_pipeline(pipeline_name)
895+
pipeline = run.make_pipeline_instance()
896+
897+
exitcode, out = pipeline.execute()
898+
self.assertEqual(0, exitcode, msg=out)
899+
900+
expected_top_level_paths = ["is-npm-1.0.0.tgz", "is-npm-1.0.0.tgz-extract"]
901+
expected_nested_paths = [
902+
"is-npm-1.0.0.tgz-extract/package/index.js",
903+
"is-npm-1.0.0.tgz-extract/package/package.json",
904+
"is-npm-1.0.0.tgz-extract/package/readme.md",
905+
]
906+
907+
top_level_resources = project1.codebaseresources.filter(
908+
parent_directory_path=None
909+
)
910+
top_level_paths = [res.path for res in top_level_resources]
911+
912+
self.assertListEqual(top_level_paths, expected_top_level_paths)
913+
914+
nested_resources = project1.codebaseresources.filter(
915+
parent_directory_path="is-npm-1.0.0.tgz-extract/package"
916+
)
917+
nested_paths = [res.path for res in nested_resources]
918+
919+
self.assertListEqual(nested_paths, expected_nested_paths)
920+
863921
def test_scanpipe_inspect_packages_creates_packages_npm(self):
864922
pipeline_name = "inspect_packages"
865923
project1 = make_project()

0 commit comments

Comments
 (0)