def _matches(cookie: Cookie, context: HgiContext) -> bool:
    """
    Matches if the creation of the data object in iRODS has been observed but the reference has been set to one that we
    are not interested in. The order of these events is not considered.
    """
    if not was_creation_observed(cookie.enrichments):
        return False

    reference = extract_latest_metadata_key_value_known_in_irods(cookie.enrichments, IRODS_REFERENCE_KEY)
    if reference is None:
        # No update to reference yet
        return False
    if len(reference) != 1:
        # Multiple values for reference is unexpected
        return False

    reference_species_groups = re.match(_REFERENCE_EXTRACTION_PATTERN, list(reference)[0])
    if reference_species_groups is None:
        # Reference is in unexpected format
        return False
    reference_species = reference_species_groups.group(1)

    # Read uninteresting references from file every time to (easily) support live updates to this list
    with open(KNOWN_UNINTERESTING_REFERENCES_PATH, "r") as file:
        uninteresting_references = file.read().splitlines()

    return reference_species in uninteresting_references
Esempio n. 2
0
 def test_creation_observed(self):
     modified_replicas = DataObjectReplicaCollection(
         {DataObjectReplica(IRODS_FIRST_REPLICA_TO_BE_CREATED_VALUE, "")})
     modification = DataObjectModification(IrodsMetadata({"other": {"value"}}), modified_replicas)
     modification_as_dict = DataObjectModificationJSONEncoder().default(modification)
     self.enrichment_collection.add([
         Enrichment(IRODS_UPDATE_ENRICHMENT, datetime(1, 1, 1), UNINTERESTING_DATA_OBJECT_MODIFICATION_AS_METADATA),
         Enrichment(IRODS_UPDATE_ENRICHMENT, datetime(2, 2, 2), Metadata(modification_as_dict)),
         Enrichment(IRODS_UPDATE_ENRICHMENT, datetime(3, 3, 3), UNINTERESTING_DATA_OBJECT_MODIFICATION_AS_METADATA),
     ])
     self.assertTrue(was_creation_observed(self.enrichment_collection))
def _matches(cookie: Cookie, context: HgiContext) -> bool:
    """
    Matches if the creation has been observed and the manual QC has been set to an incorrect value. The order of these
    events is not considered.
    """
    if not was_creation_observed(cookie.enrichments):
        return False

    manual_qc = extract_latest_metadata_key_value_known_in_irods(cookie.enrichments, IRODS_MANUAL_QC_KEY)
    if manual_qc is None:
        # No update to manual QC yet
        return False
    if len(manual_qc) != 1:
        # Multiple values for manual QC is unexpected
        return False
    return INCORRECT_MANUAL_QC_VALUE in manual_qc
Esempio n. 4
0
 def test_unrelated_enrichment(self):
     self.enrichment_collection.add(Enrichment("other", datetime(1, 1, 1), Metadata()))
     self.assertFalse(was_creation_observed(self.enrichment_collection))
Esempio n. 5
0
 def test_no_enrichments(self):
     self.assertFalse(was_creation_observed(self.enrichment_collection))