Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dojo/url/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ def get_queryset(self) -> QuerySet[URL]:
return URL.objects.annotate(
active_findings=Coalesce(active_finding_subquery, Value(0)),
)

def perform_destroy(self, instance):
instance.location.delete()
13 changes: 13 additions & 0 deletions unittests/test_rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,19 @@ def test_update_object_not_authorized(self):
response = self.client.put(relative_url, self.payload)
self.assertEqual(403, response.status_code, response.content[:1000])

def test_delete_removes_location(self):
"""Verify that deleting a URL via the API also deletes the associated Location."""
url_obj = URL.objects.get(pk=self.delete_id)
location_id = url_obj.location_id
self.assertTrue(Location.objects.filter(pk=location_id).exists())

relative_url = f"{self.url}{location_id}/"
response = self.client.delete(relative_url)
self.assertEqual(204, response.status_code, response.content[:1000])

self.assertFalse(Location.objects.filter(pk=location_id).exists())
self.assertFalse(URL.objects.filter(pk=self.delete_id).exists())


@versioned_fixtures
class EngagementTest(BaseClass.RelatedObjectsTest, BaseClass.BaseClassTest):
Expand Down
Loading