Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into david/fix-search-count
Browse files Browse the repository at this point in the history
# Conflicts:
#	prez/config.py
  • Loading branch information
recalcitrantsupplant committed Aug 15, 2024
2 parents 26b05c6 + d644e86 commit 274c75b
Show file tree
Hide file tree
Showing 9 changed files with 1,244 additions and 710 deletions.
1,818 changes: 1,114 additions & 704 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion prez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Settings(BaseSettings):
curie_separator: str = ":"
system_uri: Optional[str] = f"{protocol}://{host}:{port}"
order_lists_by_label: bool = True
listing_count_limit: int = 1000
listing_count_limit: int = 100
search_count_limit: int = 10
label_predicates: Optional[List[URIRef]] = [
SKOS.prefLabel,
Expand Down
2 changes: 1 addition & 1 deletion prez/models/query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
description="Number of items per page, must be greater than 0",
),
q: Optional[str] = Query(
None, description="Search query", examples=["building"]
None, description="Search query", example="building"
),
filter: Optional[str] = Query(
None,
Expand Down
10 changes: 8 additions & 2 deletions prez/reference_data/profiles/ogc_records_profile.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ prez:OGCRecordsProfile
dcterms:title "OGC Profile" ;
altr-ext:constrainsClass prez:CatPrez ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/json" ,
"application/ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
altr-ext:hasNodeShape [
a sh:NodeShape ;
sh:targetClass prof:Profile , dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
sh:targetClass dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
, skos:Collection , rdf:Resource , prez:SearchResult , prez:CQLObjectList ;
altr-ext:hasDefaultProfile prez:OGCListingProfile
] , [
Expand All @@ -38,7 +44,7 @@ prez:OGCRecordsProfile
altr-ext:hasDefaultProfile prez:OGCSchemesObjectProfile
] , [
a sh:NodeShape ;
sh:targetClass prof:Profile , dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
sh:targetClass dcat:Catalog , dcat:Resource , skos:Concept , geo:Feature , geo:FeatureCollection
, skos:Collection , rdf:Resource ;
altr-ext:hasDefaultProfile prez:OGCItemProfile
]
Expand Down
41 changes: 40 additions & 1 deletion prez/reference_data/profiles/prez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
a prof:Profile ;
dcterms:identifier "prez"^^xsd:token ;
dcterms:description "A profile for the Prez Linked Data API" ;
skos:prefLabel "Prez profile" ;
dcterms:title "Prez profile" ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/json" ,
"application/ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
altr-ext:hasNodeShape [
a sh:NodeShape ;
sh:targetClass prez:SPARQLQuery ;
Expand All @@ -29,6 +35,10 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
a sh:NodeShape ;
sh:targetClass prez:AltProfilesList ;
altr-ext:hasDefaultProfile <https://prez.dev/profile/open-object>
] , [
a sh:NodeShape ;
sh:targetClass prof:Profile ;
altr-ext:hasDefaultProfile <https://prez.dev/profile/profiles>
]
.

Expand Down Expand Up @@ -138,3 +148,32 @@ altr-ext:alt-profile
)
] ;
.

<https://prez.dev/profile/profiles>
a prof:Profile , prez:ObjectProfile , prez:ListingProfile ;
dcterms:description "A Profile for displaying profiles" ;
dcterms:identifier "prof"^^xsd:token ;
dcterms:title "Profiles Profile" ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat
"application/ld+json" ,
"application/anot+ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
altr-ext:constrainsClass
prof:Profile ;
sh:property [
sh:path (
sh:union (
rdf:type
altr-ext:hasResourceFormat
altr-ext:hasDefaultResourceFormat
dcterms:description
dcterms:title
dcterms:identifier
)
)
] ;
shext:bnode-depth 20 ;
.
25 changes: 25 additions & 0 deletions prez/services/connegp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic import BaseModel
from rdflib import Graph, Namespace, URIRef

from prez.config import settings
from prez.exceptions.model_exceptions import NoProfilesException
from prez.repositories.base import Repo
from prez.services.curie_functions import get_curie_id_for_uri, get_uri_for_curie_id
Expand Down Expand Up @@ -302,4 +303,28 @@ async def _do_query(self, query: str) -> tuple[Graph, list]:
response = await self.system_repo.send_queries([], [(None, query)])
if not response[1][0][1]:
raise NoProfilesException(self.classes)

if settings.log_level == "DEBUG":
from tabulate import tabulate
table_data = [
[
item['profile']['value'],
item['title']['value'],
item['class']['value'],
item['distance']['value'],
item['def_profile']['value'],
item['format']['value'],
item['req_format']['value'],
item['def_format']['value'],
]
for item in response[1][0][1]
]

# Define headers
headers = ["Profile", "Title", "Class", "Distance", "Default Profile", "Format", "Requested Format",
"Default Format"]

# Render as a table
log.debug(tabulate(table_data, headers=headers, tablefmt="grid"))

return response
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ scalene = "^1.5.18"
python-dotenv = "^1.0.0"
pyoxigraph = "^0.3.19"
coverage = "^7.3.2"
tabulate = "^0.9.0"
ogctests = "^0.1.15"

[build-system]
requires = ["poetry-core>=1.9.0"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endpoints_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def test_profile(client_no_override):
r = client_no_override.get("/profiles")
r = client_no_override.get("/profiles?per_page=50")
g = Graph().parse(data=r.text)
assert (URIRef("https://prez.dev/profile/prez"), RDF.type, PROF.Profile) in g

Expand Down
52 changes: 52 additions & 0 deletions tests/test_ogc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import asyncio
from pathlib import Path

import pytest
from fastapi.testclient import TestClient
from ogctests.main import run_ogctests
from pyoxigraph.pyoxigraph import Store

from prez.app import assemble_app
from prez.dependencies import get_data_repo
from prez.repositories import PyoxigraphRepo, Repo


@pytest.fixture(scope="session")
def test_store() -> Store:
# Create a new pyoxigraph Store
store = Store()

file = Path("../test_data/spaceprez.ttl")
store.load(file.read_bytes(), "text/turtle")

return store


@pytest.fixture(scope="session")
def test_repo(test_store: Store) -> Repo:
# Create a PyoxigraphQuerySender using the test_store
return PyoxigraphRepo(test_store)


@pytest.fixture(scope="session")
def client(test_repo: Repo) -> TestClient:
# Override the dependency to use the test_repo
def override_get_data_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_data_repo] = override_get_data_repo

with TestClient(app, backend_options={"loop_factory": asyncio.new_event_loop}) as c:
yield c

# Remove the override to ensure subsequent tests are unaffected
app.dependency_overrides.clear()


@pytest.mark.xfail()
def test_features_core(client: TestClient):
scope = "features/core"
exit_code = run_ogctests(scope, test_client=client)
assert exit_code == pytest.ExitCode.OK

0 comments on commit 274c75b

Please sign in to comment.