diff --git a/scanpipe/models.py b/scanpipe/models.py index 9d4501f1d..39d025da5 100644 --- a/scanpipe/models.py +++ b/scanpipe/models.py @@ -569,7 +569,7 @@ def _raise_if_run_in_progress(self): ) def setup_work_directory(self): - """Create all of the work_directory structure and skips if already existing.""" + """Create all the work_directory structure and skips if already existing.""" for subdirectory in self.WORK_DIRECTORIES: Path(self.work_directory, subdirectory).mkdir(parents=True, exist_ok=True) diff --git a/scanpipe/templates/scanpipe/relation_list.html b/scanpipe/templates/scanpipe/relation_list.html index b7547e775..7f9456dbf 100644 --- a/scanpipe/templates/scanpipe/relation_list.html +++ b/scanpipe/templates/scanpipe/relation_list.html @@ -44,9 +44,9 @@ {% if relation.extra_data.path_score %} {{ relation.extra_data.path_score }} {% endif %} - {% if relation.match_type == "path" %} + {% if relation.match_type == "path" and resource.is_text and relation.from_resource.is_text %}
- diff + diff {% if relation.extra_data.diff_ratio %} ratio: {{ relation.extra_data.diff_ratio }} {% endif %} diff --git a/scanpipe/tests/test_views.py b/scanpipe/tests/test_views.py index 37b4d979e..cf289f526 100644 --- a/scanpipe/tests/test_views.py +++ b/scanpipe/tests/test_views.py @@ -31,6 +31,7 @@ from scanpipe.models import CodebaseResource from scanpipe.models import Project +from scanpipe.pipes.input import copy_inputs from scanpipe.tests import license_policies_index from scanpipe.views import ProjectDetailView @@ -459,3 +460,37 @@ def test_scanpipe_views_codebase_resource_details_annotations_missing_policy(sel '{"start_line": 1, "end_line": 2, "text": null, "className": "ace_info"}' ) self.assertContains(response, expected) + + def test_scanpipe_views_codebase_relation_diff_view(self): + url = reverse("resource_diff", args=[self.project1.uuid]) + data = { + "from_path": "", + "to_path": "", + } + response = self.client.get(url, data=data) + expected = "The requested resource was not found on this server." + self.assertContains(response, expected, status_code=404) + + resource_files = [ + self.data_location / "codebase" / "a.txt", + self.data_location / "codebase" / "b.txt", + ] + copy_inputs(resource_files, self.project1.codebase_path) + resource1 = CodebaseResource.objects.create( + project=self.project1, + path="a.txt", + type=CodebaseResource.Type.FILE, + is_text=True, + ) + resource2 = CodebaseResource.objects.create( + project=self.project1, + path="b.txt", + type=CodebaseResource.Type.FILE, + is_text=True, + ) + data = { + "from_path": resource1.path, + "to_path": resource2.path, + } + response = self.client.get(url, data=data) + self.assertContains(response, '