Skip to content

Commit

Permalink
incorrect urls showing in service manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Feb 2, 2024
1 parent efde714 commit 57b8c8c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/datasette_reconcile/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-present David Kane <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "0.4.1"
__version__ = "0.5.0"
8 changes: 5 additions & 3 deletions src/datasette_reconcile/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ async def _service_manifest(self, request):
if "x-forwarded-proto" in request.headers:
scheme = request.headers.get("x-forwarded-proto")

service_url = (
f'{scheme}://{request.host}{self.datasette.setting("base_url")}/{self.database}/{self.table}/-/reconcile'
)
base_url = f'{scheme}://{request.host}{self.datasette.setting("base_url")}'
if not base_url.endswith("/"):
base_url += "/"

service_url = f"{base_url}{self.database}/{self.table}/-/reconcile"

view_url = self.config.get("view_url")
if not view_url:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,24 @@ async def test_servce_manifest_view_extend(db_path):
assert 200 == response.status_code
data = response.json()
assert "extend" in data
assert data["extend"]["propose_properties"]["service_url"] == "http://localhost//test/dogs/-/reconcile"
assert data["extend"]["propose_properties"]["service_url"] == "http://localhost/test/dogs/-/reconcile"
assert data["extend"]["property_settings"][3]["name"] == "status"


@pytest.mark.asyncio
@pytest.mark.parametrize("suggest_type", ["entity", "type", "property"])
async def test_servce_manifest_view_suggest(db_path, suggest_type):
app = Datasette(
[db_path],
metadata=plugin_metadata({"name_field": "name"}),
).app()
async with httpx.AsyncClient(app=app) as client:
response = await client.get("http://localhost/test/dogs/-/reconcile")
assert 200 == response.status_code
data = response.json()
assert "extend" in data
assert data["suggest"][suggest_type]["service_url"] == "http://localhost/test/dogs/-/reconcile"
assert data["suggest"][suggest_type]["service_path"] == f"/suggest/{suggest_type}"
assert len(data["suggest"]) == 3


Expand Down

0 comments on commit 57b8c8c

Please sign in to comment.