Merge pull request #7019 from chrismeyersfsu/fix-6960

require that insights projects have insights cred
This commit is contained in:
Chris Meyers 2017-07-12 13:05:05 -04:00 committed by GitHub
commit 77e25b236d
2 changed files with 18 additions and 1 deletions

View File

@ -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'."))

View File

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