Skip to content

Commit

Permalink
Add homology endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cachitas committed Apr 4, 2024
1 parent 0052a1c commit 1bc0cef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/stringx/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 17 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 1bc0cef

Please sign in to comment.