def test_create_invalid_deleted_revert(self): workflow_state = ckanext_factories.WorkflowState() call_action('workflow_state_delete', id=workflow_state['id']) result, obj = self.test_action('workflow_state_create', should_error=True, revert_state_id=workflow_state['id']) assert_error(result, 'revert_state_id', 'Not found: Workflow State')
def test_delete_with_dependencies(self): organization = self._generate_organization() metadata_collection = self._generate_metadata_collection( organization_id=organization['id']) metadata_schema = ckanext_factories.MetadataSchema( organization_id=organization['id']) metadata_record = ckanext_factories.MetadataRecord( owner_org=organization['id'], metadata_collection_id=metadata_collection['id']) result, obj = self.test_action('organization_delete', should_error=True, id=organization['id']) assert_error(result, 'message', 'Organization has dependent metadata records') assert ckan_model.Group.get( metadata_collection['id']).state == 'active' assert ckanext_model.MetadataSchema.get( metadata_schema['id']).state == 'active' call_action('metadata_record_delete', id=metadata_record['id']) self.test_action('organization_delete', id=organization['id']) assert ckan_model.Group.get( metadata_collection['id']).state == 'deleted' assert ckanext_model.MetadataSchema.get( metadata_schema['id']).state == 'deleted'
def test_update_invalid_bad_json_path(self): metadata_json_attr_map = ckanext_factories.MetadataJSONAttrMap() result, obj = self.test_action('metadata_json_attr_map_update', should_error=True, id=metadata_json_attr_map['id'], json_path='foo') assert_error(result, 'json_path', 'Invalid JSON pointer')
def test_update_invalid_missing_values(self): workflow_annotation = ckanext_factories.WorkflowAnnotation() result, obj = self.test_action('workflow_annotation_update', should_error=True, id=workflow_annotation['id'], attributes='') assert_error(result, 'attributes', 'Missing value')
def test_update_invalid_attributes_not_json(self): workflow_annotation = ckanext_factories.WorkflowAnnotation() result, obj = self.test_action('workflow_annotation_update', should_error=True, id=workflow_annotation['id'], attributes='not json') assert_error(result, 'attributes', 'JSON decode error')
def test_update_invalid_missing_values(self): workflow_state = ckanext_factories.WorkflowState() result, obj = self.test_action('workflow_state_update', should_error=True, id=workflow_state['id'], workflow_rules_json='') assert_error(result, 'workflow_rules_json', 'Missing value')
def test_update_invalid_record_attr(self): metadata_json_attr_map = ckanext_factories.MetadataJSONAttrMap() result, obj = self.test_action('metadata_json_attr_map_update', should_error=True, id=metadata_json_attr_map['id'], record_attr='owner_org') assert_error(result, 'record_attr', 'The specified key cannot be used')
def test_update_invalid_not_json_schema(self): metadata_schema = ckanext_factories.MetadataSchema() result, obj = self.test_action('metadata_schema_update', should_error=True, id=metadata_schema['id'], schema_json='{"type": "foo"}') assert_error(result, 'schema_json', 'Invalid JSON schema')
def test_update_invalid_bad_revert(self): workflow_state = ckanext_factories.WorkflowState() result, obj = self.test_action('workflow_state_update', should_error=True, id=workflow_state['id'], revert_state_id='foo') assert_error(result, 'revert_state_id', 'Not found: Workflow State')
def test_create_invalid_missing_values(self): result, obj = self.test_action('workflow_state_create', should_error=True, name='', workflow_rules_json='') assert_error(result, 'name', 'Missing value') assert_error(result, 'workflow_rules_json', 'Missing value')
def test_update_invalid_not_json(self): metadata_schema = ckanext_factories.MetadataSchema() result, obj = self.test_action('metadata_schema_update', should_error=True, id=metadata_schema['id'], schema_json='not json') assert_error(result, 'schema_json', 'JSON decode error')
def test_create_invalid_duplicate_standard(self): metadata_schema = ckanext_factories.MetadataSchema() result, obj = self.test_action( 'metadata_schema_create', should_error=True, metadata_standard_id=metadata_schema['metadata_standard_id']) assert_error(result, '__after', 'Unique constraint violation')
def test_create_invalid_missing_values(self): result, obj = self.test_action('metadata_schema_create', should_error=True, metadata_standard_id='', schema_json='') assert_error(result, 'metadata_standard_id', 'Missing value') assert_error(result, 'schema_json', 'Missing value')
def test_create_invalid_missing_values(self): result, obj = self.test_action('workflow_annotation_create', should_error=True, name='', attributes='') assert_error(result, 'name', 'Missing value') assert_error(result, 'attributes', 'Missing value')
def test_update_invalid_attributes_not_json_dict(self): workflow_annotation = ckanext_factories.WorkflowAnnotation() result, obj = self.test_action('workflow_annotation_update', should_error=True, id=workflow_annotation['id'], attributes='[1,2,3]') assert_error(result, 'attributes', 'Expecting a JSON dictionary')
def test_create_invalid_bad_states(self): result, obj = self.test_action('workflow_transition_create', should_error=True, from_state_id='foo', to_state_id='bar') assert_error(result, 'from_state_id', 'Not found: Workflow State') assert_error(result, 'to_state_id', 'Not found: Workflow State')
def test_create_invalid_bad_attribute_names(self): result, obj = self.test_action('workflow_annotation_create', should_error=True, attributes='{" bad": "string"}') assert_error( result, 'attributes', 'Workflow annotation attribute name may consist only of alphanumeric characters' )
def test_update_invalid_bad_parent(self): metadata_standard = ckanext_factories.MetadataStandard() result, obj = self.test_action('metadata_standard_update', should_error=True, id=metadata_standard['id'], parent_standard_id='foo') assert_error(result, 'parent_standard_id', 'Not found: Metadata Standard')
def test_update_invalid_missing_values(self): metadata_standard = ckanext_factories.MetadataStandard() result, obj = self.test_action('metadata_standard_update', should_error=True, id=metadata_standard['id'], standard_name='', metadata_template_json='') assert_error(result, 'standard_name', 'Missing value')
def test_update_invalid_empty_attributes(self): workflow_annotation = ckanext_factories.WorkflowAnnotation() result, obj = self.test_action('workflow_annotation_update', should_error=True, id=workflow_annotation['id'], attributes='{}') assert_error(result, 'attributes', 'A workflow annotation requires at least one attribute')
def test_update_invalid_missing_values(self): metadata_schema = ckanext_factories.MetadataSchema() result, obj = self.test_action('metadata_schema_update', should_error=True, id=metadata_schema['id'], metadata_standard_id='', schema_json='') assert_error(result, 'metadata_standard_id', 'Missing value') assert_error(result, 'schema_json', 'Missing value')
def test_update_invalid_duplicate_name(self): infrastructure1 = self._generate_infrastructure() infrastructure2 = self._generate_infrastructure() input_dict = { 'id': infrastructure1['id'], 'name': infrastructure2['name'], } result, obj = self.test_action('infrastructure_update', should_error=True, **input_dict) assert_error(result, 'name', 'Group name already exists in database')
def test_member_delete_invalid(self): infrastructure = self._generate_infrastructure() metadata_collection = ckanext_factories.MetadataCollection(infrastructures=[{'id': infrastructure['id']}]) result, obj = self.test_action('member_delete', should_error=True, check_auth=True, exception_class=tk.NotAuthorized, id=infrastructure['id'], object=metadata_collection['id'], object_type='group') assert_error(result, None, "This action may not be used to alter a metadata collection's membership of infrastructures.")
def test_update_invalid_missing_values(self): metadata_json_attr_map = ckanext_factories.MetadataJSONAttrMap() result, obj = self.test_action('metadata_json_attr_map_update', should_error=True, id=metadata_json_attr_map['id'], json_path='', record_attr='') assert_error(result, 'json_path', 'Missing value') assert_error(result, 'record_attr', 'Missing value')
def test_create_invalid_deleted_metadata_standard(self): metadata_standard = ckanext_factories.MetadataStandard() call_action('metadata_standard_delete', id=metadata_standard['id']) result, obj = self.test_action( 'metadata_json_attr_map_create', should_error=True, metadata_standard_id=metadata_standard['id']) assert_error(result, 'metadata_standard_id', 'Not found: Metadata Standard')
def test_update_invalid_hierarchy_not_allowed(self): infrastructure1 = self._generate_infrastructure() infrastructure2 = self._generate_infrastructure() input_dict = { 'id': infrastructure1['id'], 'groups': [{'name': infrastructure2['name']}], } result, obj = self.test_action('infrastructure_update', should_error=True, **input_dict) assert_error(result, '__junk', 'The input field .*groups.* was not expected.')
def test_update_invalid(self): workflow_transition = ckanext_factories.WorkflowTransition() result, obj = self.test_action('workflow_transition_update', should_error=True, id=workflow_transition['id']) assert_error( result, 'message', 'A workflow transition cannot be updated. Delete it and create a new one instead.' )
def test_create_invalid_bad_references(self): result, obj = self.test_action('metadata_collection_create', should_error=True, organization_id='foo', infrastructures=[{ 'id': 'bar' }]) assert_error(result, 'organization_id', 'Not found: Organization') assert_error(result, 'infrastructures/0/id', 'Not found: Infrastructure')
def test_group_create_invalid(self): result, obj = self.test_action('group_create', should_error=True, check_auth=True, exception_class=tk.NotAuthorized, type='metadata_collection') assert_error( result, None, "This action may not be used for metadata_collection type objects." )
def test_create_invalid_self_transition(self): workflow_state = ckanext_factories.WorkflowState() result, obj = self.test_action('workflow_transition_create', should_error=True, from_state_id=workflow_state['id'], to_state_id=workflow_state['id']) assert_error( result, '__after', 'The from- and to-state of a workflow transition cannot be the same.' )