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"
)
resp.body = docs_html
resp.text = docs_html
class StatusResource:
@ -63,7 +63,7 @@ class OpenAPIJSONResource:
# Set the version in the schema so Swagger UI can display it
data["info"]["version"] = VERSION
resp.body = json.dumps(data)
resp.text = json.dumps(data)
class AllStatisticsResource:
@ -215,24 +215,24 @@ class SingleStatisticsResource:
resp.media = statistics
api = application = falcon.API()
api.add_route("/", RootResource())
api.add_route("/status", StatusResource())
app = application = falcon.App()
app.add_route("/", RootResource())
app.add_route("/status", StatusResource())
# Item routes
api.add_route("/items", AllStatisticsResource())
api.add_route("/item/{id_:uuid}", SingleStatisticsResource())
app.add_route("/items", AllStatisticsResource())
app.add_route("/item/{id_:uuid}", SingleStatisticsResource())
# Community routes
api.add_route("/communities", AllStatisticsResource())
api.add_route("/community/{id_:uuid}", SingleStatisticsResource())
app.add_route("/communities", AllStatisticsResource())
app.add_route("/community/{id_:uuid}", SingleStatisticsResource())
# Collection routes
api.add_route("/collections", AllStatisticsResource())
api.add_route("/collection/{id_:uuid}", SingleStatisticsResource())
app.add_route("/collections", AllStatisticsResource())
app.add_route("/collection/{id_:uuid}", SingleStatisticsResource())
# Route to the Swagger UI OpenAPI schema
api.add_route("/docs/openapi.json", OpenAPIJSONResource())
# Route to the Swagger UI Openapp schema
app.add_route("/docs/openapi.json", OpenAPIJSONResource())
# 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
@ -242,12 +242,12 @@ SWAGGERUI_PATH = "/swagger"
# 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
# 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.
SWAGGERUI_API_URL = f"{DSPACE_STATISTICS_API_URL}/docs/openapi.json"
register_swaggerui_app(
api,
app,
SWAGGERUI_PATH,
SWAGGERUI_API_URL,
config={

View File

@ -8,10 +8,10 @@ license = "GPL-3.0-only"
[tool.poetry.dependencies]
python = "^3.6"
gunicorn = "^20.0.4"
falcon = "^2.0.0"
falcon = "3.0.0rc1"
psycopg2-binary = "^2.8.6"
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]
ipython = { version = "^7.18.1", python = "^3.7" }

View File

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

View File

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

View File

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

View File

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