Exemplo n.º 1
0
 def test_update_invalid_duplicate_standard(self):
     metadata_schema1 = ckanext_factories.MetadataSchema()
     metadata_schema2 = ckanext_factories.MetadataSchema()
     result, obj = self.test_action(
         'metadata_schema_update',
         should_error=True,
         id=metadata_schema1['id'],
         metadata_standard_id=metadata_schema2['metadata_standard_id'])
     assert_error(result, '__after', 'Unique constraint violation')
Exemplo n.º 2
0
 def test_update_invalid_duplicate_name(self):
     metadata_schema1 = ckanext_factories.MetadataSchema()
     metadata_schema2 = ckanext_factories.MetadataSchema()
     input_dict = {
         'id': metadata_schema1['id'],
         'name': metadata_schema2['name'],
     }
     result, obj = self.test_action('metadata_schema_update',
                                    should_error=True,
                                    **input_dict)
     assert_error(result, 'name', 'Duplicate name: Metadata Schema')
Exemplo n.º 3
0
    def _bulk_action_setup(self):
        metadata_schema = ckanext_factories.MetadataSchema()
        self.workflow_transition_1 = ckanext_factories.WorkflowTransition(
            from_state_id='')
        self.workflow_transition_2 = ckanext_factories.WorkflowTransition(
            from_state_id=self.workflow_transition_1['to_state_id'])
        self.metadata_collection = ckanext_factories.MetadataCollection()
        self.metadata_records = [
            ckanext_factories.MetadataRecord(
                owner_org=self.metadata_collection['organization_id'],
                metadata_collection_id=self.metadata_collection['id'],
                metadata_standard_id=metadata_schema['metadata_standard_id'])
            for _ in range(3)
        ]

        # modify the middle record; this should not affect processing of the surrounding records
        self.test_action('metadata_record_validate',
                         id=self.metadata_records[1]['id'])
        self.test_action(
            'metadata_record_workflow_state_override',
            id=self.metadata_records[1]['id'],
            workflow_state_id=self.workflow_transition_1['to_state_id'])
        assert_package_has_extra(self.metadata_records[1]['id'], 'validated',
                                 True)
        assert_package_has_extra(self.metadata_records[1]['id'],
                                 'workflow_state_id',
                                 self.workflow_transition_1['to_state_id'])
Exemplo n.º 4
0
 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')
Exemplo n.º 5
0
    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'
Exemplo n.º 6
0
 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')
Exemplo n.º 7
0
    def test_delete_valid_cascade_metadata_schemas(self):
        organization = self._generate_organization()
        metadata_schema = ckanext_factories.MetadataSchema(
            organization_id=organization['id'])

        self.test_action('organization_delete', id=organization['id'])
        assert ckanext_model.MetadataSchema.get(
            metadata_schema['id']).state == 'deleted'
Exemplo n.º 8
0
 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')
