mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 08:37:48 -02:30
JT survey license check test migrations
This commit is contained in:
@@ -3,6 +3,7 @@ import pytest
|
|||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from awx.main.models.jobs import JobTemplate
|
from awx.main.models.jobs import JobTemplate
|
||||||
|
from awx.api.license import LicenseForbids
|
||||||
|
|
||||||
def mock_feature_enabled(feature, bypass_database=None):
|
def mock_feature_enabled(feature, bypass_database=None):
|
||||||
return True
|
return True
|
||||||
@@ -10,6 +11,9 @@ def mock_feature_enabled(feature, bypass_database=None):
|
|||||||
def mock_feature_disabled(feature, bypass_database=None):
|
def mock_feature_disabled(feature, bypass_database=None):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def mock_check_license(self, add_host=False, feature=None, check_expiration=True):
|
||||||
|
raise LicenseForbids("Feature %s is not enabled in the active license" % feature)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def survey_jobtemplate(project, inventory, credential):
|
def survey_jobtemplate(project, inventory, credential):
|
||||||
return JobTemplate.objects.create(
|
return JobTemplate.objects.create(
|
||||||
@@ -24,12 +28,41 @@ def survey_jobtemplate(project, inventory, credential):
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.survey
|
@pytest.mark.survey
|
||||||
def test_survey_spec_view_denied(deploy_jobtemplate, get, user):
|
def test_survey_spec_view_denied(deploy_jobtemplate, get, user):
|
||||||
|
# TODO: Test non-enterprise license
|
||||||
spec_url = reverse('api:job_template_survey_spec', args=(deploy_jobtemplate.id,))
|
spec_url = reverse('api:job_template_survey_spec', args=(deploy_jobtemplate.id,))
|
||||||
response = get(spec_url, user('admin', True))
|
response = get(spec_url, user('admin', True))
|
||||||
|
|
||||||
assert response.status_code == 402
|
assert response.status_code == 402
|
||||||
assert response.data['detail'] == 'Your license does not allow adding surveys.'
|
assert response.data['detail'] == 'Your license does not allow adding surveys.'
|
||||||
|
|
||||||
|
@mock.patch('awx.main.access.BaseAccess.check_license', mock_check_license)
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@pytest.mark.survey
|
||||||
|
def test_deny_enabling_survey(deploy_jobtemplate, patch, user):
|
||||||
|
JT_url = reverse('api:job_template_detail', args=(deploy_jobtemplate.id,))
|
||||||
|
response = patch(url=JT_url, data=dict(survey_enabled=True), user=user('admin', True))
|
||||||
|
assert response.status_code == 402
|
||||||
|
assert response.data['detail'] == 'Feature surveys is not enabled in the active license'
|
||||||
|
|
||||||
|
@mock.patch('awx.main.access.BaseAccess.check_license', mock_check_license)
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@pytest.mark.survey
|
||||||
|
def test_deny_creating_with_survey(machine_credential, project, inventory, post, user):
|
||||||
|
JT_url = reverse('api:job_template_list')
|
||||||
|
JT_data = dict(
|
||||||
|
name = 'JT with survey',
|
||||||
|
job_type = 'run',
|
||||||
|
inventory = inventory.pk,
|
||||||
|
project = project.pk,
|
||||||
|
playbook = 'hiworld.yml',
|
||||||
|
credential = machine_credential.pk,
|
||||||
|
survey_enabled = True,
|
||||||
|
)
|
||||||
|
response = post(url=JT_url, data=JT_data, user=user('admin', True))
|
||||||
|
|
||||||
|
assert response.status_code == 402
|
||||||
|
assert response.data['detail'] == 'Feature surveys is not enabled in the active license'
|
||||||
|
|
||||||
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
|
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.survey
|
@pytest.mark.survey
|
||||||
|
|||||||
@@ -1109,27 +1109,6 @@ class JobTemplateSurveyTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(JobTemplateSurveyTest, self).tearDown()
|
super(JobTemplateSurveyTest, self).tearDown()
|
||||||
|
|
||||||
def test_post_patch_job_template_survey_wrong_license(self):
|
|
||||||
url = reverse('api:job_template_list')
|
|
||||||
data = dict(
|
|
||||||
name = 'launched job template',
|
|
||||||
job_type = PERM_INVENTORY_DEPLOY,
|
|
||||||
inventory = self.inv_eng.pk,
|
|
||||||
project = self.proj_dev.pk,
|
|
||||||
playbook = self.proj_dev.playbooks[0],
|
|
||||||
credential = self.cred_sue.pk,
|
|
||||||
survey_enabled = True,
|
|
||||||
)
|
|
||||||
self.create_test_license_file(features=dict(surveys=False))
|
|
||||||
with self.current_user(self.user_sue):
|
|
||||||
self.post(url, data, expect=402)
|
|
||||||
data['survey_enabled'] = False
|
|
||||||
with self.current_user(self.user_sue):
|
|
||||||
response = self.post(url, data, expect=201)
|
|
||||||
jt_url = reverse('api:job_template_detail', args=(response['id'],))
|
|
||||||
with self.current_user(self.user_sue):
|
|
||||||
self.patch(jt_url, dict(survey_enabled=True), expect=402)
|
|
||||||
|
|
||||||
def test_post_job_template_survey(self):
|
def test_post_job_template_survey(self):
|
||||||
url = reverse('api:job_template_list')
|
url = reverse('api:job_template_list')
|
||||||
data = dict(
|
data = dict(
|
||||||
|
|||||||
Reference in New Issue
Block a user