def test_delete_descriptor_pharmacological_action_descriptor(self):
        """ Tests the deletion of a
            `DescriptorPharmacologicalActionDescriptor` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        descriptor_02_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI2",
            name="NewDescriptor"
        )

        # IODI a new `DescriptorPharmacologicalActionDescriptor` record.
        obj_id = self.dal.iodi_descriptor_pharmacological_action_descriptor(
            descriptor_id=descriptor_id,
            pharmacological_action_descriptor_id=descriptor_02_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorPharmacologicalActionDescriptor, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorPharmacologicalActionDescriptor,
            obj_id,
        )  # type: DescriptorPharmacologicalActionDescriptor

        self.assertIsNone(obj)
    def test_delete_descriptor_related_descriptor(self):
        """ Tests the deletion of a `DescriptorRelatedDescriptor` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        descriptor_01_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI1",
            name="Name1",
        )
        descriptor_02_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI2",
            name="Name2",
        )

        # IODI a new `DescriptorRelatedDescriptor` record.
        obj_id = self.dal.iodi_descriptor_related_descriptor(
            descriptor_id=descriptor_01_id,
            related_descriptor_id=descriptor_02_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorRelatedDescriptor, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorRelatedDescriptor,
            obj_id,
        )  # type: DescriptorRelatedDescriptor

        self.assertIsNone(obj)
    def test_iodu_study_descriptor_duplicate(self):
        """ Tests the IODU insertion of duplicate `StudyDescriptor` records to
            ensure deduplication functions as intended.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal_mesh)
        descriptor_02_id, _ = create_descriptor(
            dal=self.dal_mesh,
            ui="new_ui",
            name="new_name",
        )

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should be `1` as this is the first record.
        self.assertEqual(obj_id, 1)

        # IODU the same `StudyDescriptor` record as before.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should still be `1` as the record was identical thus no
        # insertion should've occured.
        self.assertEqual(obj_id, 1)

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_02_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should be `3` as the previous failed INSERT will have
        # incremented the PK by 1.
        self.assertEqual(obj_id, 3)

        # IODU the same `StudyDescriptor` record as before.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_02_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        # The PK should still be `3` as the record is identical to the one
        # before.
        self.assertEqual(obj_id, 3)
示例#4
0
    def test_delete_descriptor_previous_indexing(self):
        """ Tests the deletion of a `DescriptorPreviousIndexing` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        previous_indexing_id, _ = create_previous_indexing(dal=self.dal)

        # IODI a new `DescriptorPreviousIndexing` record.
        obj_id = self.dal.iodi_descriptor_previous_indexing(
            descriptor_id=descriptor_id,
            previous_indexing_id=previous_indexing_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorPreviousIndexing, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorPreviousIndexing,
            obj_id,
        )  # type: DescriptorPreviousIndexing

        self.assertIsNone(obj)
示例#5
0
    def test_iodi_get_descriptor_previous_indexing(self):
        """ Tests the IODI insertion of a `DescriptorPreviousIndexing` record
            via the `iodi_descriptor_previous_indexing` method of the `DalMesh`
            class and its retrieval via the `get` method.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        previous_indexing_id, _ = create_previous_indexing(dal=self.dal)

        # IODI a new `DescriptorPreviousIndexing` record.
        obj_id = self.dal.iodi_descriptor_previous_indexing(
            descriptor_id=descriptor_id,
            previous_indexing_id=previous_indexing_id,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            DescriptorPreviousIndexing,
            obj_id,
        )  # type: DescriptorPreviousIndexing

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_previous_indexing_id, 1)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.previous_indexing_id, previous_indexing_id)
    def test_delete_descriptor_definition(self):
        """ Tests the deletion of a `DescriptorDefinition` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)

        definition = "definition"
        md5 = hashlib.md5(definition.encode("utf-8")).digest()

        # IODI a new `DescriptorDefinition` record.
        obj_id = self.dal.iodi_descriptor_definition(
            descriptor_id=descriptor_id,
            source=DescriptorDefinitionSourceType.AIR,
            definition=definition,
            md5=md5,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorDefinition, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorDefinition,
            obj_id,
        )  # type: DescriptorDefinition

        self.assertIsNone(obj)
    def test_delete_descriptor_allowable_qualifier(self):
        """ Tests the deletion of a `DescriptorAllowableQualifier` record via
            the `delete` method of the `DalMesh` class.
        """

        # Create a `Descriptor` record as a fixture.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        # Create a `Qualifier` record as a fixture.
        qualifier_id, _ = create_qualifier(dal=self.dal)

        # IODU a new `DescriptorAllowableQualifier` record.
        obj_id = self.dal.iodu_descriptor_allowable_qualifier(
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
            abbreviation="abbreviation",
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorAllowableQualifier, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorAllowableQualifier,
            obj_id,
        )  # type: DescriptorAllowableQualifier

        self.assertIsNone(obj)