Exemplo n.º 9
0
 def test_update_invalid_missing_params(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     result, obj = self.test_action('metadata_schema_update',
                                    should_error=True,
                                    id=metadata_schema['id'])
     assert_error(result, 'metadata_standard_id', 'Missing parameter')
     assert_error(result, 'organization_id', 'Missing parameter')
     assert_error(result, 'infrastructure_id', 'Missing parameter')
     assert_error(result, 'schema_json', 'Missing parameter')
Exemplo n.º 10
0
 def test_create_invalid_duplicate_standard_infrastructure(self):
     infrastructure = ckanext_factories.Infrastructure()
     metadata_schema = ckanext_factories.MetadataSchema(
         infrastructure_id=infrastructure['id'])
     result, obj = self.test_action(
         'metadata_schema_create',
         should_error=True,
         metadata_standard_id=metadata_schema['metadata_standard_id'],
         infrastructure_id=metadata_schema['infrastructure_id'])
     assert_error(result, '__after', 'Unique constraint violation')
Exemplo n.º 11
0
 def test_create_invalid_duplicate_standard_organization(self):
     organization = ckan_factories.Organization()
     metadata_schema = ckanext_factories.MetadataSchema(
         organization_id=organization['id'])
     result, obj = self.test_action(
         'metadata_schema_create',
         should_error=True,
         metadata_standard_id=metadata_schema['metadata_standard_id'],
         organization_id=metadata_schema['organization_id'])
     assert_error(result, '__after', 'Unique constraint violation')
Exemplo n.º 12
0
 def test_update_valid_datacite(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     input_dict = {
         'id': metadata_schema['id'],
         'metadata_standard_id': metadata_schema['metadata_standard_id'],
         'organization_id': '',
         'infrastructure_id': '',
         'schema_json': load_example('saeon_odp_4.2_schema.json'),
     }
     result, obj = self.test_action('metadata_schema_update', **input_dict)
     assert_object_matches_dict(obj, input_dict)
Exemplo n.º 13
0
 def test_update_invalid_bad_references(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     result, obj = self.test_action('metadata_schema_update',
                                    should_error=True,
                                    id=metadata_schema['id'],
                                    metadata_standard_id='a',
                                    organization_id='b',
                                    infrastructure_id='c')
     assert_error(result, 'metadata_standard_id',
                  'Not found: Metadata Standard')
     assert_error(result, 'organization_id', 'Not found: Organization')
     assert_error(result, 'infrastructure_id', 'Not found: Infrastructure')
Exemplo n.º 14
0
 def test_update_valid_partial(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     input_dict = {
         'id': metadata_schema['id'],
         'name': 'updated-test-metadata-schema',
         'metadata_standard_id': metadata_schema['metadata_standard_id'],
         'organization_id': '',
         'infrastructure_id': '',
         'schema_json': '{ "testkey": "newtestvalue" }',
     }
     result, obj = self.test_action('metadata_schema_update', **input_dict)
     assert_object_matches_dict(obj, input_dict)
     assert obj.description == metadata_schema['description']
Exemplo n.º 15
0
 def test_create_valid_same_standard_different_organization(self):
     organization1 = ckan_factories.Organization()
     organization2 = ckan_factories.Organization()
     metadata_schema = ckanext_factories.MetadataSchema(
         organization_id=organization1['id'])
     input_dict = {
         'metadata_standard_id': metadata_schema['metadata_standard_id'],
         'organization_id': organization2['id'],
         'infrastructure_id': '',
         'schema_json': '{}',
     }
     result, obj = self.test_action('metadata_schema_create', **input_dict)
     assert_object_matches_dict(obj, input_dict)
Exemplo n.º 16
0
 def test_create_valid_same_infrastructure_different_standard(self):
     infrastructure = ckanext_factories.Infrastructure()
     metadata_schema = ckanext_factories.MetadataSchema(
         infrastructure_id=infrastructure['id'])
     metadata_standard = ckanext_factories.MetadataStandard()
     input_dict = {
         'metadata_standard_id': metadata_standard['id'],
         'organization_id': '',
         'infrastructure_id': metadata_schema['infrastructure_id'],
         'schema_json': '{}',
     }
     result, obj = self.test_action('metadata_schema_create', **input_dict)
     assert_object_matches_dict(obj, input_dict)
Exemplo n.º 17
0
 def test_update_invalid_with_infrastructure_set_organization(self):
     infrastructure = ckanext_factories.Infrastructure()
     metadata_schema = ckanext_factories.MetadataSchema(
         infrastructure_id=infrastructure['id'])
     organization = ckan_factories.Organization()
     result, obj = self.test_action('metadata_schema_update',
                                    should_error=True,
                                    id=metadata_schema['id'],
                                    organization_id=organization['id'])
     assert_error(
         result, '__after',
         'A metadata schema may be associated with either an organization or an infrastructure but not both.'
     )
Exemplo n.º 18
0
 def test_update_valid(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     metadata_standard = ckanext_factories.MetadataStandard()
     input_dict = {
         'id': metadata_schema['id'],
         'description': 'Updated test metadata schema description',
         'metadata_standard_id': metadata_standard['id'],
         'organization_id': '',
         'infrastructure_id': '',
         'schema_json': '{ "testkey": "newtestvalue" }',
     }
     result, obj = self.test_action('metadata_schema_update', **input_dict)
     assert_object_matches_dict(obj, input_dict)
     assert obj.name == generate_name(metadata_standard['name'], '', '')
Exemplo n.º 19
0
    def test_delete_with_dependencies(self):
        infrastructure = self._generate_infrastructure()
        metadata_schema = ckanext_factories.MetadataSchema(infrastructure_id=infrastructure['id'])
        metadata_collection = ckanext_factories.MetadataCollection(infrastructures=[{'id': infrastructure['id']}])

        result, obj = self.test_action('infrastructure_delete', should_error=True,
                                       id=infrastructure['id'])
        assert_error(result, 'message', 'Project has dependent metadata collections')
        assert ckanext_model.MetadataSchema.get(metadata_schema['id']).state == 'active'

        call_action('metadata_collection_delete', id=metadata_collection['id'])
        self.test_action('infrastructure_delete',
                         id=infrastructure['id'])
        assert ckanext_model.MetadataSchema.get(metadata_schema['id']).state == 'deleted'
Exemplo n.º 20
0
 def test_update_valid_set_infrastructure(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     infrastructure = ckanext_factories.Infrastructure()
     input_dict = {
         'id': metadata_schema['id'],
         'metadata_standard_id': metadata_schema['metadata_standard_id'],
         'organization_id': '',
         'infrastructure_id': infrastructure['id'],
         'schema_json': '{}',
     }
     result, obj = self.test_action('metadata_schema_update', **input_dict)
     assert_object_matches_dict(obj, input_dict)
     metadata_standard = ckanext_model.MetadataStandard.get(
         metadata_schema['metadata_standard_id'])
     assert obj.name == generate_name(metadata_standard.name, '',
                                      infrastructure['name'])
Exemplo n.º 21
0
    def test_update_invalid_deleted_references(self):
        metadata_schema = ckanext_factories.MetadataSchema()
        metadata_standard = ckanext_factories.MetadataStandard()
        organization = ckan_factories.Organization()
        infrastructure = ckanext_factories.Infrastructure()
        call_action('metadata_standard_delete', id=metadata_standard['id'])
        call_action('organization_delete', id=organization['id'])
        call_action('infrastructure_delete', id=infrastructure['id'])

        result, obj = self.test_action(
            'metadata_schema_create',
            should_error=True,
            id=metadata_schema['id'],
            metadata_standard_id=metadata_standard['id'],
            organization_id=organization['id'],
            infrastructure_id=infrastructure['id'])
        assert_error(result, 'metadata_standard_id',
                     'Not found: Metadata Standard')
        assert_error(result, 'organization_id', 'Not found: Organization')
        assert_error(result, 'infrastructure_id', 'Not found: Infrastructure')
Exemplo n.º 22
0
    def test_delete_with_dependencies(self):
        metadata_standard = ckanext_factories.MetadataStandard()
        metadata_schema = ckanext_factories.MetadataSchema(
            metadata_standard_id=metadata_standard['id'])
        metadata_record = ckanext_factories.MetadataRecord(
            metadata_standard_id=metadata_standard['id'])

        result, obj = self.test_action('metadata_standard_delete',
                                       should_error=True,
                                       id=metadata_standard['id'])

        assert_error(result, 'message',
                     'Metadata standard has dependent metadata records')
        assert ckanext_model.MetadataSchema.get(
            metadata_schema['id']).state == 'active'

        call_action('metadata_record_delete', id=metadata_record['id'])
        self.test_action('metadata_standard_delete',
                         id=metadata_standard['id'])
        assert ckanext_model.MetadataSchema.get(
            metadata_schema['id']).state == 'deleted'
Exemplo n.º 23
0
    def _generate_and_validate_metadata_record(
            self,
            metadata_standard_id=None,
            add_infrastructure_to_collection=False,
            add_organization_to_schema=False,
            add_infrastructure_to_schema=False):
        """
        Generate a metadata record and a metadata schema, and validate the record using the schema.
        :param metadata_standard_id: specify the metadata standard to use
        :param add_infrastructure_to_collection: assign an infrastructure to the record's metadata collection
        :param add_organization_to_schema: associate the record's organization with the schema
        :param add_infrastructure_to_schema: associate the record's infrastructure with the schema
        :return: tuple of new record, new collection, new schema
        """
        organization = ckan_factories.Organization()
        metadata_collection = ckanext_factories.MetadataCollection(
            organization_id=organization['id'],
            infrastructures=[{
                'id': ckanext_factories.Infrastructure()['id']
            }] if add_infrastructure_to_collection else [])
        metadata_record = ckanext_factories.MetadataRecord(
            metadata_standard_id=metadata_standard_id,
            metadata_collection_id=metadata_collection['id'],
            owner_org=organization['id'],
        )
        metadata_schema = ckanext_factories.MetadataSchema(
            metadata_standard_id=metadata_record['metadata_standard_id'],
            organization_id=organization['id']
            if add_organization_to_schema else '',
            infrastructure_id=metadata_collection['infrastructures'][0]['id']
            if add_infrastructure_to_schema else '')

        assert_metadata_record_has_validation_schemas(metadata_record['id'],
                                                      metadata_schema['name'])
        self._validate_metadata_record(metadata_record)
        self.assert_validate_activity_logged(metadata_record['id'],
                                             metadata_schema)
        return metadata_record, metadata_collection, metadata_schema
Exemplo n.º 24
0
 def test_delete_valid(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     self.test_action('metadata_schema_delete', id=metadata_schema['id'])
Exemplo n.º 25
0
 def test_create_invalid_duplicate_name(self):
     metadata_schema = ckanext_factories.MetadataSchema()
     result, obj = self.test_action('metadata_schema_create',
                                    should_error=True,
                                    name=metadata_schema['name'])
     assert_error(result, 'name', 'Duplicate name: Metadata Schema')