From f7f12be0ad1138226cec9a3b550cb7bfa869e9d1 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Mon, 9 Sep 2013 18:54:29 -0400 Subject: [PATCH] AC-132. Auto-update a new project using SCM when saved. --- awx/main/models/__init__.py | 4 ++++ awx/main/tests/projects.py | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index 39e07cfefd..82235b3c70 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -701,6 +701,10 @@ class Project(CommonModel): slug_name = slugify(unicode(self.name)).replace(u'-', u'_') self.local_path = u'_%d__%s' % (self.pk, slug_name) self.save(update_fields=['local_path']) + # If we just created a new project with SCM and it doesn't require any + # passwords to update, start the initial update. + if new_instance and self.scm_type and not self.scm_passwords_needed: + self.update() @property def needs_scm_password(self): diff --git a/awx/main/tests/projects.py b/awx/main/tests/projects.py index 33ac9bc00a..72efef629d 100644 --- a/awx/main/tests/projects.py +++ b/awx/main/tests/projects.py @@ -663,10 +663,14 @@ class ProjectUpdatesTest(BaseTransactionTest): def check_project_scm(self, project): project_path = project.get_project_path(check_if_exists=False) - # Initial checkout. - self.assertFalse(os.path.exists(project_path)) - self.check_project_update(project) - self.assertTrue(os.path.exists(project_path)) + # If project could be auto-updated on creation, the project dir should + # already exist, otherwise run an initial checkout. + if project.scm_type and not project.scm_passwords_needed: + self.assertTrue(os.path.exists(project_path)) + else: + self.assertFalse(os.path.exists(project_path)) + self.check_project_update(project) + self.assertTrue(os.path.exists(project_path)) # Stick a new untracked file in the project. untracked_path = os.path.join(project_path, 'yadayada.txt') self.assertFalse(os.path.exists(untracked_path)) @@ -961,8 +965,10 @@ class ProjectUpdatesTest(BaseTransactionTest): scm_url=scm_url, scm_update_on_launch=True, ) - self.check_project_update(self.project) + # First update triggered by saving a new project with SCM. self.assertEqual(self.project.project_updates.count(), 1) + self.check_project_update(self.project) + self.assertEqual(self.project.project_updates.count(), 2) job_template = self.create_test_job_template() job = self.create_test_job(job_template=job_template) self.assertEqual(job.status, 'new') @@ -971,7 +977,7 @@ class ProjectUpdatesTest(BaseTransactionTest): self.assertEqual(job.status, 'pending') job = Job.objects.get(pk=job.pk) self.assertTrue(job.status in ('successful', 'failed')) - self.assertEqual(self.project.project_updates.count(), 2) + self.assertEqual(self.project.project_updates.count(), 3) def test_update_on_launch_with_project_passwords(self): scm_url = getattr(settings, 'TEST_GIT_PRIVATE_HTTPS', '')