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.'])) +