Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions py2http/examples/object_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from typing import MutableMapping

from py2http.service import shared_objects
from py2http.service import run_app, shared_objects


class BackendStore(MutableMapping):
Expand Down Expand Up @@ -60,7 +60,7 @@ def __delitem__(self, key: str):
app = mk_app(handlers, publish_openapi=True, publish_swagger=True)


def test_service(rooturl="http://localhost:8080"):
def test_service(rooturl="http://localhost:3030"):
import requests

url = f"{rooturl}/backend_store"
Expand All @@ -75,7 +75,9 @@ def test_service(rooturl="http://localhost:8080"):


if __name__ == "__main__":
app.run()
# Not `app.run()`: that is bottle's own runner (port 8080), while the OpenAPI spec (and
# so Swagger's "Try it out") points at the port `run_app` serves on, 3030 by default.
run_app(app)


# old code (with errors)
Expand Down
6 changes: 5 additions & 1 deletion py2http/openapi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ def openapi_type_mapping(obj_type):
return oatype_for_pytype.get(obj_type, None)


from py2http.default_configs import default_configs

BINARY = "binary"
DFLT_SERVER_URL = "http://localhost:3030"
# Where `run_app` serves unless told otherwise: the spec's server URL must match it, or
# Swagger's "Try it out" calls a port nothing listens on (i2mint/py2http#13).
DFLT_SERVER_URL = f"http://{default_configs['host']}:{default_configs['port']}"


class OpenApiExtractor:
Expand Down
15 changes: 15 additions & 0 deletions py2http/tests/test_example_ports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""The example services must listen where their OpenAPI spec says (i2mint/py2http#13)."""

from py2http.default_configs import default_configs
from py2http.openapi_utils import DFLT_SERVER_URL, mk_openapi_template


def test_openapi_server_url_is_where_run_app_serves():
assert DFLT_SERVER_URL == f"http://{default_configs['host']}:{default_configs['port']}"
assert mk_openapi_template()["servers"] == [{"url": DFLT_SERVER_URL}]


def test_object_dispatch_example_checks_the_port_the_spec_names():
from py2http.examples import object_dispatch as ex

assert ex.test_service.__defaults__ == (DFLT_SERVER_URL,)
Loading