diff --git a/src/stringx/client.py b/src/stringx/client.py index 2c5b8a6..d0a1026 100644 --- a/src/stringx/client.py +++ b/src/stringx/client.py @@ -91,6 +91,18 @@ def interaction_partners( return self.request("interaction_partners", params=params) + def homology( + self, identifiers: list[str], species: int, *, format: str | None = None + ): + url = f"api/{format or self.format}/homology" + + params = { + "identifiers": "\r".join(identifiers), + "species": species, + } + + return self.post(url, params=params) + def version(self) -> str: request = self.build_request("GET", "api/json/version") request.url = request.url.copy_remove_param("caller_identity") diff --git a/tests/test_client.py b/tests/test_client.py index 6f6dccd..5ae95ab 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -129,6 +129,23 @@ def test_interaction_partners(httpx_mock, test_client): test_client.interaction_partners(["id1", "id2"], 7227) +@pytest.mark.parametrize("format", ["tsv", "tsv-no-header", "json", "xml"]) +def test_homology(httpx_mock, test_client, format): + identifiers = ["id1", "id2"] + species = 1234 + + httpx_mock.add_response() + + test_client.homology(identifiers, species, format=format) + + requested_url = httpx_mock.get_request().url + + assert requested_url.path == f"/api/{format}/homology" + assert requested_url.params["identifiers"] == "\r".join(identifiers) + assert requested_url.params["species"] == str(species) + assert requested_url.params["caller_identity"] == test_client.identity + + def test_version(httpx_mock, test_client): httpx_mock.add_response( url=httpx.URL("https://string-db.org/api/json/version"),