1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-11-22 06:15:02 +01:00

Changes for Falcon 3.0.0

Mostly it seems we just need to use resp.text instead of resp.body,
including in falcon-swagger-ui (I forked the upstream one to make
this change).

See: https://falcon.readthedocs.io/en/latest/changes/3.0.0.html
This commit is contained in:
Alan Orth 2021-03-21 10:32:58 +02:00
parent 0650c5985e
commit 2f8e4f8a0a
6 changed files with 25 additions and 25 deletions

View File

@ -31,7 +31,7 @@ class RootResource:
"</html" "</html"
) )
resp.body = docs_html resp.text = docs_html
class StatusResource: class StatusResource:
@ -63,7 +63,7 @@ class OpenAPIJSONResource:
# Set the version in the schema so Swagger UI can display it # Set the version in the schema so Swagger UI can display it
data["info"]["version"] = VERSION data["info"]["version"] = VERSION
resp.body = json.dumps(data) resp.text = json.dumps(data)
class AllStatisticsResource: class AllStatisticsResource:
@ -215,24 +215,24 @@ class SingleStatisticsResource:
resp.media = statistics resp.media = statistics
api = application = falcon.API() app = application = falcon.App()
api.add_route("/", RootResource()) app.add_route("/", RootResource())
api.add_route("/status", StatusResource()) app.add_route("/status", StatusResource())
# Item routes # Item routes
api.add_route("/items", AllStatisticsResource()) app.add_route("/items", AllStatisticsResource())
api.add_route("/item/{id_:uuid}", SingleStatisticsResource()) app.add_route("/item/{id_:uuid}", SingleStatisticsResource())
# Community routes # Community routes
api.add_route("/communities", AllStatisticsResource()) app.add_route("/communities", AllStatisticsResource())
api.add_route("/community/{id_:uuid}", SingleStatisticsResource()) app.add_route("/community/{id_:uuid}", SingleStatisticsResource())
# Collection routes # Collection routes
api.add_route("/collections", AllStatisticsResource()) app.add_route("/collections", AllStatisticsResource())
api.add_route("/collection/{id_:uuid}", SingleStatisticsResource()) app.add_route("/collection/{id_:uuid}", SingleStatisticsResource())
# Route to the Swagger UI OpenAPI schema # Route to the Swagger UI Openapp schema
api.add_route("/docs/openapi.json", OpenAPIJSONResource()) app.add_route("/docs/openapi.json", OpenAPIJSONResource())
# Path to host the Swagger UI. Keep in mind that Falcon will add a route for # Path to host the Swagger UI. Keep in mind that Falcon will add a route for
# this automatically when we register Swagger and the path will be relative # this automatically when we register Swagger and the path will be relative
@ -242,12 +242,12 @@ SWAGGERUI_PATH = "/swagger"
# The *absolute* path to the OpenJSON schema. This must be absolute because # The *absolute* path to the OpenJSON schema. This must be absolute because
# it will be requested by the client and must resolve absolutely. Note: the # it will be requested by the client and must resolve absolutely. Note: the
# name of this variable is misleading because it is actually the schema URL # name of this variable is misleading because it is actually the schema URL
# but we pass it into the register_swaggerui_app() function as the api_url # but we pass it into the register_swaggerui_app() function as the app_url
# parameter. # parameter.
SWAGGERUI_API_URL = f"{DSPACE_STATISTICS_API_URL}/docs/openapi.json" SWAGGERUI_API_URL = f"{DSPACE_STATISTICS_API_URL}/docs/openapi.json"
register_swaggerui_app( register_swaggerui_app(
api, app,
SWAGGERUI_PATH, SWAGGERUI_PATH,
SWAGGERUI_API_URL, SWAGGERUI_API_URL,
config={ config={

View File

@ -8,10 +8,10 @@ license = "GPL-3.0-only"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.6" python = "^3.6"
gunicorn = "^20.0.4" gunicorn = "^20.0.4"
falcon = "^2.0.0" falcon = "3.0.0rc1"
psycopg2-binary = "^2.8.6" psycopg2-binary = "^2.8.6"
requests = "^2.24.0" requests = "^2.24.0"
falcon-swagger-ui = {git = "https://github.com/alanorth/falcon-swagger-ui.git"} falcon-swagger-ui = {git = "https://github.com/alanorth/falcon-swagger-ui.git", rev="falcon-300b1"}
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
ipython = { version = "^7.18.1", python = "^3.7" } ipython = { version = "^7.18.1", python = "^3.7" }

View File

@ -6,12 +6,12 @@ from unittest.mock import patch
import pytest import pytest
from falcon import testing from falcon import testing
from dspace_statistics_api.app import api from dspace_statistics_api.app import app
@pytest.fixture @pytest.fixture
def client(): def client():
return testing.TestClient(api) return testing.TestClient(app)
def test_get_collection(client): def test_get_collection(client):

View File

@ -6,12 +6,12 @@ from unittest.mock import patch
import pytest import pytest
from falcon import testing from falcon import testing
from dspace_statistics_api.app import api from dspace_statistics_api.app import app
@pytest.fixture @pytest.fixture
def client(): def client():
return testing.TestClient(api) return testing.TestClient(app)
def test_get_community(client): def test_get_community(client):

View File

@ -3,12 +3,12 @@
import pytest import pytest
from falcon import testing from falcon import testing
from dspace_statistics_api.app import api from dspace_statistics_api.app import app
@pytest.fixture @pytest.fixture
def client(): def client():
return testing.TestClient(api) return testing.TestClient(app)
def test_get_docs(client): def test_get_docs(client):

View File

@ -6,12 +6,12 @@ from unittest.mock import patch
import pytest import pytest
from falcon import testing from falcon import testing
from dspace_statistics_api.app import api from dspace_statistics_api.app import app
@pytest.fixture @pytest.fixture
def client(): def client():
return testing.TestClient(api) return testing.TestClient(app)
def test_get_item(client): def test_get_item(client):