コード例 #1
0
 def test_create_text_encrypted(self):
     view = JobTemplateSurveySpec()
     resp = view._validate_spec_data(
         {
             "name":
             "new survey",
             "description":
             "foobar",
             "spec": [{
                 "question_description": "",
                 "min": 0,
                 "default": "$encrypted$",
                 "max": 1024,
                 "required": True,
                 "choices": "",
                 "variable": "openshift_username",
                 "question_name": "OpenShift Username",
                 "type": "text",
             }],
         },
         {},
     )
     assert resp.status_code == 400
     assert '$encrypted$ is a reserved keyword for password question defaults' in str(
         resp.data['error'])
コード例 #2
0
ファイル: test_views.py プロジェクト: zeitounator/awx
 def test_get_password_type(self, mocker, mock_response_new):
     JobTemplate = namedtuple('JobTemplate', 'survey_spec')
     obj = JobTemplate(survey_spec={
         'spec': [{
             'type': 'password',
             'default': 'my_default'
         }]
     })
     with mocker.patch.object(JobTemplateSurveySpec,
                              'get_object',
                              return_value=obj):
         view = JobTemplateSurveySpec()
         response = view.get(mocker.MagicMock())
         assert response == mock_response_new
         # which there was a better way to do this!
         assert response.call_args[0][1]['spec'][0][
             'default'] == '$encrypted$'
コード例 #3
0
 def test_use_saved_empty_string_default(self):
     '''
     Save is allowed, the $encrypted$ replacement is done with empty string
     The empty string value for default is unencrypted,
     unlike all other password questions
     '''
     view = JobTemplateSurveySpec()
     old = {
         "name":
         "old survey",
         "description":
         "foobar",
         "spec": [{
             "question_description": "",
             "min": 0,
             "default": "",
             "max": 1024,
             "required": True,
             "choices": "",
             "variable": "openshift_username",
             "question_name": "OpenShift Username",
             "type": "password"
         }]
     }
     new = deepcopy(old)
     new['spec'][0]['default'] = '$encrypted$'
     resp = view._validate_spec_data(new, old)
     assert resp is None
     assert new == {
         "name":
         "old survey",
         "description":
         "foobar",
         "spec": [{
             "question_description": "",
             "min": 0,
             "default": "",  # still has old unencrypted default
             "max": 1024,
             "required": True,
             "choices": "",
             "variable": "openshift_username",
             "question_name": "OpenShift Username",
             "type": "password"
         }]
     }
コード例 #4
0
 def test_use_saved_encrypted_default(self):
     '''
     Save is allowed, the $encrypted$ replacement is done
     '''
     view = JobTemplateSurveySpec()
     old = {
         "name":
         "old survey",
         "description":
         "foobar",
         "spec": [{
             "question_description": "",
             "min": 0,
             "default": "$encrypted$foooooooo",
             "max": 1024,
             "required": True,
             "choices": "",
             "variable": "openshift_username",
             "question_name": "OpenShift Username",
             "type": "password"
         }]
     }
     new = deepcopy(old)
     new['spec'][0]['default'] = '$encrypted$'
     new['spec'][0]['required'] = False
     resp = view._validate_spec_data(new, old)
     assert resp is None, resp.data
     assert new == {
         "name":
         "old survey",
         "description":
         "foobar",
         "spec": [{
             "question_description": "",
             "min": 0,
             "default": "$encrypted$foooooooo",  # default remained the same
             "max": 1024,
             "required": False,  # only thing changed
             "choices": "",
             "variable": "openshift_username",
             "question_name": "OpenShift Username",
             "type": "password"
         }]
     }
コード例 #5
0
 def test_change_encrypted_var_name(self):
     view = JobTemplateSurveySpec()
     old = {
         "name":
         "old survey",
         "description":
         "foobar",
         "spec": [{
             "question_description": "",
             "min": 0,
             "default": "$encrypted$foooooooo",
             "max": 1024,
             "required": True,
             "choices": "",
             "variable": "openshift_username",
             "question_name": "OpenShift Username",
             "type": "password"
         }]
     }
     new = deepcopy(old)
     new['spec'][0]['variable'] = 'openstack_username'
     resp = view._validate_spec_data(new, old)
     assert resp.status_code == 400
     assert 'may not be used for new default' in str(resp.data['error'])
コード例 #6
0
     JobTemplateLaunch.as_view(),
     name='job_template_launch'),
 url(r'^(?P<pk>[0-9]+)/jobs/$',
     JobTemplateJobsList.as_view(),
     name='job_template_jobs_list'),
 url(r'^(?P<pk>[0-9]+)/slice_workflow_jobs/$',
     JobTemplateSliceWorkflowJobsList.as_view(),
     name='job_template_slice_workflow_jobs_list'),
 url(r'^(?P<pk>[0-9]+)/callback/$',
     JobTemplateCallback.as_view(),
     name='job_template_callback'),
 url(r'^(?P<pk>[0-9]+)/schedules/$',
     JobTemplateSchedulesList.as_view(),
     name='job_template_schedules_list'),
 url(r'^(?P<pk>[0-9]+)/survey_spec/$',
     JobTemplateSurveySpec.as_view(),
     name='job_template_survey_spec'),
 url(r'^(?P<pk>[0-9]+)/activity_stream/$',
     JobTemplateActivityStreamList.as_view(),
     name='job_template_activity_stream_list'),
 url(r'^(?P<pk>[0-9]+)/notification_templates_started/$',
     JobTemplateNotificationTemplatesStartedList.as_view(),
     name='job_template_notification_templates_started_list'),
 url(r'^(?P<pk>[0-9]+)/notification_templates_error/$',
     JobTemplateNotificationTemplatesErrorList.as_view(),
     name='job_template_notification_templates_error_list'),
 url(r'^(?P<pk>[0-9]+)/notification_templates_success/$',
     JobTemplateNotificationTemplatesSuccessList.as_view(),
     name='job_template_notification_templates_success_list'),
 url(r'^(?P<pk>[0-9]+)/instance_groups/$',
     JobTemplateInstanceGroupsList.as_view(),
コード例 #7
0
 def test_survey_spec_element_missing_property(self):
     spec = self.spec_from_element({})
     spec['spec'][0].pop('type')
     r = JobTemplateSurveySpec._validate_spec_data(spec, {})
     assert "'type' missing from survey question 0" in r.data['error']
コード例 #8
0
 def test_survey_spec_dual_names_error(self):
     spec = self.spec_from_element({})
     spec['spec'].append(spec['spec'][0].copy())
     r = JobTemplateSurveySpec._validate_spec_data(spec, {})
     assert "'variable' 'foo' duplicated in survey question 1." in r.data[
         'error']
コード例 #9
0
 def test_survey_spec_non_dict_error(self):
     spec = self.spec_from_element({})
     spec['spec'][0] = 'foo'
     r = JobTemplateSurveySpec._validate_spec_data(spec, {})
     assert 'Survey question 0 is not a json object' in r.data['error']
コード例 #10
0
 def test_survey_question_element_validation(self, survey_item, error_text):
     spec = self.spec_from_element(survey_item)
     r = JobTemplateSurveySpec._validate_spec_data(spec, {})
     assert r is not None, (spec, error_text)
     assert 'error' in r.data
     assert error_text in r.data['error']
コード例 #11
0
ファイル: test_views.py プロジェクト: kedar700/awx-bitbucket
 def test_survey_spec_element_number_empty_default(self, _type):
     """ Assert that empty default is allowed for answer. """
     spec = self.spec_from_element({'type': _type, 'default': ''})
     r = JobTemplateSurveySpec._validate_spec_data(spec, {})
     assert r is None
コード例 #12
0
    JobTemplateAccessList,
    JobTemplateObjectRolesList,
    JobTemplateLabelList,
    JobTemplateCopy,
)


urls = [
    url(r'^$', JobTemplateList.as_view(), name='job_template_list'),
    url(r'^(?P<pk>[0-9]+)/$', JobTemplateDetail.as_view(), name='job_template_detail'),
    url(r'^(?P<pk>[0-9]+)/launch/$', JobTemplateLaunch.as_view(), name='job_template_launch'),
    url(r'^(?P<pk>[0-9]+)/jobs/$', JobTemplateJobsList.as_view(), name='job_template_jobs_list'),
    url(r'^(?P<pk>[0-9]+)/slice_workflow_jobs/$', JobTemplateSliceWorkflowJobsList.as_view(), name='job_template_slice_workflow_jobs_list'),
    url(r'^(?P<pk>[0-9]+)/callback/$', JobTemplateCallback.as_view(), name='job_template_callback'),
    url(r'^(?P<pk>[0-9]+)/schedules/$', JobTemplateSchedulesList.as_view(), name='job_template_schedules_list'),
    url(r'^(?P<pk>[0-9]+)/survey_spec/$', JobTemplateSurveySpec.as_view(), name='job_template_survey_spec'),
    url(r'^(?P<pk>[0-9]+)/activity_stream/$', JobTemplateActivityStreamList.as_view(), name='job_template_activity_stream_list'),
    url(r'^(?P<pk>[0-9]+)/notification_templates_any/$', JobTemplateNotificationTemplatesAnyList.as_view(),
        name='job_template_notification_templates_any_list'),
    url(r'^(?P<pk>[0-9]+)/notification_templates_error/$', JobTemplateNotificationTemplatesErrorList.as_view(),
        name='job_template_notification_templates_error_list'),
    url(r'^(?P<pk>[0-9]+)/notification_templates_success/$', JobTemplateNotificationTemplatesSuccessList.as_view(),
        name='job_template_notification_templates_success_list'),
    url(r'^(?P<pk>[0-9]+)/instance_groups/$', JobTemplateInstanceGroupsList.as_view(), name='job_template_instance_groups_list'),
    url(r'^(?P<pk>[0-9]+)/access_list/$', JobTemplateAccessList.as_view(), name='job_template_access_list'),
    url(r'^(?P<pk>[0-9]+)/object_roles/$', JobTemplateObjectRolesList.as_view(), name='job_template_object_roles_list'),
    url(r'^(?P<pk>[0-9]+)/labels/$', JobTemplateLabelList.as_view(), name='job_template_label_list'),
    url(r'^(?P<pk>[0-9]+)/copy/$', JobTemplateCopy.as_view(), name='job_template_copy'),
]

__all__ = ['urls']