From 376170124e9205a2a1e8d10705c6a94f534fbc4a Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 12 Jul 2017 12:24:11 -0400 Subject: [PATCH] require that insights projects have insights cred --- awx/main/models/projects.py | 4 +++- awx/main/tests/unit/models/test_project.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 awx/main/tests/unit/models/test_project.py diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index 4275661437..a73c021a96 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -140,7 +140,9 @@ class ProjectOptions(models.Model): if not self.scm_type: return None cred = self.credential - if cred: + if not cred and self.scm_type == 'insights': + raise ValidationError(_("Insights Credential is required for an Insights Project.")) + elif cred: if self.scm_type == 'insights': if cred.kind != 'insights': raise ValidationError(_("Credential kind must be 'insights'.")) diff --git a/awx/main/tests/unit/models/test_project.py b/awx/main/tests/unit/models/test_project.py new file mode 100644 index 0000000000..82e34339f8 --- /dev/null +++ b/awx/main/tests/unit/models/test_project.py @@ -0,0 +1,15 @@ +import pytest +import json +from awx.main.models import ( + Project, +) +from django.core.exceptions import ValidationError + + +def test_clean_credential_insights(): + proj = Project(name="myproj", credential=None, scm_type='insights') + with pytest.raises(ValidationError) as e: + proj.clean_credential() + + assert json.dumps(str(e.value)) == json.dumps(str([u'Insights Credential is required for an Insights Project.'])) +