mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
require that insights projects have insights cred
This commit is contained in:
@@ -140,7 +140,9 @@ class ProjectOptions(models.Model):
|
|||||||
if not self.scm_type:
|
if not self.scm_type:
|
||||||
return None
|
return None
|
||||||
cred = self.credential
|
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 self.scm_type == 'insights':
|
||||||
if cred.kind != 'insights':
|
if cred.kind != 'insights':
|
||||||
raise ValidationError(_("Credential kind must be 'insights'."))
|
raise ValidationError(_("Credential kind must be 'insights'."))
|
||||||
|
|||||||
15
awx/main/tests/unit/models/test_project.py
Normal file
15
awx/main/tests/unit/models/test_project.py
Normal 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.']))
|
||||||
|
|
||||||
Reference in New Issue
Block a user