diff --git a/Dockerfile b/Dockerfile index c3a97fe9..b67d8f98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ No newline at end of file +ENTRYPOINT uvicorn prez.app:assemble_app --factory --host=${HOST:-0.0.0.0} --port=${PORT:-8000} --proxy-headers \ No newline at end of file diff --git a/tests/test_count.py b/tests/test_count.py index c4dc4cc9..c8969ccd 100644 --- a/tests/test_count.py +++ b/tests/test_count.py @@ -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 @@ -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: diff --git a/tests/test_curie_endpoint.py b/tests/test_curie_endpoint.py index 2909374a..091bca44 100644 --- a/tests/test_curie_endpoint.py +++ b/tests/test_curie_endpoint.py @@ -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 diff --git a/tests/test_dd_profiles.py b/tests/test_dd_profiles.py index 31c7e90b..d2843f8a 100644 --- a/tests/test_dd_profiles.py +++ b/tests/test_dd_profiles.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_cache.py b/tests/test_endpoints_cache.py index b0f33b4b..c7a3ce19 100644 --- a/tests/test_endpoints_cache.py +++ b/tests/test_endpoints_cache.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_catprez.py b/tests/test_endpoints_catprez.py index 0740434d..5cb3487a 100644 --- a/tests/test_endpoints_catprez.py +++ b/tests/test_endpoints_catprez.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_management.py b/tests/test_endpoints_management.py index e9b83d75..08660035 100644 --- a/tests/test_endpoints_management.py +++ b/tests/test_endpoints_management.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_object.py b/tests/test_endpoints_object.py index c32b4b31..8f397ce1 100644 --- a/tests/test_endpoints_object.py +++ b/tests/test_endpoints_object.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_profiles.py b/tests/test_endpoints_profiles.py index 2dfcbe6c..9f049443 100644 --- a/tests/test_endpoints_profiles.py +++ b/tests/test_endpoints_profiles.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_spaceprez.py b/tests/test_endpoints_spaceprez.py index 0dcb5ab8..c095c68f 100644 --- a/tests/test_endpoints_spaceprez.py +++ b/tests/test_endpoints_spaceprez.py @@ -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 @@ -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: diff --git a/tests/test_endpoints_vocprez.py b/tests/test_endpoints_vocprez.py index 97ef532c..d5090ef6 100644 --- a/tests/test_endpoints_vocprez.py +++ b/tests/test_endpoints_vocprez.py @@ -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 @@ -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: diff --git a/tests/test_redirect_endpoint.py b/tests/test_redirect_endpoint.py index 92653193..3a718752 100644 --- a/tests/test_redirect_endpoint.py +++ b/tests/test_redirect_endpoint.py @@ -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 @@ -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: diff --git a/tests/test_search.py b/tests/test_search.py index 60e2fbde..82d546e2 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -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 @@ -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: diff --git a/tests/test_sparql.py b/tests/test_sparql.py index 53c4c921..876bb4d8 100644 --- a/tests/test_sparql.py +++ b/tests/test_sparql.py @@ -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 @@ -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: @@ -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)