mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Implemented actor_from_request with tests, refs #699
Also added datasette argument to permission_allowed hook
This commit is contained in:
parent
060a56735c
commit
461c82838d
6 changed files with 80 additions and 2 deletions
|
|
@ -126,3 +126,11 @@ class DummyFacet(Facet):
|
|||
facet_results = {}
|
||||
facets_timed_out = []
|
||||
return facet_results, facets_timed_out
|
||||
|
||||
|
||||
@hookimpl
|
||||
def actor_from_request(datasette, request):
|
||||
if request.args.get("_bot"):
|
||||
return {"id": "bot"}
|
||||
else:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -95,3 +95,15 @@ def asgi_wrapper(datasette):
|
|||
return add_x_databases_header
|
||||
|
||||
return wrap_with_databases_header
|
||||
|
||||
|
||||
@hookimpl
|
||||
def actor_from_request(datasette, request):
|
||||
async def inner():
|
||||
if request.args.get("_bot2"):
|
||||
result = await datasette.get_database().execute("select 1 + 1")
|
||||
return {"id": "bot2", "1+1": result.first()[0]}
|
||||
else:
|
||||
return None
|
||||
|
||||
return inner
|
||||
|
|
|
|||
|
|
@ -503,3 +503,27 @@ def test_register_facet_classes(app_client):
|
|||
"toggle_url": "http://localhost/fixtures/compound_three_primary_keys.json?_dummy_facet=1&_facet=pk3",
|
||||
},
|
||||
] == data["suggested_facets"]
|
||||
|
||||
|
||||
def test_actor_from_request(app_client):
|
||||
app_client.get("/")
|
||||
# Should have no actor
|
||||
assert None == app_client.ds._last_request.scope["actor"]
|
||||
app_client.get("/?_bot=1")
|
||||
# Should have bot actor
|
||||
assert {"id": "bot"} == app_client.ds._last_request.scope["actor"]
|
||||
|
||||
|
||||
def test_actor_from_request_async(app_client):
|
||||
app_client.get("/")
|
||||
# Should have no actor
|
||||
assert None == app_client.ds._last_request.scope["actor"]
|
||||
app_client.get("/?_bot2=1")
|
||||
# Should have bot2 actor
|
||||
assert {"id": "bot2", "1+1": 2} == app_client.ds._last_request.scope["actor"]
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_permission_allowed(app_client):
|
||||
# TODO
|
||||
assert False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue