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'])
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" }] }
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" }] }
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'])
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']
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']
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']
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']
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