mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Merge pull request #1610 from AlanCoding/group_related
Include related Jobs in group deletion protection
This commit is contained in:
commit
71d2a4b4cf
@ -960,7 +960,10 @@ class Group(CommonModelNameNotUnique, RelatedJobsMixin):
|
||||
RelatedJobsMixin
|
||||
'''
|
||||
def _get_related_jobs(self):
|
||||
return InventoryUpdate.objects.filter(inventory_source__in=self.inventory_sources.all())
|
||||
return UnifiedJob.objects.non_polymorphic().filter(
|
||||
Q(Job___inventory=self.inventory) |
|
||||
Q(InventoryUpdate___inventory_source__groups=self)
|
||||
)
|
||||
|
||||
|
||||
class InventorySourceOptions(BaseModel):
|
||||
|
@ -12,6 +12,7 @@ from awx.main.models import (
|
||||
Inventory,
|
||||
InventorySource,
|
||||
InventoryUpdate,
|
||||
Job
|
||||
)
|
||||
from awx.main.utils.filters import SmartFilter
|
||||
|
||||
@ -99,6 +100,29 @@ class TestSCMUpdateFeatures:
|
||||
assert not mck_update.called
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestRelatedJobs:
|
||||
|
||||
def test_inventory_related(self, inventory):
|
||||
job = Job.objects.create(
|
||||
inventory=inventory
|
||||
)
|
||||
assert job.id in [jerb.id for jerb in inventory._get_related_jobs()]
|
||||
|
||||
def test_related_group_jobs(self, group):
|
||||
job = Job.objects.create(
|
||||
inventory=group.inventory
|
||||
)
|
||||
assert job.id in [jerb.id for jerb in group._get_related_jobs()]
|
||||
|
||||
def test_related_group_update(self, group):
|
||||
src = group.inventory_sources.create(name='foo')
|
||||
job = InventoryUpdate.objects.create(
|
||||
inventory_source=src
|
||||
)
|
||||
assert job.id in [jerb.id for jerb in group._get_related_jobs()]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestSCMClean:
|
||||
def test_clean_update_on_project_update_multiple(self, inventory):
|
||||
|
Loading…
Reference in New Issue
Block a user