Skip to content

Commit

Permalink
update Dockerfile and prez tests to use factory pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysommer committed Apr 21, 2024
1 parent bf776c5 commit deb6a19
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ RUN apk update && \
WORKDIR /app
COPY . .

ENTRYPOINT uvicorn prez.app:app --host=${HOST:-0.0.0.0} --port=${PORT:-8000} --proxy-headers
ENTRYPOINT uvicorn prez.app:assemble_app --factory --host=${HOST:-0.0.0.0} --port=${PORT:-8000} --proxy-headers
4 changes: 3 additions & 1 deletion tests/test_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.testclient import TestClient
from pyoxigraph.pyoxigraph import Store

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -32,6 +32,8 @@ def test_client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_curie_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
from fastapi.testclient import TestClient

from prez.app import app
from prez.app import assemble_app


@pytest.fixture
def client() -> TestClient:
app = assemble_app()
testclient = TestClient(app)

# Make a request for the following IRI to ensure
Expand Down
4 changes: 3 additions & 1 deletion tests/test_dd_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi.testclient import TestClient
from pyoxigraph.pyoxigraph import Store

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -34,6 +34,8 @@ def test_client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyoxigraph.pyoxigraph import Store
from rdflib import Graph

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -33,6 +33,8 @@ def test_client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_catprez.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdflib import Graph, URIRef
from rdflib.namespace import RDF, DCAT

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -34,6 +34,8 @@ def client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyoxigraph.pyoxigraph import Store
from rdflib import Graph

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.reference_data.prez_ns import PREZ
from prez.sparql.methods import Repo, PyoxigraphRepo
Expand Down Expand Up @@ -34,6 +34,8 @@ def client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdflib import Graph
from rdflib import RDF, DCAT

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -34,6 +34,8 @@ def test_client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdflib import Graph, URIRef
from rdflib.namespace import RDF, PROF

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -34,6 +34,8 @@ def client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_spaceprez.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdflib import Graph, URIRef
from rdflib.namespace import RDF, DCAT, RDFS

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -34,6 +34,8 @@ def client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_endpoints_vocprez.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdflib import Graph, URIRef
from rdflib.compare import isomorphic

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -34,6 +34,8 @@ def test_client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_redirect_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.testclient import TestClient
from pyoxigraph.pyoxigraph import Store

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -32,6 +32,8 @@ def test_client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rdflib import Literal, URIRef, Graph
from rdflib.compare import isomorphic

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.models.search_method import SearchMethod
from prez.routers.search import extract_qsa_params
Expand Down Expand Up @@ -37,6 +37,8 @@ def client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand Down
18 changes: 14 additions & 4 deletions tests/test_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.testclient import TestClient
from pyoxigraph.pyoxigraph import Store

from prez.app import app
from prez.app import assemble_app
from prez.dependencies import get_repo
from prez.sparql.methods import Repo, PyoxigraphRepo

Expand Down Expand Up @@ -32,6 +32,8 @@ def client(test_repo: Repo) -> TestClient:
def override_get_repo():
return test_repo

app = assemble_app()

app.dependency_overrides[get_repo] = override_get_repo

with TestClient(app) as c:
Expand All @@ -43,15 +45,23 @@ def override_get_repo():

def test_select(client):
"""check that a valid select query returns a 200 response."""
r = client.get("/sparql?query=SELECT%20*%0AWHERE%20%7B%0A%20%20%3Fs%20%3Fp%20%3Fo%0A%7D%20LIMIT%201")
r = client.get(
"/sparql?query=SELECT%20*%0AWHERE%20%7B%0A%20%20%3Fs%20%3Fp%20%3Fo%0A%7D%20LIMIT%201"
)
assert (r.status_code, 200)


def test_construct(client):
"""check that a valid construct query returns a 200 response."""
r = client.get("/sparql?query=CONSTRUCT%20%7B%0A%20%20%3Fs%20%3Fp%20%3Fo%0A%7D%20WHERE%20%7B%0A%20%20%3Fs%20%3Fp%20%3Fo%0A%7D%20LIMIT%201")
r = client.get(
"/sparql?query=CONSTRUCT%20%7B%0A%20%20%3Fs%20%3Fp%20%3Fo%0A%7D%20WHERE%20%7B%0A%20%20%3Fs%20%3Fp%20%3Fo%0A%7D%20LIMIT%201"
)
assert (r.status_code, 200)


def test_ask(client):
"""check that a valid ask query returns a 200 response."""
r = client.get("/sparql?query=PREFIX%20ex%3A%20%3Chttp%3A%2F%2Fexample.com%2Fdatasets%2F%3E%0APREFIX%20dcterms%3A%20%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Fterms%2F%3E%0A%0AASK%0AWHERE%20%7B%0A%20%20%3Fsubject%20dcterms%3Atitle%20%3Ftitle%20.%0A%20%20FILTER%20CONTAINS(LCASE(%3Ftitle)%2C%20%22sandgate%22)%0A%7D")
r = client.get(
"/sparql?query=PREFIX%20ex%3A%20%3Chttp%3A%2F%2Fexample.com%2Fdatasets%2F%3E%0APREFIX%20dcterms%3A%20%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Fterms%2F%3E%0A%0AASK%0AWHERE%20%7B%0A%20%20%3Fsubject%20dcterms%3Atitle%20%3Ftitle%20.%0A%20%20FILTER%20CONTAINS(LCASE(%3Ftitle)%2C%20%22sandgate%22)%0A%7D"
)
assert (r.status_code, 200)

0 comments on commit deb6a19

Please sign in to comment.