From e30de4e5d7bedbd28896e2951c8671e438d4546f Mon Sep 17 00:00:00 2001 From: tdruez Date: Mon, 3 Jun 2024 15:35:33 +0400 Subject: [PATCH] Rename resolved_dependencies to resolved_from_dependencies #1066 Signed-off-by: tdruez --- ...e.py => 0060_discovereddependency_renames.py} | 16 +++++++++++++++- scanpipe/models.py | 2 +- scanpipe/tests/test_models.py | 12 ++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) rename scanpipe/migrations/{0060_rename_resolved_to_discovereddependency_resolved_to_package_and_more.py => 0060_discovereddependency_renames.py} (52%) diff --git a/scanpipe/migrations/0060_rename_resolved_to_discovereddependency_resolved_to_package_and_more.py b/scanpipe/migrations/0060_discovereddependency_renames.py similarity index 52% rename from scanpipe/migrations/0060_rename_resolved_to_discovereddependency_resolved_to_package_and_more.py rename to scanpipe/migrations/0060_discovereddependency_renames.py index 2525ced30..dbdfd267b 100644 --- a/scanpipe/migrations/0060_rename_resolved_to_discovereddependency_resolved_to_package_and_more.py +++ b/scanpipe/migrations/0060_discovereddependency_renames.py @@ -1,5 +1,6 @@ -# Generated by Django 5.0.6 on 2024-06-03 08:20 +# Generated by Django 5.0.6 on 2024-06-03 11:32 +import django.db.models.deletion from django.db import migrations, models @@ -15,6 +16,19 @@ class Migration(migrations.Migration): old_name="resolved_to", new_name="resolved_to_package", ), + migrations.AlterField( + model_name="discovereddependency", + name="resolved_to_package", + field=models.ForeignKey( + blank=True, + editable=False, + help_text="The resolved package for this dependency. If empty, it indicates the dependency is unresolved.", + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="resolved_from_dependencies", + to="scanpipe.discoveredpackage", + ), + ), migrations.AddField( model_name="discoveredpackage", name="children_packages", diff --git a/scanpipe/models.py b/scanpipe/models.py index 081a4bbe0..8a5027946 100644 --- a/scanpipe/models.py +++ b/scanpipe/models.py @@ -3386,7 +3386,7 @@ class DiscoveredDependency( ) resolved_to_package = models.ForeignKey( DiscoveredPackage, - related_name="resolved_dependencies", + related_name="resolved_from_dependencies", help_text=_( "The resolved package for this dependency. " "If empty, it indicates the dependency is unresolved." diff --git a/scanpipe/tests/test_models.py b/scanpipe/tests/test_models.py index 94db44ede..a156fc24f 100644 --- a/scanpipe/tests/test_models.py +++ b/scanpipe/tests/test_models.py @@ -2124,7 +2124,7 @@ def test_scanpipe_discovered_dependency_model_many_to_many(self): a_b = make_dependency(project, for_package=a, resolved_to_package=b) b_c = make_dependency(project, for_package=b, resolved_to_package=c) - # *_packages fields return Package QuerySet + # *_packages fields return DiscoveredPackage QuerySet self.assertEqual([b], list(a.children_packages.all())) self.assertEqual([], list(a.parent_packages.all())) self.assertEqual([c], list(b.children_packages.all())) @@ -2132,13 +2132,13 @@ def test_scanpipe_discovered_dependency_model_many_to_many(self): self.assertEqual([], list(c.children_packages.all())) self.assertEqual([b], list(c.parent_packages.all())) - # *_dependencies fields return Dependency QuerySet + # *_dependencies fields return DiscoveredDependency QuerySet self.assertEqual([a_b], list(a.declared_dependencies.all())) - self.assertEqual([], list(a.resolved_dependencies.all())) + self.assertEqual([], list(a.resolved_from_dependencies.all())) self.assertEqual([b_c], list(b.declared_dependencies.all())) - self.assertEqual([a_b], list(b.resolved_dependencies.all())) + self.assertEqual([a_b], list(b.resolved_from_dependencies.all())) self.assertEqual([], list(c.declared_dependencies.all())) - self.assertEqual([b_c], list(c.resolved_dependencies.all())) + self.assertEqual([b_c], list(c.resolved_from_dependencies.all())) def test_scanpipe_discovered_dependency_model_is_vulnerable_property(self): package = DiscoveredPackage.create_from_data(self.project1, package_data1) @@ -2164,7 +2164,7 @@ def test_scanpipe_package_model_integrity_with_toolkit_package_model(self): "compliance_alert", "tag", "declared_dependencies", - "resolved_dependencies", + "resolved_from_dependencies", ] package_data_only_field = ["datasource_id", "dependencies"]