Skip to content

Commit 2b5b2f7

Browse files
committed
update parent_path to display root files on empty string instead of None to align with the code format
Signed-off-by: Aayush Kumar <aayush214.kumar@gmail.com>
1 parent d163577 commit 2b5b2f7

File tree

5 files changed

+6
-7
lines changed

5 files changed

+6
-7
lines changed

scanpipe/migrations/0074_codebaseresource_parent_path_and_more.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Migration(migrations.Migration):
1313
migrations.AddField(
1414
model_name='codebaseresource',
1515
name='parent_path',
16-
field=models.CharField(blank=True, help_text='The path of the resource\'s parent directory. Set to None for top-level (root) resources. Used to efficiently retrieve a directory\'s contents.', max_length=2000, null=True),
16+
field=models.CharField(blank=True, help_text='The path of the resource\'s parent directory. Set to None for top-level (root) resources. Used to efficiently retrieve a directory\'s contents.', max_length=2000),
1717
),
1818
migrations.AddIndex(
1919
model_name='codebaseresource',

scanpipe/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,6 @@ class CodebaseResource(
26982698

26992699
parent_path = models.CharField(
27002700
max_length=2000,
2701-
null=True,
27022701
blank=True,
27032702
help_text=_(
27042703
"The path of the resource's parent directory. "
@@ -2815,7 +2814,7 @@ def __str__(self):
28152814

28162815
def save(self, *args, **kwargs):
28172816
if self.path and not self.parent_path:
2818-
self.parent_path = self.parent_directory()
2817+
self.parent_path = self.parent_directory() or ""
28192818
super().save(*args, **kwargs)
28202819

28212820
def get_absolute_url(self):

scanpipe/pipes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def make_codebase_resource(project, location, save=True, **extra_fields):
7474
parent_path = str(relative_path.parent)
7575

7676
if parent_path == ".":
77-
parent_path = None
77+
parent_path = ""
7878

7979
try:
8080
resource_data = scancode.get_resource_info(location=str(location))

scanpipe/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ def test_scanpipe_can_compute_compliance_alert_for_license_exceptions(self):
16481648
def test_scanpipe_codebase_root_parent_path(self):
16491649
resource1 = self.project1.codebaseresources.create(path="file")
16501650

1651-
self.assertIsNone(resource1.parent_path)
1651+
self.assertEqual("", resource1.parent_path)
16521652

16531653
def test_scanpipe_codebase_regular_parent_path(self):
16541654
resource2 = self.project1.codebaseresources.create(path="dir1/dir2/file")

scanpipe/tests/test_pipelines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def test_scanpipe_scan_codebase_creates_top_level_paths(self):
879879

880880
expected_top_level_paths = ["is-npm-1.0.0.tgz", "is-npm-1.0.0.tgz-extract"]
881881

882-
top_level_resources = project1.codebaseresources.filter(parent_path=None)
882+
top_level_resources = project1.codebaseresources.filter(parent_path="")
883883
top_level_paths = [resource.path for resource in top_level_resources]
884884

885885
self.assertListEqual(top_level_paths, expected_top_level_paths)
@@ -905,7 +905,7 @@ def test_scanpipe_scan_codebase_creates_parent_path_field(self):
905905
"is-npm-1.0.0.tgz-extract/package/readme.md",
906906
]
907907

908-
top_level_resources = project1.codebaseresources.filter(parent_path=None)
908+
top_level_resources = project1.codebaseresources.filter(parent_path="")
909909
top_level_paths = [resource.path for resource in top_level_resources]
910910

911911
self.assertListEqual(top_level_paths, expected_top_level_paths)

0 commit comments

Comments
 (0)