Skip to content

Commit 0da5530

Browse files
committed
Add unit test for get_best_checksum_matches #688
Signed-off-by: Thomas Druez <tdruez@nexb.com>
1 parent 8ef6dc6 commit 0da5530

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

scanpipe/pipelines/develop_to_deploy.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class DevelopToDeploy(Pipeline):
3535
@classmethod
3636
def steps(cls):
3737
return (
38-
# cls.get_inputs,
39-
# cls.extract_inputs_to_codebase_directory,
40-
# cls.extract_archives_in_place,
41-
# cls.collect_and_create_codebase_resources,
42-
# cls.tag_empty_and_ignored_files,
38+
cls.get_inputs,
39+
cls.extract_inputs_to_codebase_directory,
40+
cls.extract_archives_in_place,
41+
cls.collect_and_create_codebase_resources,
42+
cls.tag_empty_and_ignored_files,
4343
cls.checksum_match,
44-
# cls.purldb_match,
44+
cls.purldb_match,
4545
cls.java_to_class_match,
4646
cls.path_match,
4747
)
@@ -84,7 +84,6 @@ def tag_empty_and_ignored_files(self):
8484

8585
def checksum_match(self):
8686
"""Match using SHA1 checksum."""
87-
self.project.codebaserelations.all().delete()
8887
d2d.checksum_match(project=self.project, checksum_field="sha1", logger=self.log)
8988

9089
def purldb_match(self):

scanpipe/pipes/d2d.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def _resource_path_match(to_resource, from_resources):
148148
matches = from_resources.filter(path__endswith=f"/{current_path}")
149149

150150
if len(matches) > len(current_parts):
151+
to_resource.status = "too-many-matches"
152+
to_resource.save()
151153
break
152154

153155
for match in matches:

scanpipe/templates/scanpipe/relation_list.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<tr>
3737
{% if forloop.first %}
3838
<td class="break-all" rowspan="{{ resource.related_from.all|length }}">
39-
<a href="{{ resource.get_absolute_url }}">{{ resource.path }}</a>
39+
<a href="{{ resource.get_absolute_url }}#viewer">{{ resource.path }}</a>
4040
</td>
4141
{% endif %}
4242
<td>
@@ -49,13 +49,13 @@
4949
{% endif %}
5050
</td>
5151
<td class="break-all">
52-
<a href="{{ relation.from_resource.get_absolute_url }}">{{ relation.from_resource.path }}</a>
52+
<a href="{{ relation.from_resource.get_absolute_url }}#viewer">{{ relation.from_resource.path }}</a>
5353
</td>
5454
</tr>
5555
{% empty %}
5656
<tr>
5757
<td class="break-all">
58-
<a class="has-text-danger" href="{{ resource.get_absolute_url }}">{{ resource.path }}</a>
58+
<a class="has-text-danger" href="{{ resource.get_absolute_url }}#viewer">{{ resource.path }}</a>
5959
</td>
6060
<td></td>
6161
<td></td>

scanpipe/tests/pipes/test_d2d.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from django.test import TestCase
2626

27+
from scanpipe.models import CodebaseResource
2728
from scanpipe.models import Project
2829
from scanpipe.pipes import d2d
2930

@@ -58,3 +59,21 @@ def test_scanpipe_d2d_get_extracted_subpath(self):
5859

5960
path = "a.jar-extract/subpath/b.jar-extract/subpath/file.ext"
6061
self.assertEqual("subpath/file.ext", d2d.get_extracted_subpath(path))
62+
63+
def test_scanpipe_d2d_get_best_checksum_matches_same_name(self):
64+
to_1 = CodebaseResource(name="package-1.0.ext", path="to/package-1.0.ext")
65+
to_2 = CodebaseResource(name="package-2.0.ext", path="to/package-2.0.ext")
66+
from_1 = CodebaseResource(name="package-1.0.ext", path="from/package-1.0.ext")
67+
from_2 = CodebaseResource(name="package-2.0.ext", path="from/package-2.0.ext")
68+
matches = [from_1, from_2]
69+
self.assertEqual([from_1], d2d.get_best_checksum_matches(to_1, matches))
70+
self.assertEqual([from_2], d2d.get_best_checksum_matches(to_2, matches))
71+
72+
def test_scanpipe_d2d_get_best_checksum_matches_extracted_subpath(self):
73+
to_1 = CodebaseResource(path="to/jar-extract/a/package-1.0.ext")
74+
to_2 = CodebaseResource(path="to/jar-extract/a/package-2.0.ext")
75+
from_1 = CodebaseResource(path="from/src/a/package-1.0.ext")
76+
from_2 = CodebaseResource(path="from/src/a/package-2.0.ext")
77+
matches = [from_1, from_2]
78+
self.assertEqual([from_1], d2d.get_best_checksum_matches(to_1, matches))
79+
self.assertEqual([from_2], d2d.get_best_checksum_matches(to_2, matches))

0 commit comments

Comments
 (0)