-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jschaff
committed
Oct 4, 2024
1 parent
99ed0f9
commit 72e8319
Showing
7 changed files
with
483 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Client fixtures for usage across the biothings_client testing | ||
""" | ||
|
||
import pytest | ||
|
||
from biothings_client import get_async_client | ||
from biothings_client.client.definitions import AsyncMyGeneInfo | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def async_gene_client() -> AsyncMyGeneInfo: | ||
""" | ||
Fixture for generating an asynchronous mygene client | ||
""" | ||
client = "gene" | ||
gene_client = get_async_client(client) | ||
return gene_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
Test suite for the async client | ||
""" | ||
|
||
from typing import List | ||
|
||
import pytest | ||
|
||
import biothings_client | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"client_name,client_url,class_name", | ||
[ | ||
(["gene"], "https://mygene.info/v3", "AsyncMyGeneInfo"), | ||
(["variant"], "https://myvariant.info/v1", "AsyncMyVariantInfo"), | ||
(["chem", "drug"], "https://mychem.info/v1", "AsyncMyChemInfo"), | ||
(["disease"], "https://mydisease.info/v1", "AsyncMyDiseaseInfo"), | ||
(["taxon"], "https://t.biothings.info/v1", "AsyncMyTaxonInfo"), | ||
(["geneset"], "https://mygeneset.info/v1", "AsyncMyGenesetInfo"), | ||
], | ||
) | ||
async def test_get_async_client(client_name: List[str], client_url: str, class_name: str): | ||
""" | ||
Tests our ability to generate async clients | ||
""" | ||
client_name_instances = [biothings_client.get_async_client(name) for name in client_name] | ||
client_url_instance = biothings_client.get_async_client(url=client_url) | ||
clients = [client_url_instance, *client_name_instances] | ||
for client in clients: | ||
assert type(client).__name__ == class_name | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"client_name,client_url,class_name", | ||
[ | ||
("gene", "https://mygene.info/v3", "AsyncMyGeneInfo"), | ||
("variant", "https://mychem.info/v1", "AsyncMyVariantInfo"), | ||
("chem", "https://mychem.info/v1", "AsyncMyChemInfo"), | ||
("disease", "https://mydisease.info/v1", "AsyncMyDiseaseInfo"), | ||
("taxon", "https://t.biothings.info/v1", "AsyncMyTaxonInfo"), | ||
("geneset", "https://mygeneset.info/v1", "AsyncMyGenesetInfo"), | ||
], | ||
) | ||
async def test_generate_async_settings(client_name: str, client_url: str, class_name: str): | ||
client_settings = biothings_client.client.asynchronous.generate_async_settings(client_name, url=client_url) | ||
assert client_settings["class_kwargs"]["_default_url"] == client_url | ||
assert client_settings["class_name"] == class_name | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"client_name", | ||
( | ||
"gene", | ||
"variant", | ||
"chem", | ||
"disease", | ||
"taxon", | ||
"geneset", | ||
), | ||
) | ||
async def test_url_protocol(client_name: str): | ||
""" | ||
Tests that our HTTP protocol modification methods work | ||
as expected when transforming to either HTTP or HTTPS | ||
""" | ||
client_instance = biothings_client.get_async_client(client_name) | ||
|
||
http_protocol = "http://" | ||
https_protocol = "https://" | ||
|
||
# DEFAULT: HTTPS | ||
assert client_instance.url.startswith(https_protocol) | ||
|
||
# Transform to HTTP | ||
await client_instance.use_http() | ||
assert client_instance.url.startswith(http_protocol) | ||
|
||
# Transform back to HTTPS | ||
await client_instance.use_https() | ||
client_instance.url.startswith(https_protocol) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.