def test_rule_get_projects(): result = RuleManager(admin_mode=True).get_projects("false") projects = result.projects assert projects is not None assert projects.__len__() >= 2 assert projects[0].title == "(MDL) Placeholder project" assert projects[1].title == "(HVC) Placeholder project"
def test_rule_get_project_acl_for_manager(): project = RuleManager("opalmen").get_project_acl_for_manager( "P000000010", "false") assert project.viewers is not None assert project.contributors is not None assert project.managers is not None assert project.principal_investigator is not None assert project.data_steward is not None
def test_rule_get_groups(): result = RuleManager(admin_mode=True).get_groups("true") groups = result.groups assert groups is not None assert groups.__len__() >= 2 assert groups[0].name is not None assert groups[0].id is not None assert groups[0].display_name is not None
def test_rule_get_users_in_group(): result = RuleManager(admin_mode=True).get_users_in_group("10002") users = result.users assert users is not None assert users.__len__() >= 2 assert users[0].user_name is not None assert users[0].user_id is not None assert users[0].display_name is not None
def test_rule_get_data_stewards(): result = RuleManager(admin_mode=True).get_data_stewards() data_stewards = result.data_stewards assert data_stewards is not None assert data_stewards.__len__() >= 2 assert data_stewards[0].user_name is not None assert data_stewards[0].user_id is not None assert data_stewards[0].display_name is not None
def test_rule_get_project_collection_details(): collection = RuleManager(admin_mode=True).get_project_collection_details( "P000000011", "C000000001", "false") assert collection is not None assert collection.id == "C000000001" assert collection.creator == "*****@*****.**" assert collection.title == "(HVC) Placeholder collection" assert collection.enable_archive is False assert collection.enable_open_access_export is False
def test_rule_get_collections_var_config(): config = dict() config["IRODS_HOST"] = "0.0.0.0" config["IRODS_USER"] = "******" config["IRODS_PASS"] = "******" result = RuleManager( config=config).get_collections("/nlmumc/projects/P000000011") collections = result.collections assert collections is not None assert collections[0].creator == "*****@*****.**"
def test_rule_archive(): result = False try: # RuleManager("service-surfarchive").archive_project_collection("/nlmumc/projects/P000000016/C000000001") RuleManager("jmelius").archive_project_collection( "/nlmumc/projects/P000000015/C000000001") except CAT_NO_ACCESS_PERMISSION: result = True assert result is True
def test_rule_export(): result = False try: # RuleManager(admin_mode=True).export_project_collection("P000000016", "C000000001", "DataverseNL", {}) RuleManager("mcoonen").export_project_collection( "P000000016", "C000000001", "DataverseNL", {}) except CAT_NO_ACCESS_PERMISSION: result = True assert result is True
def test_rule_create_new_project(): manager = RuleManager(admin_mode=True) project = manager.create_new_project( "authorizationPeriodEndDate", "dataRetentionPeriodEndDate", "ingestResource", "resource", 42, "PyTest title", "jmelius", "opalmen", "XXXXXXXXX", "true", "false", "false", ) assert project.project_id is not None assert project.project_path is not None # Set ACL otherwise list_project fails manager.set_acl("default", "own", "opalmen", project.project_path) manager.set_acl("default", "own", "jmelius", project.project_path)
def test_rule_get_project_details(): project_details = RuleManager(admin_mode=True).get_project_details( "/nlmumc/projects/P000000011", "true") assert project_details is not None assert project_details.principal_investigator_display_name == "Pascal Suppers" assert project_details.data_steward_display_name == "Olav Palmen" assert project_details.responsible_cost_center == "AZM-123456" assert project_details.manager_users.users[ 0].display_name == "Pascal Suppers" assert project_details.contributor_users.users[ 0].display_name == "service-mdl" # assert project_details.viewer_groups.groups[0].display_name == 'DataHub' assert project_details.title == "(HVC) Placeholder project" assert project_details.enable_open_access_export is False assert project_details.enable_archive is False assert project_details.has_financial_view_access is False assert project_details.size == 0
def test_rule_export_project_collection(): project = "P000000015" collection = "C000000002" repository = "Dataverse" message = { "project": project, "collection": collection, "repository": repository, "dataverse_alias": "DataHub", "restrict": False, "restrict_list": "P000000015/C000000002/specialchars_~!@#$%^&()-+=[]{};\"',.txt,\tP000000015/C000000002/test.log", "data_export": False, "delete": False, "depositor": "*****@*****.**", } RuleManager(admin_mode=True).export_project_collection( project, collection, repository, message) assert True is True
def test_export_project_collection_by_step(): project = "P000000015" collection = "C000000002" repository = "Dataverse" RuleManager(admin_mode=True).prepare_export(project, collection, repository) message = { "project": project, "collection": collection, "repository": repository, "dataverse_alias": "DataHub", "restrict": False, "restrict_list": "P000000015/C000000002/specialchars_~!@#$%^&()-+=[]{};\"',.txt,\tP000000015/C000000002/test.log", "data_export": False, "delete": False, "depositor": "*****@*****.**", } json_message = json.dumps(message) publish_message("datahub.events_tx", "projectCollection.exporter.requested", json_message) assert True is True
def test_rule_get_contributing_projects(): result = RuleManager("jmelius").get_contributing_projects("false") assert result is not None
def test_rule_get_project_contributors(): result = RuleManager("opalmen").get_project_contributors( "P000000010", "true", "false") assert result is not None
def test_rule_get_contributing_project(): result = RuleManager("mcoonen").get_contributing_project( "P000000010", "false") assert result is not None
def connect(self): logger.info("--\t Connect to iRODS") self.rule_manager = RuleManager(admin_mode=True, config=self.config) self.session = self.rule_manager.session
class irodsClient: """iRODS client to connect to the iRODS server, to retrieve metadata and data.""" def __init__(self, host=None, user=None, password=None): self.collection_object = None self.project_id = None self.collection_id = None self.collection_avu = CollectionAVU() self.repository = None self.instance = None self.rule_manager = None self.session = None self.config = { "IRODS_HOST": host, "IRODS_USER": user, "IRODS_PASS": password, "IRODS_CLIENT_SERVER_POLICY": "CS_NEG_REQUIRE", } def __del__(self): # iRODSSession's reference count is always > 0 due to circular # references. Therefore, losing all local references to it doesn't # imply that its __del__() method and subsequent .cleanup() will be # called. if self.session: self.session.cleanup() def connect(self): logger.info("--\t Connect to iRODS") self.rule_manager = RuleManager(admin_mode=True, config=self.config) self.session = self.rule_manager.session def prepare(self, project_id, collection_id, repository): self.project_id = project_id self.collection_id = collection_id self.connect() path = f"/nlmumc/projects/{project_id}/{collection_id}" self.collection_object = self.session.collections.get(path) self.repository = repository self.read_collection_metadata(project_id, collection_id) # clear all exporterState AVU values and re-add in-queue-for-export # in case of remaining failed report AVUs like: upload-failed , failed-dataset-creation etc .. self.update_metadata_status(ExporterState.ATTRIBUTE.value, ExporterState.IN_QUEUE_FOR_EXPORT.value) def read_collection_metadata(self, project_id, collection_id): logger.info("--\t Read collection AVU") for x in self.collection_object.metadata.items(): self.collection_avu.__dict__.update( {x.name.lower().replace("dcat:", ""): x.value}) logger.info("--\t Parse collection instance.json") instance = self.rule_manager.read_instance_from_collection( project_id, collection_id) self.instance = self.rule_manager.parse_general_instance(instance) def update_metadata_status(self, attribute, value): new_status = f"{self.repository}:{value}" self.rule_manager.set_collection_avu(self.collection_object.path, attribute, new_status) def remove_metadata(self, key, value): try: if value: self.collection_object.metadata.remove(key, value) except iRODSException as error: logger.error(f"{key} : {value} {error}") def add_metadata(self, key, value, unit=None): try: if unit is None and value: self.collection_object.metadata.add(key, value) elif value: self.collection_object.metadata.add(key, value, unit) except iRODSException as error: logger.error(f"{key} : {value} {error}") def status_cleanup(self, repository): logger.error("An error occurred during the upload") logger.error("Clean up exporterState AVU") # exporter client crashed, clean all exporterState AVUs for state in ExporterState: new_status = f"{repository}:{state.value}" self.remove_metadata(ExporterState.ATTRIBUTE.value, new_status) logger.error("Call rule closeProjectCollection") self.rule_manager.close_project_collection(self.project_id, self.collection_id)
def test_rule_get_collection_avu(): avu = RuleManager(admin_mode=True).get_collection_attribute_value( "/nlmumc/projects/P000000010/C000000001", "title") assert avu is not None
def test_get_project_collection_tape_estimate(): collection = RuleManager( admin_mode=True).get_project_collection_tape_estimate( "P000000010", "C000000001") assert collection is not None
def test_rule_get_active_drop_zones(): result = RuleManager(admin_mode=True).get_active_drop_zones("false") assert result is not None
def test_rule_get_collection_tree(): collection = RuleManager(admin_mode=True).get_collection_tree( "P000000010/C000000001", "P000000010/C000000001") assert collection is not None
def test_rule_get_project_migration_status(): result = RuleManager(admin_mode=True).get_project_migration_status( "/nlmumc/projects/P000000010") cards = result.cards assert cards is not None
def test_rule_get_collection_size_per_resource(): result = RuleManager( admin_mode=True).get_collection_size_per_resource("P000000017") assert result is not None
def test_rule_get_projects_overview(): result = RuleManager(admin_mode=True).get_projects_overview() assert result is not None
def test_rule_get_projects(): result = RuleManager(admin_mode=True).get_projects("false") assert result is not None
def test_generate_token(): result = RuleManager(admin_mode=True).generate_token() assert result is not None and result.token is not None
def test_rule_get_active_drop_zone(): result = RuleManager(admin_mode=True).get_active_drop_zone("adorable-barracuda", "true") assert result is not None
def test_rule_get_projects_finance(): project = RuleManager("opalmen").get_projects_finance() assert project.projects_cost is not None
def test_rule_get_collections(): result = RuleManager( admin_mode=True).get_collections("/nlmumc/projects/P000000011") collections = result.collections assert collections is not None assert collections[0].creator == "*****@*****.**"