mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 22:07:36 -02:30
exception for dual-name questions and more tests
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import mock
|
||||
import pytest
|
||||
import json
|
||||
|
||||
from awx.main.utils import timestamp_apiformat
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils import timezone
|
||||
from awx.main.models.jobs import JobTemplate
|
||||
|
||||
def mock_feature_enabled(feature, bypass_database=None):
|
||||
return True
|
||||
@@ -40,6 +38,65 @@ def test_survey_spec_view_allowed(deploy_jobtemplate, get, user):
|
||||
response = get(spec_url, user('admin', True))
|
||||
|
||||
assert response.status_code == 200
|
||||
print response.data
|
||||
|
||||
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.survey
|
||||
def test_survey_spec_sucessful_creation(deploy_jobtemplate, post, user):
|
||||
spec_url = reverse('api:job_template_survey_spec', args=(deploy_jobtemplate.id,))
|
||||
response = post(
|
||||
url=spec_url,
|
||||
data={
|
||||
"description": "Email of the submitter",
|
||||
"spec": [{
|
||||
"variable": "submitter_email",
|
||||
"question_name": "Enter your email",
|
||||
"type": "text",
|
||||
"required": False
|
||||
}],
|
||||
"name": "Email survey"
|
||||
},
|
||||
user=user('admin', True))
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.survey
|
||||
def test_survey_spec_non_dict_error(deploy_jobtemplate, post, user):
|
||||
spec_url = reverse('api:job_template_survey_spec', args=(deploy_jobtemplate.id,))
|
||||
response = post(
|
||||
url=spec_url,
|
||||
data={"description": "Email of the submitter",
|
||||
"spec": ["What is your email?"], "name": "Email survey"},
|
||||
user=user('admin', True))
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.data['error'] == "survey element 0 is not a json object"
|
||||
|
||||
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.survey
|
||||
def test_survey_spec_dual_names_error(deploy_jobtemplate, post, user):
|
||||
spec_url = reverse('api:job_template_survey_spec', args=(deploy_jobtemplate.id,))
|
||||
response = post(
|
||||
url=spec_url,
|
||||
data={
|
||||
"description": "Email of the submitter",
|
||||
"spec": [{
|
||||
"variable": "submitter_email",
|
||||
"question_name": "Enter your email",
|
||||
"type": "text",
|
||||
"required": False
|
||||
}, {
|
||||
"variable": "submitter_email",
|
||||
"question_name": "Same variable as last question",
|
||||
"type": "integer",
|
||||
"required": False
|
||||
}],
|
||||
"name": "Email survey"
|
||||
},
|
||||
user=user('admin', True))
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.data['error'] == "'variable' name 'submitter_email' duplicated in survey element 1"
|
||||
|
||||
Reference in New Issue
Block a user