Skip to content

Commit 4da9b62

Browse files
committed
Create tests for new CodebaseResource methods #447
* Update walk test to also test for new parent and sibling related methods on CodebaseResource * Remove has_sibling method from CodebaseResource Signed-off-by: Jono Yang <[email protected]>
1 parent 1981cb2 commit 4da9b62

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

scanpipe/models.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,15 +1640,6 @@ def parent(self, codebase=None):
16401640
parent_path = self.parent_path()
16411641
return parent_path and self.project.codebaseresources.get(path=parent_path)
16421642

1643-
def has_siblings(self, codebase=None):
1644-
"""
1645-
Return True is this CodebaseResource has siblings.
1646-
1647-
`codebase` is not used in this context but required for compatibility
1648-
with the commoncode.resource.Codebase class API.
1649-
"""
1650-
return self.has_parent() and self.parent(codebase).has_children()
1651-
16521643
def siblings(self, codebase=None):
16531644
"""
16541645
Return a sequence of sibling Resource objects for this Resource

scanpipe/pipes/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def update_or_create_dependencies(project, dependency_data):
113113
"""
114114
for_package_uid = dependency_data.get("for_package_uid")
115115
try:
116-
dependency = DiscoveredDependency.objects.get(
117-
project=project,
116+
dependency = project.discovereddependencys.get(
118117
dependency_uid=dependency_data.get("dependency_uid"),
119118
for_package_uid=for_package_uid,
120119
)

scanpipe/tests/test_models.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,33 @@ def test_scanpipe_codebase_resource_model_walk_method(self):
12001200
]
12011201
self.assertEqual(expected_bottom_up_paths, bottom_up_paths)
12021202

1203+
# Test parent-related methods
1204+
asgiref_resource = self.project_asgiref.codebaseresources.get(
1205+
path="asgiref-3.3.0.whl-extract/asgiref/compatibility.py"
1206+
)
1207+
expected_parent_path = "asgiref-3.3.0.whl-extract/asgiref"
1208+
self.assertEqual(expected_parent_path, asgiref_resource.parent_path())
1209+
self.assertTrue(asgiref_resource.has_parent())
1210+
expected_parent = self.project_asgiref.codebaseresources.get(
1211+
path="asgiref-3.3.0.whl-extract/asgiref"
1212+
)
1213+
self.assertEqual(expected_parent, asgiref_resource.parent())
1214+
1215+
# Test sibling-related methods
1216+
expected_siblings = [
1217+
"asgiref-3.3.0.whl-extract/asgiref/__init__.py",
1218+
"asgiref-3.3.0.whl-extract/asgiref/compatibility.py",
1219+
"asgiref-3.3.0.whl-extract/asgiref/current_thread_executor.py",
1220+
"asgiref-3.3.0.whl-extract/asgiref/local.py",
1221+
"asgiref-3.3.0.whl-extract/asgiref/server.py",
1222+
"asgiref-3.3.0.whl-extract/asgiref/sync.py",
1223+
"asgiref-3.3.0.whl-extract/asgiref/testing.py",
1224+
"asgiref-3.3.0.whl-extract/asgiref/timeout.py",
1225+
"asgiref-3.3.0.whl-extract/asgiref/wsgi.py",
1226+
]
1227+
asgiref_resource_siblings = [r.path for r in asgiref_resource.siblings()]
1228+
self.assertEqual(sorted(expected_siblings), sorted(asgiref_resource_siblings))
1229+
12031230
@mock.patch("requests.post")
12041231
def test_scanpipe_webhook_subscription_send_method(self, mock_post):
12051232
webhook = self.project1.add_webhook_subscription("https://localhost")

0 commit comments

Comments
 (0)