I've excerpted this from #49 - this code tests public SPARQL interfaces are able to use the Bioregistry. I'm not sure if this belongs in this package, though
"""Tests for remote federated SPARQL."""
from textwrap import dedent
from curies.mapping_service import _handle_header
from tests.test_federated_sparql import FederationMixin
BIOREGISTRY_SPARQL_ENDPOINT = "http://bioregistry.io/sparql"
class TestPublicFederatedSPARQL(FederationMixin):
"""Test the identifier mapping service."""
def setUp(self) -> None:
"""Set up the public federated SPARQL test case."""
self.sparql = dedent(
f"""\
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?o WHERE {{
SERVICE <{BIOREGISTRY_SPARQL_ENDPOINT}> {{
<http://purl.obolibrary.org/obo/CHEBI_24867> owl:sameAs ?o
}}
}}
""".rstrip()
)
def query_endpoint(self, endpoint: str):
"""Query an endpoint."""
self.assert_service_works(endpoint)
accept = "application/sparql-results+json"
resp = self.get(endpoint, self.sparql, accept=accept)
self.assertEqual(
200,
resp.status_code,
msg=f"SPARQL query failed at {endpoint}:\n\n{self.sparql}\n\nResponse:\n{resp.text}",
)
response_content_type = _handle_header(resp.headers["content-type"])
self.assertEqual(accept, response_content_type, msg="Server sent incorrect content type")
try:
res = resp.json()
except Exception:
self.fail(msg=f"\n\nError running the federated query to {endpoint}:\n{resp.text}")
self.assertGreater(
len(res["results"]["bindings"]),
0,
msg=f"Federated query to {endpoint} gives no results",
)
self.assertIn(
"https://bioregistry.io/chebi:24867",
{binding["o"]["value"] for binding in res["results"]["bindings"]},
)
def test_public_federated_virtuoso(self):
"""Test sending a federated query to a public mapping service from Virtuoso."""
self.query_endpoint("https://bio2rdf.org/sparql")
def test_public_federated_blazegraph(self):
"""Test sending a federated query to a public mapping service from Blazegraph."""
self.query_endpoint("http://kg-hub-rdf.berkeleybop.io/blazegraph/sparql")
def test_public_federated_graphdb(self):
"""Test sending a federated query to a public mapping service from GraphDB."""
self.query_endpoint("https://graphdb.dumontierlab.com/repositories/test")
I've excerpted this from #49 - this code tests public SPARQL interfaces are able to use the Bioregistry. I'm not sure if this belongs in this package, though