示例#8
0
    def test_iodi_get_supplemental_heading_mapped_to(self):
        """ Tests the IODI insertion of a `SupplementalHeadingMappedTo` record
            via the `iodi_supplemental_heading_mapped_to` method of the
            `DalMesh` class and its retrieval via the `get` method.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        qualifier_id, _ = create_qualifier(dal=self.dal)
        entry_combination_id, _ = create_entry_combination(
            dal=self.dal,
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
        )
        supplemental_id, _ = create_supplemental(dal=self.dal)

        # IODI a new `SupplementalHeadingMappedTo` record.
        obj_id = self.dal.iodi_supplemental_heading_mapped_to(
            supplemental_id=supplemental_id,
            entry_combination_id=entry_combination_id,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            SupplementalHeadingMappedTo,
            obj_id,
        )  # type: SupplementalHeadingMappedTo

        # Assert that the different fields of the record match.
        self.assertEqual(obj.supplemental_heading_mapped_to_id, 1)
        self.assertEqual(obj.supplemental_id, supplemental_id)
        self.assertEqual(obj.entry_combination_id, entry_combination_id)
示例#9
0
    def test_delete_supplemental_heading_mapped_to(self):
        """ Tests the deletion of a `SupplementalHeadingMappedTo` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        qualifier_id, _ = create_qualifier(dal=self.dal)
        entry_combination_id, _ = create_entry_combination(
            dal=self.dal,
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
        )
        supplemental_id, _ = create_supplemental(dal=self.dal)

        # IODI a new `SupplementalHeadingMappedTo` record.
        obj_id = self.dal.iodi_supplemental_heading_mapped_to(
            supplemental_id=supplemental_id,
            entry_combination_id=entry_combination_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(SupplementalHeadingMappedTo, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            SupplementalHeadingMappedTo,
            obj_id,
        )  # type: SupplementalHeadingMappedTo

        self.assertIsNone(obj)
示例#10
0
    def test_delete_descriptor_concept(self):
        """ Tests the deletion of a `DescriptorConcept` record via the `delete`
            method of the `DalMesh` class.
        """

        # Create a `Descriptor` record as a fixture.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        # Create a `Concept` record as a fixture.
        concept_id, _ = create_concept(dal=self.dal)

        # IODU a new `DescriptorConcept` record.
        obj_id = self.dal.iodu_descriptor_concept(
            descriptor_id=descriptor_id,
            concept_id=concept_id,
            is_preferred=True,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorConcept, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(DescriptorConcept,
                           obj_id)  # type: DescriptorConcept

        self.assertIsNone(obj)
示例#11
0
    def test_iodi_get_descriptor_entry_combination(self):
        """ Tests the IODI insertion of a `DescriptorEntryCombination` record
            via the `iodi_descriptor_entry_combination` method of the `DalMesh`
            class and its retrieval via the `get` method.
        """

        # Create fixture records.
        qualifier_id, _ = create_qualifier(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal)
        entry_combination_id, _ = create_entry_combination(
            dal=self.dal,
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
        )

        # IODI a new `DescriptorEntryCombination` record.
        obj_id = self.dal.iodi_descriptor_entry_combination(
            descriptor_id=descriptor_id,
            entry_combination_id=entry_combination_id,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            DescriptorEntryCombination,
            obj_id,
        )  # type: DescriptorEntryCombination

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_entry_combination_id, 1)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.entry_combination_id, entry_combination_id)
    def test_delete_descriptor_tree_number(self):
        """ Tests the deletion of a `DescriptorTreeNumber` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        tree_number_id, _ = create_tree_number(dal=self.dal)

        # IODI a new `DescriptorTreeNumber` record.
        obj_id = self.dal.iodi_descriptor_tree_number(
            descriptor_id=descriptor_id,
            tree_number_id=tree_number_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorTreeNumber, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorTreeNumber,
            obj_id,
        )  # type: DescriptorTreeNumber

        self.assertIsNone(obj)
    def test_iodi_get_descriptor_tree_number(self):
        """ Tests the IODI insertion of a `DescriptorTreeNumber` record via the
            `iodi_descriptor_tree_number` method of the `DalMesh` class and its
            retrieval via the `get` method.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        tree_number_id, _ = create_tree_number(dal=self.dal)

        # IODI a new `DescriptorTreeNumber` record.
        obj_id = self.dal.iodi_descriptor_tree_number(
            descriptor_id=descriptor_id,
            tree_number_id=tree_number_id,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            DescriptorTreeNumber,
            obj_id,
        )  # type: DescriptorTreeNumber

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_tree_number_id, 1)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.tree_number_id, tree_number_id)
    def test_iodu_get_study_descriptor(self):
        """ Tests the insertion of a `StudyDescriptor` record via the
            `iodu_study_descriptor` method of the `DalClinicalTrials` class and
            its retrieval via the get` method.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal_mesh)

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(StudyDescriptor, obj_id)  # type: StudyDescriptor

        # Assert that the different fields of the record match.
        self.assertEqual(obj.study_descriptor_id, 1)
        self.assertEqual(obj.study_id, study_id)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.study_descriptor_type, MeshTermType.CONDITION)
    def test_delete_study_descriptor(self):
        """ Tests the deletion of a `StudyDescriptor` record via the `delete`
            method of the `DalClinicalTrials` class.
        """

        # Create fixtures.
        study_id, _ = create_study(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal_mesh)

        # IODU a new `StudyDescriptor` record.
        obj_id = self.dal.iodu_study_descriptor(
            study_id=study_id,
            descriptor_id=descriptor_id,
            study_descriptor_type=MeshTermType.CONDITION,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(StudyDescriptor, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(StudyDescriptor, obj_id)  # type: StudyDescriptor

        self.assertIsNone(obj)
示例#16
0
    def test_iodu_get_descriptor_concept(self):
        """ Tests the IODU insertion of a `DescriptorConcept` record via the
            `iodu_descriptor_concept` method of the `DalMesh` class and its
            retrieval via the `get` method.
        """

        # Create a `Descriptor` record as a fixture.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        # Create a `Concept` record as a fixture.
        concept_id, _ = create_concept(dal=self.dal)

        # IODU a new `DescriptorConcept` record.
        obj_id = self.dal.iodu_descriptor_concept(
            descriptor_id=descriptor_id,
            concept_id=concept_id,
            is_preferred=True,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(DescriptorConcept,
                           obj_id)  # type: DescriptorConcept

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_concept_id, obj_id)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.concept_id, concept_id)
        self.assertEqual(obj.is_preferred, True)
示例#17
0
    def test_iodi_get_supplemental_pharmacological_action_descriptor(self):
        """ Tests the IODI insertion of a
            `SupplementalPharmacologicalActionDescriptor` record via the
            `iodi_supplemental_pharmacological_action_descriptor` method of the
            `DalMesh` class and its retrieval via the `get` method.
        """

        # Create fixture records.
        supplemental_id, _ = create_supplemental(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal)

        # IODI a new `SupplementalPharmacologicalActionDescriptor` record.
        obj_id = self.dal.iodi_supplemental_pharmacological_action_descriptor(
            supplemental_id=supplemental_id,
            pharmacological_action_descriptor_id=descriptor_id,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            SupplementalPharmacologicalActionDescriptor,
            obj_id,
        )  # type: SupplementalPharmacologicalActionDescriptor

        # Assert that the different fields of the record match.
        self.assertEqual(
            obj.supplemental_pharmacological_action_descriptor_id,
            1,
        )
        self.assertEqual(obj.supplemental_id, supplemental_id)
        self.assertEqual(
            obj.pharmacological_action_descriptor_id,
            descriptor_id,
        )
示例#18
0
    def test_iodu_get_descriptor(self):
        """ Tests the IODU insertion of a `Descriptor` record via the
            `iodu_descriptor` method of the `DalMesh` class and its retrieval
            via the `get` method.
        """

        # Create a new `Descriptor` record.
        obj_id, refr = create_descriptor(dal=self.dal)

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(Descriptor, obj_id)  # type: Descriptor

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_id, obj_id)
        self.assertEqual(obj.ui, refr["ui"])
        self.assertEqual(obj.name, refr["name"])
        self.assertEqual(obj.created, refr["created"])
        self.assertEqual(obj.revised, refr["revised"])
        self.assertEqual(obj.established, refr["established"])
        self.assertEqual(obj.annotation, refr["annotation"])
        self.assertEqual(obj.history_note, refr["history_note"])
        self.assertEqual(
            obj.nlm_classification_number,
            refr["nlm_classification_number"],
        )
        self.assertEqual(obj.online_note, refr["online_note"])
        self.assertEqual(obj.public_mesh_note, refr["public_mesh_note"])
        self.assertEqual(obj.consider_also, refr["consider_also"])
示例#19
0
    def test_delete_supplemental_pharmacological_action_descriptor(self):
        """ Tests the deletion of a
            `SupplementalPharmacologicalActionDescriptor` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        supplemental_id, _ = create_supplemental(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal)

        # IODI a new `SupplementalPharmacologicalActionDescriptor` record.
        obj_id = self.dal.iodi_supplemental_pharmacological_action_descriptor(
            supplemental_id=supplemental_id,
            pharmacological_action_descriptor_id=descriptor_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(SupplementalPharmacologicalActionDescriptor, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            SupplementalPharmacologicalActionDescriptor,
            obj_id,
        )  # type: SupplementalPharmacologicalActionDescriptor

        self.assertIsNone(obj)
    def test_iodi_get_descriptor_definition(self):
        """ Tests the IODI insertion of a `DescriptorDefinition` record via the
            `iodi_descriptor_definition` method of the `DalMesh` class and its
            retrieval via the `get` method.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)

        definition = "definition"
        md5 = hashlib.md5(definition.encode("utf-8")).digest()

        # IODI a new `DescriptorDefinition` record.
        obj_id = self.dal.iodi_descriptor_definition(
            descriptor_id=descriptor_id,
            source=DescriptorDefinitionSourceType.AIR,
            definition=definition,
            md5=md5,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            DescriptorDefinition,
            obj_id,
        )  # type: DescriptorDefinition

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_definition_id, 1)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.source, DescriptorDefinitionSourceType.AIR)
        self.assertEqual(obj.definition, definition)
        self.assertEqual(obj.md5, md5)
示例#21
0
    def test_delete_descriptor_entry_combination(self):
        """ Tests the deletion of a `DescriptorEntryCombination` record via the
            `delete` method of the `DalMesh` class.
        """

        # Create fixture records.
        qualifier_id, _ = create_qualifier(dal=self.dal)
        descriptor_id, _ = create_descriptor(dal=self.dal)
        entry_combination_id, _ = create_entry_combination(
            dal=self.dal,
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
        )

        # IODI a new `DescriptorEntryCombination` record.
        obj_id = self.dal.iodi_descriptor_entry_combination(
            descriptor_id=descriptor_id,
            entry_combination_id=entry_combination_id,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(DescriptorEntryCombination, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(
            DescriptorEntryCombination,
            obj_id,
        )  # type: DescriptorEntryCombination

        self.assertIsNone(obj)
    def test_iodu_get_descriptor_allowable_qualifier(self):
        """ Tests the IODU insertion of a `DescriptorAllowableQualifier` record
            via the `iodu_descriptor_allowable_qualifier` method of the
            `DalMesh` class and its retrieval via the `get` method.
        """

        # Create a `Descriptor` record as a fixture.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        # Create a `Qualifier` record as a fixture.
        qualifier_id, _ = create_qualifier(dal=self.dal)

        # IODU a new `DescriptorAllowableQualifier` record.
        obj_id = self.dal.iodu_descriptor_allowable_qualifier(
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
            abbreviation="abbreviation",
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(
            DescriptorAllowableQualifier,
            obj_id,
        )  # type: DescriptorAllowableQualifier

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_allowable_qualifier_id, obj_id)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.qualifier_id, qualifier_id)
        self.assertEqual(obj.abbreviation, "abbreviation")
示例#23
0
    def test_biodi_get_descriptor_synonyms(self):
        """ Tests the BIODI insertion of multiple `DescriptorSynonym` records
            via the `biodi_descriptor_synonyms` method of the `DalMesh` class
            and its retrieval via the `get` method.
        """

        # Create a new `Descriptor` record.
        descriptor_id, _ = create_descriptor(dal=self.dal)

        synonyms = ["synonym01", "synonym02", "synonym03", "synonym04"]

        # Create a new `DescriptorSynonym` record.
        self.dal.biodi_descriptor_synonyms(
            descriptor_id=descriptor_id,
            synonyms=synonyms,
            md5s=self._get_md5s(values=synonyms),
        )

        # Retrieve all `DescriptorSynonym` records for the new `Descriptor`.
        objs = self.dal.bget_by_attr(
            orm_class=DescriptorSynonym,
            attr_name="descriptor_id",
            attr_values=[descriptor_id],
            do_sort=True,
        )  # type: List[DescriptorSynonym]

        self.assertEqual(len(objs), len(synonyms))

        synonyms_eval = [obj.synonym for obj in objs]

        self.assertListEqual(synonyms_eval, synonyms)
示例#24
0
    def test_biodi_get_descriptor_synonym(self):
        """ Tests the BIODI insertion of a single `DescriptorSynonym` record via
            the `biodi_descriptor_synonyms` method of the `DalMesh` class and
            its retrieval via the `get` method.
        """

        # Create a new `Descriptor` record.
        descriptor_id, _ = create_descriptor(dal=self.dal)

        synonyms = ["synonym"]

        # Create a new `DescriptorSynonym` record.
        self.dal.biodi_descriptor_synonyms(
            descriptor_id=descriptor_id,
            synonyms=synonyms,
            md5s=self._get_md5s(values=synonyms),
        )

        # Retrieve all `DescriptorSynonym` records for the new `Descriptor`.
        objs = self.dal.bget_by_attr(
            orm_class=DescriptorSynonym,
            attr_name="descriptor_id",
            attr_values=[descriptor_id],
            do_sort=True,
        )  # type: List[DescriptorSynonym]

        self.assertEqual(len(objs), 1)

        obj = objs[0]

        # Assert that the different fields of the record match.
        self.assertEqual(obj.descriptor_synonym_id, 1)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.synonym, synonyms[0])
        self.assertEqual(obj.md5, self._get_md5s(values=synonyms)[0])
示例#25
0
    def test_get_joined_mutliple_relationship(self):
        """ Tests the `get_joined` method with multiple relationships."""

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        tree_number_id, _ = create_tree_number(dal=self.dal)
        concept_id, _ = create_concept(dal=self.dal)

        # IODI a new `DescriptorTreeNumber` record.
        self.dal.iodi_descriptor_tree_number(
            descriptor_id=descriptor_id,
            tree_number_id=tree_number_id,
        )

        # IODU a new `DescriptorConcept` record.
        self.dal.iodu_descriptor_concept(
            descriptor_id=descriptor_id,
            concept_id=concept_id,
            is_preferred=True,
        )

        # Retrieve the `Descriptor` join-loaded with its `TreeNumber` and
        # `Concept` record.
        obj = self.dal.get_joined(
            orm_class=Descriptor,
            pk=descriptor_id,
            joined_relationships=["tree_numbers",
                                  "concepts"])  # type: Descriptor

        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertIsNotNone(obj.tree_numbers)
        self.assertIsNotNone(obj.concepts)
示例#26
0
    def test_iodu_get_entry_combination(self):
        """ Tests the IODU insertion of a `EntryCombination` record via the
            `iodu_entry_combination` method of the `DalMesh` class and its
            retrieval via the `get` method.
        """

        # Create a `Qualifier` record as a fixture.
        qualifier_id, _ = create_qualifier(dal=self.dal)
        # Create a `Descriptor` record as a fixture.
        descriptor_id, _ = create_descriptor(dal=self.dal)

        # IODU a new `EntryCombination` record.
        obj_id = self.dal.iodu_entry_combination(
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
            combination_type=EntryCombinationType.ECIN,
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(EntryCombination, obj_id)  # type: EntryCombination

        # Assert that the different fields of the record match.
        self.assertEqual(obj.entry_combination_id, obj_id)
        self.assertEqual(obj.descriptor_id, descriptor_id)
        self.assertEqual(obj.qualifier_id, qualifier_id)
        self.assertEqual(obj.combination_type, EntryCombinationType.ECIN)
示例#27
0
    def test_delete_entry_combination(self):
        """ Tests the deletion of a `EntryCombination` record via the `delete`
            method of the `DalMesh` class.
        """

        # Create a `Qualifier` record as a fixture.
        qualifier_id, _ = create_qualifier(dal=self.dal)
        # Create a `Descriptor` record as a fixture.
        descriptor_id, _ = create_descriptor(dal=self.dal)

        # IODU a new `EntryCombination` record.
        obj_id = self.dal.iodu_entry_combination(
            descriptor_id=descriptor_id,
            qualifier_id=qualifier_id,
            combination_type=EntryCombinationType.ECIN,
        )

        self.assertEqual(obj_id, 1)

        # Delete the new record.
        self.dal.delete(EntryCombination, obj_id)

        # (Attempt to) retrieve the deleted record.
        obj = self.dal.get(EntryCombination, obj_id)  # type: EntryCombination

        self.assertIsNone(obj)
示例#28
0
    def test_iodu_descriptor_duplicate(self):
        """ Tests the IODU insertion of duplicate `Descriptor` records to ensure
            deduplication functions as intended.
        """

        # Create a new `Descriptor` record.
        obj_id, refr = create_descriptor(dal=self.dal)

        self.assertEqual(obj_id, 1)

        # IODU the same `Descriptor` record.
        obj_id, refr = create_descriptor(dal=self.dal)

        self.assertEqual(obj_id, 1)

        # IODU the same `Descriptor` record with a changed `history_note` field
        # which should trigger an update on the existing record.
        obj_id, refr = create_descriptor(
            dal=self.dal,
            history_note="different history note"
        )

        self.assertEqual(obj_id, 1)

        # Retrieve the new record.
        obj = self.dal.get(Descriptor, obj_id)  # type: Descriptor

        self.assertEqual(obj.history_note, "different history note")

        # IODU a new `Descriptor` record.
        obj_id, refr = create_descriptor(
            dal=self.dal,
            ui="D000057",
            name="NewDescriptor"
        )

        self.assertEqual(obj_id, 4)

        # IODU the same `Descriptor` record as before.
        obj_id, refr = create_descriptor(
            dal=self.dal,
            ui="D000057",
            name="NewDescriptor"
        )

        self.assertEqual(obj_id, 4)
    def test_iodi_descriptor_related_descriptor_duplicate(self):
        """ Tests the IODI insertion of duplicate `DescriptorRelatedDescriptor`
            records to ensure deduplication functions as intended.
        """

        # Create fixture records.
        descriptor_01_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI1",
            name="Name1",
        )
        descriptor_02_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI2",
            name="Name2",
        )
        descriptor_03_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI3",
            name="Name3",
        )

        # IODI a new `DescriptorRelatedDescriptor` record.
        obj_id = self.dal.iodi_descriptor_related_descriptor(
            descriptor_id=descriptor_01_id,
            related_descriptor_id=descriptor_02_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI an identical `DescriptorRelatedDescriptor` record.
        obj_id = self.dal.iodi_descriptor_related_descriptor(
            descriptor_id=descriptor_01_id,
            related_descriptor_id=descriptor_02_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI a new `DescriptorRelatedDescriptor` record.
        obj_id = self.dal.iodi_descriptor_related_descriptor(
            descriptor_id=descriptor_01_id,
            related_descriptor_id=descriptor_03_id,
        )

        self.assertEqual(obj_id, 3)
    def test_iodi_descriptor_pharmacological_action_descriptor_duplicate(
        self
    ):
        """ Tests the IODI insertion of duplicate
            `DescriptorPharmacologicalActionDescriptor` records to ensure
            deduplication functions as intended.
        """

        # Create fixture records.
        descriptor_id, _ = create_descriptor(dal=self.dal)
        descriptor_02_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI2",
            name="NewDescriptor"
        )
        descriptor_03_id, _ = create_descriptor(
            dal=self.dal,
            ui="UI3",
            name="NewerDescriptor"
        )

        # IODI a new `DescriptorPharmacologicalActionDescriptor` record.
        obj_id = self.dal.iodi_descriptor_pharmacological_action_descriptor(
            descriptor_id=descriptor_id,
            pharmacological_action_descriptor_id=descriptor_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI an identical `DescriptorPharmacologicalActionDescriptor`
        # record.
        obj_id = self.dal.iodi_descriptor_pharmacological_action_descriptor(
            descriptor_id=descriptor_id,
            pharmacological_action_descriptor_id=descriptor_id,
        )

        self.assertEqual(obj_id, 1)

        # IODI a new `DescriptorPharmacologicalActionDescriptor` record.
        obj_id = self.dal.iodi_descriptor_pharmacological_action_descriptor(
            descriptor_id=descriptor_id,
            pharmacological_action_descriptor_id=descriptor_02_id,
        )

        self.assertEqual(obj_id, 3)