def test_create_valid_same_standard_different_infrastructure(self): infrastructure1 = ckanext_factories.Infrastructure() infrastructure2 = ckanext_factories.Infrastructure() metadata_schema = ckanext_factories.MetadataSchema( infrastructure_id=infrastructure1['id']) input_dict = { 'metadata_standard_id': metadata_schema['metadata_standard_id'], 'organization_id': '', 'infrastructure_id': infrastructure2['id'], 'schema_json': '{}', } result, obj = self.test_action('metadata_schema_create', **input_dict) assert_object_matches_dict(obj, input_dict)
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')
def test_create_invalid_with_organization_and_infrastructure(self): organization = ckan_factories.Organization() infrastructure = ckanext_factories.Infrastructure() result, obj = self.test_action('metadata_schema_create', should_error=True, organization_id=organization['id'], infrastructure_id=infrastructure['id']) assert_error( result, '__after', 'A metadata schema may be associated with either an organization or an infrastructure but not both.' )
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.' )
def test_create_no_invalidate_records_different_infrastructure_2(self): """ Create a schema with the same standard but a different infrastructure to that of an existing validated metadata record. This should not invalidate the record. """ metadata_record, _, _ = self._generate_and_validate_metadata_record() call_action( 'metadata_schema_create', metadata_standard_id=metadata_record['metadata_standard_id'], organization_id='', infrastructure_id=ckanext_factories.Infrastructure()['id'], schema_json='{}') assert_package_has_extra(metadata_record['id'], 'validated', True)
def test_create_valid_with_infrastructure_byname(self): metadata_standard = ckanext_factories.MetadataStandard() infrastructure = ckanext_factories.Infrastructure() input_dict = { 'metadata_standard_id': metadata_standard['name'], 'organization_id': '', 'infrastructure_id': infrastructure['name'], 'schema_json': '{}', } result, obj = self.test_action('metadata_schema_create', **input_dict) assert obj.metadata_standard_id == metadata_standard['id'] assert obj.organization_id is None assert obj.infrastructure_id == infrastructure['id'] assert obj.name == generate_name(metadata_standard['name'], '', infrastructure['name'])
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'])
def test_create_invalid_deleted_references(self): 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, 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')
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
def _generate_infrastructure(self, **kwargs): return ckanext_factories.Infrastructure(user=self.normal_user, **kwargs)