From 064dd6dc082412e7ddcea6ec02b82e0fd906b455 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Mon, 7 Apr 2014 14:18:59 -0400 Subject: [PATCH] Fix up unit tests where we no longer allow posting a schedule to an inventory source that is not a cloud source --- awx/main/models/inventory.py | 3 +++ awx/main/signals.py | 1 + awx/main/tests/schedules.py | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index e2d82254c2..5c85105ab4 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -37,6 +37,7 @@ from awx.main.utils import encrypt_field __all__ = ['Inventory', 'Host', 'Group', 'InventorySource', 'InventoryUpdate'] +logger = logging.getLogger('awx.main.models.inventory') class Inventory(CommonModel): ''' @@ -123,6 +124,7 @@ class Inventory(CommonModel): ''' Update model fields that are computed from database relationships. ''' + logger.debug("Going to update inventory computed fields") if update_hosts: for host in self.hosts.filter(active=True): host.update_computed_fields(update_inventory=False, @@ -154,6 +156,7 @@ class Inventory(CommonModel): computed_fields.pop(field) if computed_fields: self.save(update_fields=computed_fields.keys()) + logger.debug("Finished updating inventory computed fields") @property def root_groups(self): diff --git a/awx/main/signals.py b/awx/main/signals.py index 0c85a7bd90..36b46f2e22 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -60,6 +60,7 @@ def update_inventory_computed_fields(sender, **kwargs): Signal handler and wrapper around inventory.update_computed_fields to prevent unnecessary recursive calls. ''' + logger.debug("In update inventory computed fields") if getattr(_inventory_updates, 'is_updating', False): return instance = kwargs['instance'] diff --git a/awx/main/tests/schedules.py b/awx/main/tests/schedules.py index 573a29e059..cf7089a213 100644 --- a/awx/main/tests/schedules.py +++ b/awx/main/tests/schedules.py @@ -65,10 +65,15 @@ class ScheduleTest(BaseTest): self.diff_org_user = self.make_user('fred') self.organizations[1].users.add(self.diff_org_user) + self.cloud_source = Credential.objects.create(kind='awx', user=self.super_django_user, + username='Dummy', password='Dummy') + self.first_inventory = Inventory.objects.create(name='test_inventory', description='for org 0', organization=self.organizations[0]) self.first_inventory.hosts.create(name='host_1') self.first_inventory_group = self.first_inventory.groups.create(name='group_1') self.first_inventory_source = self.first_inventory_group.inventory_source + self.first_inventory_source.source = 'ec2' + self.first_inventory_source.save() inv_read = Permission.objects.create( inventory = self.first_inventory, @@ -80,12 +85,19 @@ class ScheduleTest(BaseTest): self.second_inventory.hosts.create(name='host_2') self.second_inventory_group = self.second_inventory.groups.create(name='group_2') self.second_inventory_source = self.second_inventory_group.inventory_source + self.second_inventory_source.source = 'ec2' + self.second_inventory_source.save() self.first_schedule = Schedule.objects.create(name='test_schedule_1', unified_job_template=self.first_inventory_source, enabled=True, rrule=GOOD_SCHEDULES[0]) self.second_schedule = Schedule.objects.create(name='test_schedule_2', unified_job_template=self.second_inventory_source, enabled=True, rrule=GOOD_SCHEDULES[0]) + self.without_valid_source_inventory = Inventory.objects.create(name='without valid source', description='for org 0', organization=self.organizations[0]) + self.without_valid_source_inventory.hosts.create(name='host_3') + self.without_valid_source_inventory_group = self.without_valid_source_inventory.groups.create(name='not valid source') + self.without_valid_source_inventory_source = self.without_valid_source_inventory_group.inventory_source + def test_schedules_list(self): url = reverse('api:schedule_list') enabled_schedules = Schedule.objects.filter(enabled=True).distinct() @@ -141,6 +153,13 @@ class ScheduleTest(BaseTest): with self.current_user(self.diff_org_user): data = self.post(first_url, data=diff_user_schedule, expect=403) + def test_post_schedule_to_non_cloud_source(self): + invalid_inv_url = reverse('api:inventory_source_schedules_list', args=(self.without_valid_source_inventory_source.pk,)) + new_schedule = dict(name='newsched_1', description='newsched', enabled=True, rrule=GOOD_SCHEDULES[0]) + + with self.current_user(self.super_django_user): + self.post(invalid_inv_url, data=new_schedule, expect=400) + def test_update_existing_schedule(self): first_url = reverse('api:inventory_source_schedules_list', args=(self.first_inventory_source.pk,))