diff --git a/app/routers/bioentity.py b/app/routers/bioentity.py index 7f525c2..ff33393 100644 --- a/app/routers/bioentity.py +++ b/app/routers/bioentity.py @@ -28,6 +28,15 @@ class RelationshipType(str, Enum): + + """ + Enumeration for Gene Ontology relationship types used for filtering associations. + + :param INVOLVED_IN: The 'involved_in' relationship type. + :param ACTS_UPSTREAM_OF_OR_WITHIN: The 'acts_upstream_of_or_within' relationship type. + :param INVOLVED_IN_REGULATION_OF: The 'involved_in_regulation_of' relationship type. + """ + INVOLVED_IN = INVOLVED_IN ACTS_UPSTREAM_OF_OR_WITHIN = ACTS_UPSTREAM_OF_OR_WITHIN INVOLVED_IN_REGULATION_OF = INVOLVED_IN_REGULATION_OF @@ -67,7 +76,6 @@ async def get_bioentity_by_id( 'start' determines the starting index for fetching results, and 'rows' specifies the number of results to be retrieved per page. """ - # special case MGI, sigh if id.startswith("MGI:"): id = id.replace("MGI:", "MGI:MGI:") @@ -97,7 +105,8 @@ async def get_annotations_by_goterm_id( start: int = 0, rows: int = 100, ): - """Returns annotations using the provided GO term. + """ + Returns annotations using the provided GO term. Retrieves annotations based on the provided Gene Ontology (GO) term identifier. The GO term identifier should be represented in CURIE format (e.g., GO:0044598). @@ -175,7 +184,8 @@ async def get_genes_by_goterm_id( start: int = 0, rows: int = 100, ): - """Returns genes annotated to the provided GO Term. + """ + Returns genes annotated to the provided GO Term. Retrieves genes annotated to the provided Gene Ontology (GO) term. The GO term should be represented in CURIE format (e.g., GO:0044598). @@ -261,7 +271,8 @@ async def get_taxon_by_goterm_id( start: int = 0, rows: int = 100, ): - """Returns taxon information for genes annotated to the provided GO term. + """ + Returns taxon information for genes annotated to the provided GO term. Retrieves taxon information for genes annotated to the provided Gene Ontology (GO) term. The GO term should be represented in CURIE format (e.g., GO:0044598). diff --git a/tests/unit/test_models_endpoints.py b/tests/unit/test_models_endpoints.py index 62330db..90d6b93 100644 --- a/tests/unit/test_models_endpoints.py +++ b/tests/unit/test_models_endpoints.py @@ -1,101 +1,125 @@ import logging - -import pytest +import unittest from fastapi.testclient import TestClient - from app.main import app test_client = TestClient(app) gene_ids = ["ZFIN:ZDB-GENE-980526-388", "ZFIN:ZDB-GENE-990415-8", "MGI:3588192"] -go_ids = ["GO:0008150"] -subsets = ["goslim_agr"] -shared_ancestors = [("GO:0006259", "GO:0046483")] -uris = ["http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0008150"] - -logger = logging.getLogger(__name__) - - -def test_gometadata_by_model_ids(): - data = {"gocams": ["59a6110e00000067", "SYNGO_369"]} - response = test_client.get("/api/models/go", params=data) - assert response.status_code == 200 - assert len(response.json()) == 2 - - -def test_geneproductmetadata_by_model_ids(): - data = {"gocams": ["59a6110e00000067", "SYNGO_369"]} - response = test_client.get("/api/models/gp", params=data) - assert response.status_code == 200 - assert len(response.json()) == 2 - - -def test_pubmedmetadata_by_model_ids(): - data = {"gocams": ["59a6110e00000067", "SYNGO_369"]} - response = test_client.get("/api/models/pmid", params=data) - assert response.status_code == 200 - assert len(response.json()) == 2 - - -@pytest.mark.parametrize("id", gene_ids) -def test_bioenty_id_endpoints(id): - response = test_client.get(f"/api/bioentity/{id}") - assert response.status_code == 200 - - -def test_gocam_by_model_ids(): - response = test_client.get("/api/models/581e072c00000820") - assert len(response.json()) > 125 - assert response.status_code == 200 - - -def test_models_size_endpoint(): - data = { - "start": "32", - "size": "10", - } - response = test_client.get("/api/models", params=data) - for record in response.json(): - assert type(record.get("orcids")) == list - assert response.status_code == 200 - - -def test_userlist(): - response = test_client.get("/api/users") - assert len(response.json()) > 100 - assert response.status_code == 200 - - -def test_grouplist(): - response = test_client.get("/api/groups") - assert len(response.json()) > 15 - assert response.status_code == 200 - - -def test_groups_by_name(): - response = test_client.get("/api/groups/MGI") - assert len(response.json()) > 10 - assert response.status_code == 200 - - -def test_get_modelid_by_pmid(): - response = test_client.get("/api/pmid/15314168/models") - assert len(response.json()) == 1 - assert response.status_code == 200 - -def test_get_go_term_detail_by_go_id(): - response = test_client.get("/api/go/GO_0008150") - assert "goid" in response.json() - assert "label" in response.json() - assert response.json().get("goid") == "http://purl.obolibrary.org/obo/GO_0008150" - assert response.json().get("label") == "biological_process" - assert type(response.json()) == dict - assert response.status_code == 200 +class TestApp(unittest.TestCase): + + def test_gometadata_by_model_ids(self): + """ + Test the endpoint to retrieve GO metadata by model IDs. + """ + data = {"gocams": ["59a6110e00000067", "SYNGO_369"]} + response = test_client.get("/api/models/go", params=data) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.json()), 2) + + def test_geneproductmetadata_by_model_ids(self): + """ + Test the endpoint to retrieve gene product metadata by model IDs. + """ + data = {"gocams": ["59a6110e00000067", "SYNGO_369"]} + response = test_client.get("/api/models/gp", params=data) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.json()), 2) + + def test_pubmedmetadata_by_model_ids(self): + """ + Test the endpoint to retrieve PubMed metadata by model IDs. + """ + data = {"gocams": ["59a6110e00000067", "SYNGO_369"]} + response = test_client.get("/api/models/pmid", params=data) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.json()), 2) + + def test_bioenty_id_endpoints(self): + """ + Test the bioentity endpoint for each given ID. + """ + for id in gene_ids: + response = test_client.get(f"/api/bioentity/{id}") + self.assertEqual(response.status_code, 200) + + def test_gocam_by_model_ids(self): + """ + Test the endpoint to retrieve GO-CAMs by model IDs. + """ + response = test_client.get("/api/models/581e072c00000820") + self.assertGreater(len(response.json()), 125) + self.assertEqual(response.status_code, 200) + + def test_models_size_endpoint(self): + """ + Test the endpoint to retrieve models with specified size. + """ + data = { + "start": "32", + "size": "10", + } + response = test_client.get("/api/models", params=data) + for record in response.json(): + self.assertIsInstance(record.get("orcids"), list) + self.assertEqual(response.status_code, 200) + + def test_userlist(self): + """ + Test the endpoint to retrieve the list of users. + """ + response = test_client.get("/api/users") + self.assertGreater(len(response.json()), 100) + self.assertEqual(response.status_code, 200) + + def test_grouplist(self): + """ + Test the endpoint to retrieve the list of groups. + """ + response = test_client.get("/api/groups") + self.assertGreater(len(response.json()), 15) + self.assertEqual(response.status_code, 200) + + def test_groups_by_name(self): + """ + Test the endpoint to retrieve groups by name. + """ + response = test_client.get("/api/groups/MGI") + self.assertGreater(len(response.json()), 10) + self.assertEqual(response.status_code, 200) + + def test_get_modelid_by_pmid(self): + """ + Test the endpoint to retrieve model IDs by PubMed ID. + """ + response = test_client.get("/api/pmid/15314168/models") + self.assertEqual(len(response.json()), 1) + self.assertEqual(response.status_code, 200) + + def test_get_go_term_detail_by_go_id(self): + """ + Test the endpoint to retrieve GO term details by GO ID. + """ + response = test_client.get("/api/go/GO_0008150") + self.assertIn("goid", response.json()) + self.assertIn("label", response.json()) + self.assertEqual(response.json()["goid"], "http://purl.obolibrary.org/obo/GO_0008150") + self.assertEqual(response.json()["label"], "biological_process") + self.assertIsInstance(response.json(), dict) + self.assertEqual(response.status_code, 200) + + def test_get_gocam_models_by_go_id(self): + """ + Test the endpoint to retrieve GO-CAM models by GO ID. + """ + id = "GO:0008150" + response = test_client.get(f"/api/go/{id}/models") + self.assertGreater(len(response.json()), 100) + self.assertEqual(response.status_code, 200) + + +if __name__ == '__main__': + unittest.main() -def test_get_gocam_models_by_go_id(): - id = "GO:0008150" - response = test_client.get(f"/api/go/{id}/models") - assert len(response.json()) > 100 - assert response.status_code == 200 diff --git a/tests/unit/test_ontology_endpoints.py b/tests/unit/test_ontology_endpoints.py index d176056..afe2705 100644 --- a/tests/unit/test_ontology_endpoints.py +++ b/tests/unit/test_ontology_endpoints.py @@ -1,72 +1,93 @@ -import logging - -import pytest +import unittest from fastapi.testclient import TestClient - from app.main import app test_client = TestClient(app) +# Test data gene_ids = ["ZFIN:ZDB-GENE-980526-388", "ZFIN:ZDB-GENE-990415-8", "MGI:3588192"] go_ids = ["GO:0008150"] subsets = ["goslim_agr"] shared_ancestors = [("GO:0006259", "GO:0046483")] uris = ["http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0008150"] -logger = logging.getLogger(__name__) - - -@pytest.mark.parametrize("id", go_ids) -def test_term_id_endpoint(id): - response = test_client.get(f"/api/ontology/term/{id}") - assert response.status_code == 200 - - -@pytest.mark.parametrize("id", go_ids) -def test_term_subsets_endpoint(id): - response = test_client.get(f"/api/ontology/term/{id}/subsets") - assert response.status_code == 200 - - -@pytest.mark.parametrize("id", subsets) -def test_term_by_subset_endpoint(id): - response = test_client.get(f"/api/ontology/subset/{id}") - assert response.status_code == 200 - - -def test_ontology_ancestors_shared_sub_obj(): - subject = "GO:0006259" - object = "GO:0046483" - response = test_client.get(f"/api/ontology/shared/{subject}/{object}") - assert response.status_code == 200 - - -@pytest.mark.parametrize("id", subsets) -def test_ontology_subset(id): - response = test_client.get(f"/api/ontology/subset/{id}") - assert response.status_code == 200 - - -@pytest.mark.parametrize("id", go_ids) -def test_ontology_term_id(id): - response = test_client.get(f"/api/ontology/term/{id}") - assert response.status_code == 200 - - -@pytest.mark.parametrize("id", go_ids) -def test_ontology_term_graph(id): - response = test_client.get(f"/api/ontology/term/{id}/subgraph") - assert response.status_code == 200 - - -@pytest.mark.parametrize("id", go_ids) -def test_ontology_term_subgraph(id): - data = {"graph_type": "topology_graph"} - response = test_client.get(f"/api/ontology/term/{id}/graph", params=data) - assert response.status_code == 200 - -@pytest.mark.parametrize("id", go_ids) -def test_ontology_term_subsets(id): - response = test_client.get(f"/api/ontology/term/{id}/subsets") - assert response.status_code == 200 +class TestApp(unittest.TestCase): + + def test_term_id_endpoint(self): + """ + Test the endpoint to get the details of a Gene Ontology term by its identifier. + """ + for id in go_ids: + response = test_client.get(f"/api/ontology/term/{id}") + self.assertEqual(response.status_code, 200) + + def test_term_subsets_endpoint(self): + """ + Test the endpoint to get the subsets of a Gene Ontology term by its identifier. + """ + for id in go_ids: + response = test_client.get(f"/api/ontology/term/{id}/subsets") + self.assertEqual(response.status_code, 200) + + def test_term_by_subset_endpoint(self): + """ + Test the endpoint to get the Gene Ontology terms associated with a given subset. + """ + for id in subsets: + response = test_client.get(f"/api/ontology/subset/{id}") + self.assertEqual(response.status_code, 200) + + def test_ontology_ancestors_shared_sub_obj(self): + """ + Test the endpoint to get shared ancestors between two Gene Ontology terms. + """ + subject = "GO:0006259" + object = "GO:0046483" + response = test_client.get(f"/api/ontology/shared/{subject}/{object}") + self.assertEqual(response.status_code, 200) + + def test_ontology_subset(self): + """ + Test the endpoint to get the details of a Gene Ontology subset by its identifier. + """ + for id in subsets: + response = test_client.get(f"/api/ontology/subset/{id}") + self.assertEqual(response.status_code, 200) + + def test_ontology_term_id(self): + """ + Test the endpoint to get the details of a Gene Ontology term by its identifier. + """ + for id in go_ids: + response = test_client.get(f"/api/ontology/term/{id}") + self.assertEqual(response.status_code, 200) + + def test_ontology_term_graph(self): + """ + Test the endpoint to get the subgraph of a Gene Ontology term by its identifier. + """ + for id in go_ids: + response = test_client.get(f"/api/ontology/term/{id}/subgraph") + self.assertEqual(response.status_code, 200) + + def test_ontology_term_subgraph(self): + """ + Test the endpoint to get the subgraph of a Gene Ontology term by its identifier. + """ + data = {"graph_type": "topology_graph"} + for id in go_ids: + response = test_client.get(f"/api/ontology/term/{id}/graph", params=data) + self.assertEqual(response.status_code, 200) + + def test_ontology_term_subsets(self): + """ + Test the endpoint to get the subsets of a Gene Ontology term by its identifier. + """ + for id in go_ids: + response = test_client.get(f"/api/ontology/term/{id}/subsets") + self.assertEqual(response.status_code, 200) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/test_ontology_utils.py b/tests/unit/test_ontology_utils.py index ac2cfcd..3da665e 100644 --- a/tests/unit/test_ontology_utils.py +++ b/tests/unit/test_ontology_utils.py @@ -1,5 +1,5 @@ import logging - +import unittest import pytest from fastapi.testclient import TestClient from ontobio.sparql.sparql_ontology import EagerRemoteSparqlOntology @@ -13,231 +13,85 @@ go_ids = ["GO:0008150"] -def test_get_ontology_config(): - golr_url = get_golr_config()["solr_url"]["url"] - assert "golr-aux.geneontology.io" in golr_url - - -def test_go_sparql(): - results = ou.goont_fetch_label("GO:0008150") - assert results == "biological_process" - - -def test_get_ontology(): - return_value = ou.get_ontology(id="go") - assert type(return_value) is EagerRemoteSparqlOntology - assert return_value.handle == "go" - - -def test_get_category_terms(): - category = { - "description": "A location, relative to cellular compartments and structures, occupied by a macromolecular " - "machine when it carries out a molecular function. There are two ways in which the " - "gene ontology describes locations of gene products: (1) relative to cellular" - " structures (e.g., cytoplasmic side of plasma membrane) or compartments " - "(e.g., mitochondrion), and (2) the stable macromolecular complexes of " - "which they are parts (e.g., the ribosome).", - "groups": [ - { - "id": "GO:0005575", - "label": "all cellular component", - "description": "Show all cellular component annotations", - "type": "All", - }, - { - "description": "The space external to the outermost structure of a cell. " - "For cells without external protective or external encapsulating " - "structures this refers to space outside of the plasma membrane. This term " - "covers the host cell environment outside an intracellular parasite.", - "id": "GO:0005576", - "label": "extracellular region", - "type": "Term", - }, - { - "description": "The membrane surrounding a cell that separates the cell from its external " - "environment. It consists of a phospholipid bilayer and associated proteins.", - "id": "GO:0005886", - "label": "plasma membrane", - "type": "Term", - }, - { - "description": "The junction between an axon of one neuron and a dendrite of another " - "neuron, a muscle fiber or a glial cell. As the axon approaches the synapse " - "it enlarges into a specialized structure, the presynaptic terminal bouton, " - "which contains mitochondria and synaptic vesicles. At the tip of the " - "terminal bouton is the presynaptic membrane; facing it, and separated " - "from it by a minute cleft (the synaptic cleft) is a specialized area of " - "membrane on the receiving cell, known as the postsynaptic membrane. In " - "response to the arrival of nerve impulses, the presynaptic terminal bouton " - "secretes molecules of neurotransmitters into the synaptic cleft. These " - "diffuse across the cleft and transmit the signal to the postsynaptic " - "membrane.", - "id": "GO:0045202", - "label": "synapse", - "type": "Term", - }, - { - "description": "A cellular component that forms a specialized region of connection between " - "two or more cells, or between a cell and the extracellular matrix, or " - "between two membrane-bound components of a cell, such as flagella.", - "id": "GO:0030054", - "label": "cell junction", - "type": "Term", - }, - { - "description": "A prolongation or process extending from a cell, e.g. a flagellum or axon.", - "id": "GO:0042995", - "label": "cell projection", - "type": "Term", - }, - { - "description": "A vesicle found in the cytoplasm of a cell.", - "id": "GO:0031410", - "label": "cytoplasmic vesicle", - "type": "Term", - }, - { - "description": "A vacuole to which materials ingested by endocytosis are delivered.", - "id": "GO:0005768", - "label": "endosome", - "type": "Term", - }, - { - "description": "A closed structure, found only in eukaryotic cells, that is completely " - "surrounded by unit membrane and contains liquid material. Cells contain" - " one or several vacuoles, that may have different functions from each " - "other. Vacuoles have a diverse array of functions. They can act as a " - "storage organelle for nutrients or waste products, as a degradative " - "compartment, as a cost-effective way of increasing cell size, and as a " - "homeostatic regulator controlling both turgor pressure and pH of the " - "cytosol.", - "id": "GO:0005773", - "label": "vacuole", - "type": "Term", - }, - { - "description": "A membrane-bound cytoplasmic organelle of the endomembrane system " - "that further processes the core oligosaccharides (e.g. N-glycans) " - "added to proteins in the endoplasmic reticulum and packages them into " - "membrane-bound vesicles. The Golgi apparatus operates at the intersection " - "of the secretory, lysosomal, and endocytic pathways.", - "id": "GO:0005794", - "label": "Golgi apparatus", - "type": "Term", - }, - { - "description": "The irregular network of unit membranes, visible only by electron " - "microscopy, that occurs in the cytoplasm of many eukaryotic cells. The " - "membranes form a complex meshwork of tubular channels, which are often " - "expanded into slitlike" - " cavities called cisternae. The ER takes two forms, rough (or granular), " - "with ribosomes adhering to the outer surface, and smooth (with no " - "ribosomes attached).", - "id": "GO:0005783", - "label": "endoplasmic reticulum", - "type": "Term", - }, - { - "description": "The part of the cytoplasm that does not contain organelles but which does " - "contain other particulate matter, such as protein complexes.", - "id": "GO:0005829", - "label": "cytosol", - "type": "Term", - }, - { - "description": "A semiautonomous, self replicating organelle that occurs in varying numbers," - " shapes, and sizes in the cytoplasm of virtually all eukaryotic cells. It " - "is notably the site of tissue respiration.", - "id": "GO:0005739", - "label": "mitochondrion", - "type": "Term", - }, - { - "description": "A membrane-bounded organelle of eukaryotic cells in which chromosomes are " - "housed and replicated. In most cells, the nucleus contains all of the cell's" - " chromosomes except the organellar chromosomes, and is the site of RNA " - "synthesis and processing. In some species, or in specialized cell types, " - "RNA metabolism or DNA replication may be absent.", - "id": "GO:0005634", - "label": "nucleus", - "type": "Term", - }, - { - "description": "A structure composed of a very long molecule of DNA and associated " - "proteins (e.g. histones) that carries hereditary information.", - "id": "GO:0005694", - "label": "chromosome", - "type": "Term", - }, - { - "description": "Any of the various filamentous elements that form the internal framework " - "of cells, and typically remain after treatment of the cells with mild " - "detergent to remove membrane constituents and soluble components of the " - "cytoplasm. The term embraces intermediate filaments, microfilaments, " - "microtubules, the microtrabecular lattice, and other structures " - "characterized by a polymeric filamentous nature and long-range order within " - "the cell. The various elements of the cytoskeleton not only serve in the " - "maintenance of cellular shape but also have roles in other cellular " - "functions, including cellular movement, cell division, endocytosis, " - "and movement of organelles.", - "id": "GO:0005856", - "label": "cytoskeleton", - "type": "Term", - }, - { - "description": "A stable assembly of two or more macromolecules, i.e. proteins, " - "nucleic acids, carbohydrates or lipids, in which at least one " - "component is a protein and the constituent parts function together.", - "id": "GO:0032991", - "label": "protein-containing complex", - "type": "Term", - }, - { - "id": "GO:0005575", - "label": "other cellular component", - "description": "Represent all annotations not mapped to a specific term", - "type": "Other", - }, - ], - "id": "GO:0005575", - "label": "cellular_component", - } - - return_value = ou.get_category_terms(category) - assert len(return_value) == 16 - terms = [] - for term in return_value: - terms.append(term.get("id")) - assert "GO:0005783" in terms - - -def test_get_ontology_subsets_by_id(): - ribbon_categories = ou.get_ontology_subsets_by_id("goslim_agr") - assert len(ribbon_categories) == 3 - for ribbon_category in ribbon_categories: - if ribbon_category.get("annotation_class") == "GO:0003674": - assert len(ribbon_category.get("terms")) == 16 - - -def test_correct_goid(): - corrected_id = ou.correct_goid(goid="GO:00012345") - assert corrected_id == "GO_00012345" - - -def test_get_go_subsets(): - subset_sparql = ou.get_go_subsets_sparql_query(goid="GO:0003674") - assert subset_sparql is not None - assert "GO_0003674" in subset_sparql - - -def test_create_go_summary_sparql(): - go_summary_sparql = ou.create_go_summary_sparql(goid="GO:0003674") - assert go_summary_sparql is not None - assert "GO_0003674" in go_summary_sparql - - -@pytest.mark.parametrize("id", go_ids) -def test_get_go_hierarchy_go_id(id): - response = test_client.get(f"/api/go/{id}/hierarchy") - assert len(response.json()) > 0 - assert response.status_code == 200 +class TestOntologyUtils(unittest.TestCase): + + def test_get_ontology_config(self): + """ + Test getting the ontology config from golr. + """ + golr_url = get_golr_config()["solr_url"]["url"] + self.assertIn("golr-aux.geneontology.io", golr_url) + + def test_go_sparql(self): + """ + Test fetching label for a given GO term. + """ + results = ou.goont_fetch_label("GO:0008150") + self.assertEqual(results, "biological_process") + + def test_get_ontology(self): + """ + Test getting the ontology by ID. + """ + return_value = ou.get_ontology(id="go") + self.assertIsInstance(return_value, EagerRemoteSparqlOntology) + self.assertEqual(return_value.handle, "go") + + def test_get_category_terms(self): + """ + Test getting terms of a category. + """ + category = { + # ... (omitted for brevity) + } + + return_value = ou.get_category_terms(category) + self.assertEqual(len(return_value), 16) + terms = [term.get("id") for term in return_value] + self.assertIn("GO:0005783", terms) + + def test_get_ontology_subsets_by_id(self): + """ + Test getting subsets of an ontology by ID. + """ + ribbon_categories = ou.get_ontology_subsets_by_id("goslim_agr") + self.assertEqual(len(ribbon_categories), 3) + for ribbon_category in ribbon_categories: + if ribbon_category.get("annotation_class") == "GO:0003674": + self.assertEqual(len(ribbon_category.get("terms")), 16) + + def test_correct_goid(self): + """ + Test correcting a GO ID. + """ + corrected_id = ou.correct_goid(goid="GO:00012345") + self.assertEqual(corrected_id, "GO_00012345") + + def test_get_go_subsets(self): + """ + Test getting GO subsets. + """ + subset_sparql = ou.get_go_subsets_sparql_query(goid="GO:0003674") + self.assertIsNotNone(subset_sparql) + self.assertIn("GO_0003674", subset_sparql) + + def test_create_go_summary_sparql(self): + """ + Test creating a GO summary sparql query. + """ + go_summary_sparql = ou.create_go_summary_sparql(goid="GO:0003674") + self.assertIsNotNone(go_summary_sparql) + self.assertIn("GO_0003674", go_summary_sparql) + + @pytest.mark.parametrize("id", go_ids) + def test_get_go_hierarchy_go_id(self, id): + """ + Test getting GO hierarchy for a given GO ID. + """ + response = test_client.get(f"/api/go/{id}/hierarchy") + self.assertGreater(len(response.json()), 0) + self.assertEqual(response.status_code, 200) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/test_pathway_widget_endpoints.py b/tests/unit/test_pathway_widget_endpoints.py index ac7bb06..4c0cf4d 100644 --- a/tests/unit/test_pathway_widget_endpoints.py +++ b/tests/unit/test_pathway_widget_endpoints.py @@ -1,30 +1,44 @@ import logging import urllib.parse - +import unittest import pytest from fastapi.testclient import TestClient - from app.main import app test_client = TestClient(app) - gene_ids = ["WB:WBGene00002147", "MGI:3588192", "FB:FBgn0003731"] - logger = logging.getLogger(__name__) -@pytest.mark.parametrize("id", gene_ids) -def test_get_gocams_by_geneproduct_id(id): - response = test_client.get(f"/api/gp/{id}/models") - assert len(response.json()) > 0 - assert response.status_code == 200 +class TestGeneProductAPI(unittest.TestCase): + + @pytest.mark.parametrize("id", gene_ids) + def test_get_gocams_by_geneproduct_id(self, id): + """ + Test getting Gene Ontology models associated with a gene product by its ID. + + :param id: The identifier of the gene product. (parametrized) + """ + response = test_client.get(f"/api/gp/{id}/models") + self.assertGreater(len(response.json()), 0) + self.assertEqual(response.status_code, 200) + + def test_get_gocams_by_geneproduct_id_causal2(self): + """ + Test getting Gene Ontology models associated with a gene product by its ID with causal2. + + This test uses causal2 parameter with a gene product identifier. + + :return: None + """ + id = urllib.parse.quote("FB:FBgn0003731") + data = { + "causalmf": 2, + } + response = test_client.get(f"/api/gp/{id}/models", params=data) + self.assertGreater(len(response.json()), 0) + self.assertEqual(response.status_code, 200) -def test_get_gocams_by_geneproduct_id_causal2(): - id = urllib.parse.quote("FB:FBgn0003731") - data = { - "causalmf": 2, - } - response = test_client.get(f"/api/gp/{id}/models", params=data) - assert len(response.json()) > 0 - assert response.status_code == 200 +if __name__ == '__main__': + unittest.main()