Don't return ids for deleted credential/inventory for ad hoc commands. Fixes https://trello.com/c/ps2bW38Q

This commit is contained in:
Chris Church 2015-04-16 14:31:23 -04:00
parent 3f98b40ed7
commit 6dda8e58ad
2 changed files with 15 additions and 0 deletions

View File

@ -1543,6 +1543,10 @@ class AdHocCommandSerializer(UnifiedJobSerializer):
if parent_model in (Host, Group):
ret.pop('inventory', None)
ret.pop('limit', None)
if 'inventory' in ret and (not obj.inventory or not obj.inventory.active):
ret['inventory'] = None
if 'credential' in ret and (not obj.credential or not obj.credential.active):
ret['credential'] = None
return ret

View File

@ -567,8 +567,10 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
self.assertEqual(url, response['url'])
with self.current_user('admin'):
response = self.get(url, expect=200)
self.assertEqual(response['credential'], self.credential.pk)
self.assertEqual(response['related']['credential'],
reverse('api:credential_detail', args=(self.credential.pk,)))
self.assertEqual(response['inventory'], self.inventory.pk)
self.assertEqual(response['related']['inventory'],
reverse('api:inventory_detail', args=(self.inventory.pk,)))
self.assertTrue(response['related']['stdout'])
@ -600,6 +602,15 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
self.patch(url, {}, expect=401)
self.delete(url, expect=401)
# Verify that the credential and inventory are null when they have
# been deleted.
self.credential.mark_inactive()
self.inventory.mark_inactive()
with self.current_user('admin'):
response = self.get(url, expect=200)
self.assertEqual(response['credential'], None)
self.assertEqual(response['inventory'], None)
def test_ad_hoc_command_cancel(self):
# Override setting so that ad hoc command isn't actually started.
with self.settings(CELERY_UNIT_TEST=False):